feat(ui): disable panels based on app props

This commit is contained in:
Mary Hipp 2023-04-04 14:12:19 -04:00
parent cc3401a159
commit 9820829edb
9 changed files with 112 additions and 50 deletions

View File

@ -68,6 +68,7 @@ declare module '@invoke-ai/invoke-ai-ui' {
interface InvokeProps extends PropsWithChildren {
apiUrl?: string;
disabledPanels?: string[];
}
declare function Invoke(props: InvokeProps): JSX.Element;

View File

@ -5,16 +5,28 @@ import storage from 'redux-persist/lib/storage'; // defaults to localStorage for
import { getPersistConfig } from 'redux-deep-persist';
import canvasReducer from 'features/canvas/store/canvasSlice';
import galleryReducer from 'features/gallery/store/gallerySlice';
import resultsReducer from 'features/gallery/store/resultsSlice';
import uploadsReducer from 'features/gallery/store/uploadsSlice';
import lightboxReducer from 'features/lightbox/store/lightboxSlice';
import generationReducer from 'features/parameters/store/generationSlice';
import postprocessingReducer from 'features/parameters/store/postprocessingSlice';
import systemReducer from 'features/system/store/systemSlice';
import uiReducer from 'features/ui/store/uiSlice';
import apiReducer from 'services/apiSlice';
import canvasReducer, { canvasSlice } from 'features/canvas/store/canvasSlice';
import galleryReducer, {
gallerySlice,
} from 'features/gallery/store/gallerySlice';
import resultsReducer, {
resultsSlice,
} from 'features/gallery/store/resultsSlice';
import uploadsReducer, {
uploadsSlice,
} 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 as nodesSocketioMiddleware } from './nodesSocketio/middleware';
@ -113,28 +125,60 @@ 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
export const store = configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
immutableCheck: false,
serializableCheck: false,
}).concat(buildMiddleware()),
devTools: {
// Uncommenting these very rapidly called actions makes the redux dev tools output much more readable
actionsDenylist: [
'canvas/setCursorPosition',
'canvas/setStageCoordinates',
'canvas/setStageScale',
'canvas/setIsDrawing',
'canvas/setBoundingBoxCoordinates',
'canvas/setBoundingBoxDimensions',
'canvas/setIsDrawing',
'canvas/addPointToCurrentLine',
],
},
});
export const initializeStore = ({ disabledPanels = [] }: InitializeStore) =>
configureStore({
reducer: persistedReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
immutableCheck: false,
serializableCheck: false,
}).concat(buildMiddleware()),
preloadedState: {
ui: {
...uiSlice.getInitialState(),
enabledParameterPanels: disablePanels({
disabledPanels,
enabledParameterPanels:
uiSlice.getInitialState().enabledParameterPanels,
}),
},
},
devTools: {
// Uncommenting these very rapidly called actions makes the redux dev tools output much more readable
actionsDenylist: [
'canvas/setCursorPosition',
'canvas/setStageCoordinates',
'canvas/setStageScale',
'canvas/setIsDrawing',
'canvas/setBoundingBoxCoordinates',
'canvas/setBoundingBoxDimensions',
'canvas/setIsDrawing',
'canvas/addPointToCurrentLine',
],
},
});
const store = initializeStore({});
export type AppGetState = typeof store.getState;
export type RootState = ReturnType<typeof store.getState>;

View File

@ -1,7 +1,7 @@
import React, { lazy, PropsWithChildren, useEffect } from 'react';
import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/integration/react';
import { store } from './app/store';
import { initializeStore } from './app/store';
import { persistor } from './persistor';
import { OpenAPI } from 'services/api';
import '@fontsource/inter/100.css';
@ -24,16 +24,17 @@ const ThemeLocaleProvider = lazy(() => import('./app/ThemeLocaleProvider'));
interface Props extends PropsWithChildren {
apiUrl?: string;
disabledPanels?: string[];
}
export default function Component({ apiUrl, children }: Props) {
export default function Component({ apiUrl, disabledPanels, children }: Props) {
useEffect(() => {
if (apiUrl) OpenAPI.BASE = apiUrl;
}, [apiUrl]);
return (
<React.StrictMode>
<Provider store={store}>
<Provider store={initializeStore({ disabledPanels })}>
<PersistGate loading={<Loading />} persistor={persistor}>
<React.Suspense fallback={<Loading showText />}>
<ThemeLocaleProvider>

View File

@ -21,9 +21,10 @@ type ParametersAccordionsType = {
const ParametersAccordion = (props: ParametersAccordionsType) => {
const { accordionInfo } = props;
const openAccordions = useAppSelector(
(state: RootState) => state.system.openAccordions
);
const { system, ui } = useAppSelector((state: RootState) => state);
const { openAccordions } = system;
const { enabledParameterPanels } = ui;
const dispatch = useAppDispatch();
@ -39,15 +40,19 @@ const ParametersAccordion = (props: ParametersAccordionsType) => {
Object.keys(accordionInfo).forEach((key) => {
const { header, feature, content, additionalHeaderComponents } =
accordionInfo[key];
accordionsToRender.push(
<InvokeAccordionItem
key={key}
header={header}
feature={feature}
content={content}
additionalHeaderComponents={additionalHeaderComponents}
/>
);
// do not render if panel is disabled in global state
if (enabledParameterPanels[key] !== false) {
accordionsToRender.push(
<InvokeAccordionItem
key={key}
header={header}
feature={feature}
content={content}
additionalHeaderComponents={additionalHeaderComponents}
/>
);
}
});
}
return accordionsToRender;

View File

@ -44,7 +44,7 @@ const ImageToImageParameters = () => {
content: <VariationsSettings />,
additionalHeaderComponents: <GenerateVariationsToggle />,
},
face_restore: {
faceRestore: {
header: `${t('parameters.faceRestoration')}`,
feature: Feature.FACE_CORRECTION,
content: <FaceRestoreSettings />,

View File

@ -38,7 +38,7 @@ const TextToImageParameters = () => {
content: <VariationsSettings />,
additionalHeaderComponents: <GenerateVariationsToggle />,
},
face_restore: {
faceRestore: {
header: `${t('parameters.faceRestoration')}`,
feature: Feature.FACE_CORRECTION,
content: <FaceRestoreSettings />,

View File

@ -16,6 +16,16 @@ const initialtabsState: UIState = {
addNewModelUIOption: null,
shouldPinGallery: true,
shouldShowGallery: true,
enabledParameterPanels: {
general: true,
seed: true,
variations: true,
faceRestore: true,
upscale: true,
symmetry: true,
other: true,
imageToImage: true,
},
};
const initialState: UIState = initialtabsState;

View File

@ -13,4 +13,5 @@ export interface UIState {
addNewModelUIOption: AddNewModelType;
shouldPinGallery: boolean;
shouldShowGallery: boolean;
enabledParameterPanels: { [key: string]: boolean };
}

View File

@ -1,4 +1,4 @@
import { store } from 'app/store';
import { initializeStore } from 'app/store';
import { persistStore } from 'redux-persist';
export const persistor = persistStore(store);
export const persistor = persistStore(initializeStore({}));