mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add support to disableTabs
This commit is contained in:
2
invokeai/frontend/web/index.d.ts
vendored
2
invokeai/frontend/web/index.d.ts
vendored
@ -1,6 +1,7 @@
|
|||||||
import React, { PropsWithChildren } from 'react';
|
import React, { PropsWithChildren } from 'react';
|
||||||
import { IAIPopoverProps } from '../web/src/common/components/IAIPopover';
|
import { IAIPopoverProps } from '../web/src/common/components/IAIPopover';
|
||||||
import { IAIIconButtonProps } from '../web/src/common/components/IAIIconButton';
|
import { IAIIconButtonProps } from '../web/src/common/components/IAIIconButton';
|
||||||
|
import { InvokeTabName } from 'features/ui/store/tabMap';
|
||||||
|
|
||||||
export {};
|
export {};
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ declare module '@invoke-ai/invoke-ai-ui' {
|
|||||||
interface InvokeProps extends PropsWithChildren {
|
interface InvokeProps extends PropsWithChildren {
|
||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
disabledPanels?: string[];
|
disabledPanels?: string[];
|
||||||
|
disabledTabs?: InvokeTabName[];
|
||||||
}
|
}
|
||||||
|
|
||||||
declare function Invoke(props: InvokeProps): JSX.Element;
|
declare function Invoke(props: InvokeProps): JSX.Element;
|
||||||
|
@ -15,13 +15,15 @@ import ImageGalleryPanel from 'features/gallery/components/ImageGalleryPanel';
|
|||||||
import Lightbox from 'features/lightbox/components/Lightbox';
|
import Lightbox from 'features/lightbox/components/Lightbox';
|
||||||
import { useAppDispatch, useAppSelector } from './storeHooks';
|
import { useAppDispatch, useAppSelector } from './storeHooks';
|
||||||
import { PropsWithChildren, useEffect } from 'react';
|
import { PropsWithChildren, useEffect } from 'react';
|
||||||
import { setDisabledPanels } from 'features/ui/store/uiSlice';
|
import { setDisabledPanels, setDisabledTabs } from 'features/ui/store/uiSlice';
|
||||||
|
import { InvokeTabName } from 'features/ui/store/tabMap';
|
||||||
|
|
||||||
keepGUIAlive();
|
keepGUIAlive();
|
||||||
|
|
||||||
interface Props extends PropsWithChildren {
|
interface Props extends PropsWithChildren {
|
||||||
options: {
|
options: {
|
||||||
disabledPanels: string[];
|
disabledPanels: string[];
|
||||||
|
disabledTabs: InvokeTabName[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +38,10 @@ const App = (props: Props) => {
|
|||||||
dispatch(setDisabledPanels(props.options.disabledPanels));
|
dispatch(setDisabledPanels(props.options.disabledPanels));
|
||||||
}, [dispatch, props.options.disabledPanels]);
|
}, [dispatch, props.options.disabledPanels]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(setDisabledTabs(props.options.disabledTabs));
|
||||||
|
}, [dispatch, props.options.disabledTabs]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setColorMode(['light'].includes(currentTheme) ? 'light' : 'dark');
|
setColorMode(['light'].includes(currentTheme) ? 'light' : 'dark');
|
||||||
}, [setColorMode, currentTheme]);
|
}, [setColorMode, currentTheme]);
|
||||||
|
@ -4,6 +4,7 @@ import { PersistGate } from 'redux-persist/integration/react';
|
|||||||
import { store } from './app/store';
|
import { store } from './app/store';
|
||||||
import { persistor } from './persistor';
|
import { persistor } from './persistor';
|
||||||
import { OpenAPI } from 'services/api';
|
import { OpenAPI } from 'services/api';
|
||||||
|
import { InvokeTabName } from 'features/ui/store/tabMap';
|
||||||
import '@fontsource/inter/100.css';
|
import '@fontsource/inter/100.css';
|
||||||
import '@fontsource/inter/200.css';
|
import '@fontsource/inter/200.css';
|
||||||
import '@fontsource/inter/300.css';
|
import '@fontsource/inter/300.css';
|
||||||
@ -25,11 +26,13 @@ const ThemeLocaleProvider = lazy(() => import('./app/ThemeLocaleProvider'));
|
|||||||
interface Props extends PropsWithChildren {
|
interface Props extends PropsWithChildren {
|
||||||
apiUrl?: string;
|
apiUrl?: string;
|
||||||
disabledPanels?: string[];
|
disabledPanels?: string[];
|
||||||
|
disabledTabs?: InvokeTabName[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Component({
|
export default function Component({
|
||||||
apiUrl,
|
apiUrl,
|
||||||
disabledPanels = [],
|
disabledPanels = [],
|
||||||
|
disabledTabs = [],
|
||||||
children,
|
children,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -42,7 +45,7 @@ export default function Component({
|
|||||||
<PersistGate loading={<Loading />} persistor={persistor}>
|
<PersistGate loading={<Loading />} persistor={persistor}>
|
||||||
<React.Suspense fallback={<Loading showText />}>
|
<React.Suspense fallback={<Loading showText />}>
|
||||||
<ThemeLocaleProvider>
|
<ThemeLocaleProvider>
|
||||||
<App options={{ disabledPanels }}>{children}</App>
|
<App options={{ disabledPanels, disabledTabs }}>{children}</App>
|
||||||
</ThemeLocaleProvider>
|
</ThemeLocaleProvider>
|
||||||
</React.Suspense>
|
</React.Suspense>
|
||||||
</PersistGate>
|
</PersistGate>
|
||||||
|
@ -45,7 +45,8 @@ const tabIconStyles: ChakraProps['sx'] = {
|
|||||||
boxSize: 6,
|
boxSize: 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
const tabInfo: InvokeTabInfo[] = [
|
const buildTabs = (disabledTabs: InvokeTabName[]): InvokeTabInfo[] => {
|
||||||
|
const tabs: InvokeTabInfo[] = [
|
||||||
{
|
{
|
||||||
id: 'txt2img',
|
id: 'txt2img',
|
||||||
icon: <Icon as={MdTextFields} sx={tabIconStyles} />,
|
icon: <Icon as={MdTextFields} sx={tabIconStyles} />,
|
||||||
@ -76,7 +77,9 @@ const tabInfo: InvokeTabInfo[] = [
|
|||||||
icon: <Icon as={MdFlashOn} sx={tabIconStyles} />,
|
icon: <Icon as={MdFlashOn} sx={tabIconStyles} />,
|
||||||
workarea: <TrainingWIP />,
|
workarea: <TrainingWIP />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
return tabs.filter((tab) => !disabledTabs.includes(tab.id));
|
||||||
|
};
|
||||||
|
|
||||||
export default function InvokeTabs() {
|
export default function InvokeTabs() {
|
||||||
const activeTab = useAppSelector(activeTabIndexSelector);
|
const activeTab = useAppSelector(activeTabIndexSelector);
|
||||||
@ -85,13 +88,10 @@ export default function InvokeTabs() {
|
|||||||
(state: RootState) => state.lightbox.isLightboxOpen
|
(state: RootState) => state.lightbox.isLightboxOpen
|
||||||
);
|
);
|
||||||
|
|
||||||
const shouldPinGallery = useAppSelector(
|
const { shouldPinGallery, disabledTabs, shouldPinParametersPanel } =
|
||||||
(state: RootState) => state.ui.shouldPinGallery
|
useAppSelector((state: RootState) => state.ui);
|
||||||
);
|
|
||||||
|
|
||||||
const shouldPinParametersPanel = useAppSelector(
|
const activeTabs = buildTabs(disabledTabs);
|
||||||
(state: RootState) => state.ui.shouldPinParametersPanel
|
|
||||||
);
|
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ export default function InvokeTabs() {
|
|||||||
|
|
||||||
const tabs = useMemo(
|
const tabs = useMemo(
|
||||||
() =>
|
() =>
|
||||||
tabInfo.map((tab) => (
|
activeTabs.map((tab) => (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
key={tab.id}
|
key={tab.id}
|
||||||
hasArrow
|
hasArrow
|
||||||
@ -157,13 +157,13 @@ export default function InvokeTabs() {
|
|||||||
</Tab>
|
</Tab>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)),
|
)),
|
||||||
[t]
|
[t, activeTabs]
|
||||||
);
|
);
|
||||||
|
|
||||||
const tabPanels = useMemo(
|
const tabPanels = useMemo(
|
||||||
() =>
|
() =>
|
||||||
tabInfo.map((tab) => <TabPanel key={tab.id}>{tab.workarea}</TabPanel>),
|
activeTabs.map((tab) => <TabPanel key={tab.id}>{tab.workarea}</TabPanel>),
|
||||||
[]
|
[activeTabs]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -17,6 +17,7 @@ const initialtabsState: UIState = {
|
|||||||
shouldPinGallery: true,
|
shouldPinGallery: true,
|
||||||
shouldShowGallery: true,
|
shouldShowGallery: true,
|
||||||
disabledParameterPanels: [],
|
disabledParameterPanels: [],
|
||||||
|
disabledTabs: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialState: UIState = initialtabsState;
|
const initialState: UIState = initialtabsState;
|
||||||
@ -96,6 +97,9 @@ export const uiSlice = createSlice({
|
|||||||
setDisabledPanels: (state, action: PayloadAction<string[]>) => {
|
setDisabledPanels: (state, action: PayloadAction<string[]>) => {
|
||||||
state.disabledParameterPanels = action.payload;
|
state.disabledParameterPanels = action.payload;
|
||||||
},
|
},
|
||||||
|
setDisabledTabs: (state, action: PayloadAction<InvokeTabName[]>) => {
|
||||||
|
state.disabledTabs = action.payload;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -118,6 +122,7 @@ export const {
|
|||||||
toggleParametersPanel,
|
toggleParametersPanel,
|
||||||
toggleGalleryPanel,
|
toggleGalleryPanel,
|
||||||
setDisabledPanels,
|
setDisabledPanels,
|
||||||
|
setDisabledTabs,
|
||||||
} = uiSlice.actions;
|
} = uiSlice.actions;
|
||||||
|
|
||||||
export default uiSlice.reducer;
|
export default uiSlice.reducer;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { InvokeTabName } from './tabMap';
|
||||||
|
|
||||||
export type AddNewModelType = 'ckpt' | 'diffusers' | null;
|
export type AddNewModelType = 'ckpt' | 'diffusers' | null;
|
||||||
|
|
||||||
export interface UIState {
|
export interface UIState {
|
||||||
@ -14,4 +16,5 @@ export interface UIState {
|
|||||||
shouldPinGallery: boolean;
|
shouldPinGallery: boolean;
|
||||||
shouldShowGallery: boolean;
|
shouldShowGallery: boolean;
|
||||||
disabledParameterPanels: string[];
|
disabledParameterPanels: string[];
|
||||||
|
disabledTabs: InvokeTabName[];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user