mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): disable panels based on app props
This commit is contained in:
parent
cc3401a159
commit
9820829edb
1
invokeai/frontend/web/index.d.ts
vendored
1
invokeai/frontend/web/index.d.ts
vendored
@ -68,6 +68,7 @@ declare module '@invoke-ai/invoke-ai-ui' {
|
|||||||
|
|
||||||
interface InvokeProps extends PropsWithChildren {
|
interface InvokeProps extends PropsWithChildren {
|
||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
|
disabledPanels?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
declare function Invoke(props: InvokeProps): JSX.Element;
|
declare function Invoke(props: InvokeProps): JSX.Element;
|
||||||
|
@ -5,16 +5,28 @@ import storage from 'redux-persist/lib/storage'; // defaults to localStorage for
|
|||||||
|
|
||||||
import { getPersistConfig } from 'redux-deep-persist';
|
import { getPersistConfig } from 'redux-deep-persist';
|
||||||
|
|
||||||
import canvasReducer from 'features/canvas/store/canvasSlice';
|
import canvasReducer, { canvasSlice } from 'features/canvas/store/canvasSlice';
|
||||||
import galleryReducer from 'features/gallery/store/gallerySlice';
|
import galleryReducer, {
|
||||||
import resultsReducer from 'features/gallery/store/resultsSlice';
|
gallerySlice,
|
||||||
import uploadsReducer from 'features/gallery/store/uploadsSlice';
|
} from 'features/gallery/store/gallerySlice';
|
||||||
import lightboxReducer from 'features/lightbox/store/lightboxSlice';
|
import resultsReducer, {
|
||||||
import generationReducer from 'features/parameters/store/generationSlice';
|
resultsSlice,
|
||||||
import postprocessingReducer from 'features/parameters/store/postprocessingSlice';
|
} from 'features/gallery/store/resultsSlice';
|
||||||
import systemReducer from 'features/system/store/systemSlice';
|
import uploadsReducer, {
|
||||||
import uiReducer from 'features/ui/store/uiSlice';
|
uploadsSlice,
|
||||||
import apiReducer from 'services/apiSlice';
|
} from 'features/gallery/store/uploadsSlice';
|
||||||
|
import lightboxReducer, {
|
||||||
|
lightboxSlice,
|
||||||
|
} from 'features/lightbox/store/lightboxSlice';
|
||||||
|
import generationReducer, {
|
||||||
|
generationSlice,
|
||||||
|
} from 'features/parameters/store/generationSlice';
|
||||||
|
import postprocessingReducer, {
|
||||||
|
postprocessingSlice,
|
||||||
|
} from 'features/parameters/store/postprocessingSlice';
|
||||||
|
import systemReducer, { systemSlice } from 'features/system/store/systemSlice';
|
||||||
|
import uiReducer, { uiSlice } from 'features/ui/store/uiSlice';
|
||||||
|
import apiReducer, { apiSlice } from 'services/apiSlice';
|
||||||
|
|
||||||
import { socketioMiddleware } from './socketio/middleware';
|
import { socketioMiddleware } from './socketio/middleware';
|
||||||
import { socketioMiddleware as nodesSocketioMiddleware } from './nodesSocketio/middleware';
|
import { socketioMiddleware as nodesSocketioMiddleware } from './nodesSocketio/middleware';
|
||||||
@ -113,14 +125,44 @@ function buildMiddleware() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface InitializeStore {
|
||||||
|
disabledPanels?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const disablePanels = ({
|
||||||
|
disabledPanels,
|
||||||
|
enabledParameterPanels,
|
||||||
|
}: {
|
||||||
|
disabledPanels: string[];
|
||||||
|
enabledParameterPanels: { [key: string]: boolean };
|
||||||
|
}) => {
|
||||||
|
const updatedParameterPanels: { [key: string]: boolean } = {};
|
||||||
|
Object.keys(enabledParameterPanels).forEach(function (key, index) {
|
||||||
|
updatedParameterPanels[key] =
|
||||||
|
disabledPanels.indexOf(key) >= 0 ? false : true;
|
||||||
|
});
|
||||||
|
return updatedParameterPanels;
|
||||||
|
};
|
||||||
|
|
||||||
// Continue with store setup
|
// Continue with store setup
|
||||||
export const store = configureStore({
|
export const initializeStore = ({ disabledPanels = [] }: InitializeStore) =>
|
||||||
|
configureStore({
|
||||||
reducer: persistedReducer,
|
reducer: persistedReducer,
|
||||||
middleware: (getDefaultMiddleware) =>
|
middleware: (getDefaultMiddleware) =>
|
||||||
getDefaultMiddleware({
|
getDefaultMiddleware({
|
||||||
immutableCheck: false,
|
immutableCheck: false,
|
||||||
serializableCheck: false,
|
serializableCheck: false,
|
||||||
}).concat(buildMiddleware()),
|
}).concat(buildMiddleware()),
|
||||||
|
preloadedState: {
|
||||||
|
ui: {
|
||||||
|
...uiSlice.getInitialState(),
|
||||||
|
enabledParameterPanels: disablePanels({
|
||||||
|
disabledPanels,
|
||||||
|
enabledParameterPanels:
|
||||||
|
uiSlice.getInitialState().enabledParameterPanels,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
devTools: {
|
devTools: {
|
||||||
// Uncommenting these very rapidly called actions makes the redux dev tools output much more readable
|
// Uncommenting these very rapidly called actions makes the redux dev tools output much more readable
|
||||||
actionsDenylist: [
|
actionsDenylist: [
|
||||||
@ -136,6 +178,8 @@ export const store = configureStore({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const store = initializeStore({});
|
||||||
|
|
||||||
export type AppGetState = typeof store.getState;
|
export type AppGetState = typeof store.getState;
|
||||||
export type RootState = ReturnType<typeof store.getState>;
|
export type RootState = ReturnType<typeof store.getState>;
|
||||||
export type AppDispatch = typeof store.dispatch;
|
export type AppDispatch = typeof store.dispatch;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React, { lazy, PropsWithChildren, useEffect } from 'react';
|
import React, { lazy, PropsWithChildren, useEffect } from 'react';
|
||||||
import { Provider } from 'react-redux';
|
import { Provider } from 'react-redux';
|
||||||
import { PersistGate } from 'redux-persist/integration/react';
|
import { PersistGate } from 'redux-persist/integration/react';
|
||||||
import { store } from './app/store';
|
import { initializeStore } from './app/store';
|
||||||
import { persistor } from './persistor';
|
import { persistor } from './persistor';
|
||||||
import { OpenAPI } from 'services/api';
|
import { OpenAPI } from 'services/api';
|
||||||
import '@fontsource/inter/100.css';
|
import '@fontsource/inter/100.css';
|
||||||
@ -24,16 +24,17 @@ const ThemeLocaleProvider = lazy(() => import('./app/ThemeLocaleProvider'));
|
|||||||
|
|
||||||
interface Props extends PropsWithChildren {
|
interface Props extends PropsWithChildren {
|
||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
|
disabledPanels?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Component({ apiUrl, children }: Props) {
|
export default function Component({ apiUrl, disabledPanels, children }: Props) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (apiUrl) OpenAPI.BASE = apiUrl;
|
if (apiUrl) OpenAPI.BASE = apiUrl;
|
||||||
}, [apiUrl]);
|
}, [apiUrl]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Provider store={store}>
|
<Provider store={initializeStore({ disabledPanels })}>
|
||||||
<PersistGate loading={<Loading />} persistor={persistor}>
|
<PersistGate loading={<Loading />} persistor={persistor}>
|
||||||
<React.Suspense fallback={<Loading showText />}>
|
<React.Suspense fallback={<Loading showText />}>
|
||||||
<ThemeLocaleProvider>
|
<ThemeLocaleProvider>
|
||||||
|
@ -21,9 +21,10 @@ type ParametersAccordionsType = {
|
|||||||
const ParametersAccordion = (props: ParametersAccordionsType) => {
|
const ParametersAccordion = (props: ParametersAccordionsType) => {
|
||||||
const { accordionInfo } = props;
|
const { accordionInfo } = props;
|
||||||
|
|
||||||
const openAccordions = useAppSelector(
|
const { system, ui } = useAppSelector((state: RootState) => state);
|
||||||
(state: RootState) => state.system.openAccordions
|
|
||||||
);
|
const { openAccordions } = system;
|
||||||
|
const { enabledParameterPanels } = ui;
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
@ -39,6 +40,9 @@ const ParametersAccordion = (props: ParametersAccordionsType) => {
|
|||||||
Object.keys(accordionInfo).forEach((key) => {
|
Object.keys(accordionInfo).forEach((key) => {
|
||||||
const { header, feature, content, additionalHeaderComponents } =
|
const { header, feature, content, additionalHeaderComponents } =
|
||||||
accordionInfo[key];
|
accordionInfo[key];
|
||||||
|
|
||||||
|
// do not render if panel is disabled in global state
|
||||||
|
if (enabledParameterPanels[key] !== false) {
|
||||||
accordionsToRender.push(
|
accordionsToRender.push(
|
||||||
<InvokeAccordionItem
|
<InvokeAccordionItem
|
||||||
key={key}
|
key={key}
|
||||||
@ -48,6 +52,7 @@ const ParametersAccordion = (props: ParametersAccordionsType) => {
|
|||||||
additionalHeaderComponents={additionalHeaderComponents}
|
additionalHeaderComponents={additionalHeaderComponents}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return accordionsToRender;
|
return accordionsToRender;
|
||||||
|
@ -44,7 +44,7 @@ const ImageToImageParameters = () => {
|
|||||||
content: <VariationsSettings />,
|
content: <VariationsSettings />,
|
||||||
additionalHeaderComponents: <GenerateVariationsToggle />,
|
additionalHeaderComponents: <GenerateVariationsToggle />,
|
||||||
},
|
},
|
||||||
face_restore: {
|
faceRestore: {
|
||||||
header: `${t('parameters.faceRestoration')}`,
|
header: `${t('parameters.faceRestoration')}`,
|
||||||
feature: Feature.FACE_CORRECTION,
|
feature: Feature.FACE_CORRECTION,
|
||||||
content: <FaceRestoreSettings />,
|
content: <FaceRestoreSettings />,
|
||||||
|
@ -38,7 +38,7 @@ const TextToImageParameters = () => {
|
|||||||
content: <VariationsSettings />,
|
content: <VariationsSettings />,
|
||||||
additionalHeaderComponents: <GenerateVariationsToggle />,
|
additionalHeaderComponents: <GenerateVariationsToggle />,
|
||||||
},
|
},
|
||||||
face_restore: {
|
faceRestore: {
|
||||||
header: `${t('parameters.faceRestoration')}`,
|
header: `${t('parameters.faceRestoration')}`,
|
||||||
feature: Feature.FACE_CORRECTION,
|
feature: Feature.FACE_CORRECTION,
|
||||||
content: <FaceRestoreSettings />,
|
content: <FaceRestoreSettings />,
|
||||||
|
@ -16,6 +16,16 @@ const initialtabsState: UIState = {
|
|||||||
addNewModelUIOption: null,
|
addNewModelUIOption: null,
|
||||||
shouldPinGallery: true,
|
shouldPinGallery: true,
|
||||||
shouldShowGallery: true,
|
shouldShowGallery: true,
|
||||||
|
enabledParameterPanels: {
|
||||||
|
general: true,
|
||||||
|
seed: true,
|
||||||
|
variations: true,
|
||||||
|
faceRestore: true,
|
||||||
|
upscale: true,
|
||||||
|
symmetry: true,
|
||||||
|
other: true,
|
||||||
|
imageToImage: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialState: UIState = initialtabsState;
|
const initialState: UIState = initialtabsState;
|
||||||
|
@ -13,4 +13,5 @@ export interface UIState {
|
|||||||
addNewModelUIOption: AddNewModelType;
|
addNewModelUIOption: AddNewModelType;
|
||||||
shouldPinGallery: boolean;
|
shouldPinGallery: boolean;
|
||||||
shouldShowGallery: boolean;
|
shouldShowGallery: boolean;
|
||||||
|
enabledParameterPanels: { [key: string]: boolean };
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { store } from 'app/store';
|
import { initializeStore } from 'app/store';
|
||||||
import { persistStore } from 'redux-persist';
|
import { persistStore } from 'redux-persist';
|
||||||
|
|
||||||
export const persistor = persistStore(store);
|
export const persistor = persistStore(initializeStore({}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user