Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(ui): edit preset routing

joshistoastd6da12251a32
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index daa35ddbf7..bf31089ec6 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -334,6 +334,8 @@
"builtIn": "Built-in",
"custom": "Custom",
"customLayouts": "Custom layouts",
+ "defaultDestination": "Default destination",
+ "defaultSource": "Default source",
"delete": "Delete preset",
"deleteBody": "Delete “{{name}}”? This only removes the saved preset.",
"deleteNamed": "Delete {{name}}",
@@ -350,8 +352,9 @@
"moreAvailable": "More layout presets, {{count}} available",
"name": "Preset name",
"none": "No custom presets yet. Arrange the dock, then choose Save as new preset.",
- "restore": "Restore the shipped arrangement",
- "restoreNamed": "Restore {{name}} default",
+ "noInvocationSource": "This layout does not contain an invocation source.",
+ "restore": "Restore shipped layout and routing",
+ "restoreNamed": "Restore {{name}} layout and routing defaults",
"revert": "Revert to saved layout",
"save": "Save preset",
"saveAs": "Save as new preset",
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx
index 14dbedda60..e1e18baf48 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx
@@ -1,11 +1,18 @@
+import type { LayoutPreset } from '@workbench/layoutContracts';
+
import { ConfirmDialog } from '@platform/ui/ConfirmDialog';
+import { getLayoutPresetSourceOptions } from '@workbench/layoutPresetRouting';
+import { layoutPresets } from '@workbench/layoutPresets';
+import { resolveSavedLayoutPreset } from '@workbench/layoutPresetSnapshots';
import { useWorkbenchCommands, useWorkbenchSelector } from '@workbench/WorkbenchContext';
-import { useCallback } from 'react';
+import { useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { LayoutPresetDialog } from './LayoutPresetDialog';
import { closeLayoutPresetAdmin, layoutPresetManagerStore } from './layoutPresetManagerStore';
+const EMPTY_LAYOUT_PRESETS: LayoutPreset[] = [];
+
/**
* Hosts the edit and delete dialogs shared by every preset-management surface.
* The trigger only writes a preset id to the store, which avoids mounting a
@@ -14,16 +21,38 @@ import { closeLayoutPresetAdmin, layoutPresetManagerStore } from './layoutPreset
export const LayoutPresetAdminDialogs = () => {
const { t } = useTranslation();
const { layout } = useWorkbenchCommands();
- const customPresets = useWorkbenchSelector((snapshot) => snapshot.account.customLayoutPresets ?? []);
+ const account = useWorkbenchSelector((snapshot) => snapshot.account);
+ const customPresets = account.customLayoutPresets ?? EMPTY_LAYOUT_PRESETS;
const { deletePresetId, editPresetId } = layoutPresetManagerStore.useSelector((snapshot) => snapshot);
- const editTarget = customPresets.find((preset) => preset.id === editPresetId) ?? null;
+ const editTarget = useMemo(() => {
+ if (!editPresetId) {
+ return null;
+ }
+
+ const exists = [...layoutPresets, ...customPresets].some((preset) => preset.id === editPresetId);
+
+ return exists ? resolveSavedLayoutPreset(account, editPresetId) : null;
+ }, [account, customPresets, editPresetId]);
const deleteTarget = customPresets.find((preset) => preset.id === deletePresetId) ?? null;
+ const sourceOptions = useMemo(() => (editTarget ? getLayoutPresetSourceOptions(editTarget) : []), [editTarget]);
const submitEdit = useCallback(
- ({ iconId, name }: { iconId: string; name: string }) => {
+ ({
+ defaultRoute,
+ iconId,
+ name,
+ }: {
+ defaultRoute: Parameters<typeof layout.setPresetRoute>[1];
+ iconId: string;
+ name: string;
+ }) => {
if (editTarget) {
- layout.renamePreset(editTarget.id, name);
- layout.setPresetIcon(editTarget.id, iconId);
+ layout.setPresetRoute(editTarget.id, defaultRoute);
+
+ if (!editTarget.isBuiltIn) {
+ layout.renamePreset(editTarget.id, name);
+ layout.setPresetIcon(editTarget.id, iconId);
+ }
}
},
[editTarget, layout]
@@ -38,9 +67,13 @@ export const LayoutPresetAdminDialogs = () => {
<>
{editTarget ? (
<LayoutPresetDialog
+ key={editTarget.id}
+ defaultRoute={editTarget.defaultRoute}
iconId={editTarget.iconId}
+ isBuiltIn={editTarget.isBuiltIn}
isOpen
name={editTarget.label}
+ sourceOptions={sourceOptions}
submitLabel={t('topbar.presets.save')}
title={t('topbar.presets.edit')}
onClose={closeLayoutPresetAdmin}
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsx
new file mode 100644
index 0000000000..92e7277dbf
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.browser.test.tsx
@@ -0,0 +1,113 @@
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { graphWidgetSources } from '@workbench/graphWidgets';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
+
+vi.mock('react-i18next', () => ({
+ useTranslation: () => ({
+ t: (key: string) =>
+ ({
+ 'common.cancel': 'Cancel',
+ 'topbar.presets.defaultDestination': 'Default destination',
+ 'topbar.presets.defaultSource': 'Default source',
+ 'topbar.presets.icon': 'Icon',
+ 'topbar.presets.iconPicker': 'Layout preset icon',
+ 'topbar.presets.name': 'Preset name',
+ 'topbar.presets.noInvocationSource': 'This layout does not contain an invocation source.',
+ })[key] ?? key,
+ }),
+}));
+
+import { LayoutPresetDialog } from './LayoutPresetDialog';
+
+const BUILT_IN_DEFAULT_ROUTE = { destination: 'gallery', sourceId: 'workflow' } as const;
+const BUILT_IN_SOURCE_OPTIONS = graphWidgetSources.filter(
+ (source) => source.sourceId === 'generate' || source.sourceId === 'workflow'
+);
+
+let host: HTMLDivElement | null = null;
+let root: Root | null = null;
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+afterEach(async () => {
+ await act(() => root?.unmount());
+ host?.remove();
+ host = null;
+ root = null;
+});
+
+describe('LayoutPresetDialog', () => {
+ it('edits only routing for a built-in preset and limits sources to its saved arrangement', async () => {
+ const onClose = vi.fn();
+ const onSubmit = vi.fn();
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+
+ await act(async () => {
+ root?.render(
+ <ChakraProvider value={system}>
+ <LayoutPresetDialog
+ defaultRoute={BUILT_IN_DEFAULT_ROUTE}
+ isBuiltIn
+ isOpen
+ name="Automate"
+ sourceOptions={BUILT_IN_SOURCE_OPTIONS}
+ submitLabel="Save preset"
+ title="Edit layout preset"
+ onClose={onClose}
+ onSubmit={onSubmit}
+ />
+ </ChakraProvider>
+ );
+ await new Promise<void>((resolve) => {
+ globalThis.setTimeout(resolve, 50);
+ });
+ });
+
+ expect(document.querySelector('input[name="layout-preset-name"]')).toBeNull();
+ expect(document.querySelector('[role="radiogroup"][aria-label="Layout preset icon"]')).toBeNull();
+ expect(document.body.textContent).toContain('Default source');
+ expect(document.body.textContent).toContain('Default destination');
+
+ const sourceSelect = document.querySelector<HTMLSelectElement>('select');
+ expect(Array.from(sourceSelect?.options ?? []).map((option) => option.value)).toEqual(['generate', 'workflow']);
+ expect(sourceSelect?.value).toBe('workflow');
+
+ const destinationGroup = document.querySelector<HTMLElement>('[data-scope="segment-group"][data-part="root"]');
+ expect(destinationGroup?.getAttribute('aria-label')).toBe('Default destination');
+
+ const sourceTrigger = document.querySelector<HTMLButtonElement>('[data-scope="select"][data-part="trigger"]');
+ expect(sourceTrigger).toBeDefined();
+ expect(sourceTrigger?.getAttribute('aria-label')).toBe('Default source');
+ await act(() => userEvent.click(sourceTrigger!));
+ const generateOption = Array.from(
+ document.querySelectorAll<HTMLElement>('[data-scope="select"][data-part="item"]')
+ ).find((option) => option.textContent === 'Generate');
+ expect(generateOption).toBeDefined();
+ await act(() => userEvent.click(generateOption!));
+
+ const canvasDestination = document.querySelector<HTMLInputElement>('input[type="radio"][value="canvas"]');
+ expect(canvasDestination).toBeDefined();
+ const canvasDestinationLabel = document.querySelector<HTMLLabelElement>(`label[for="${canvasDestination?.id}"]`);
+ expect(canvasDestinationLabel).toBeDefined();
+ await act(() => userEvent.click(canvasDestinationLabel!));
+
+ const submit = Array.from(document.querySelectorAll<HTMLButtonElement>('button')).find(
+ (button) => button.textContent === 'Save preset'
+ );
+ expect(submit).toBeDefined();
+ await act(() => userEvent.click(submit!));
+
+ expect(onSubmit).toHaveBeenCalledWith(
+ expect.objectContaining({
+ defaultRoute: { destination: 'canvas', sourceId: 'generate' },
+ name: 'Automate',
+ })
+ );
+ expect(onClose).toHaveBeenCalledOnce();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx
index 9ab4d842d2..b114b60333 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx
@@ -1,15 +1,49 @@
+import type { GraphWidgetSource } from '@workbench/graphWidgets';
+import type { InvocationSourceId, ResultDestination } from '@workbench/invocationContracts';
+import type { LayoutPresetRoute } from '@workbench/layoutContracts';
import type { FormEvent, KeyboardEvent } from 'react';
-import { chakra, Dialog, Icon, Input, Portal, SimpleGrid, Stack, Text } from '@chakra-ui/react';
+import {
+ chakra,
+ createListCollection,
+ Dialog,
+ HStack,
+ Icon,
+ Input,
+ Portal,
+ SegmentGroup,
+ SimpleGrid,
+ Stack,
+ Text,
+} from '@chakra-ui/react';
import { Button, CloseButton, IconButton } from '@platform/ui/Button';
import { Field } from '@platform/ui/Field';
+import { Select } from '@platform/ui/Select';
import { Tooltip } from '@platform/ui/Tooltip';
-import { useCallback, useRef, useState } from 'react';
+import { getNaturalDestination } from '@workbench/graphWidgets';
+import { WidgetIcon } from '@workbench/iconResolver';
+import { getDestinationLabel, resultDestinations } from '@workbench/invocation';
+import { getWidgetById } from '@workbench/widgetRegistry';
+import { useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { getInitialLayoutPresetRoute } from './layoutPresetDialogModel';
import { DEFAULT_LAYOUT_PRESET_ICON_ID, layoutPresetIconGroups } from './layoutPresetIcons';
const layoutPresetIconIds = layoutPresetIconGroups.flatMap((group) => group.options.map((option) => option.id));
+const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {
+ canvas: 'canvas',
+ gallery: 'gallery',
+};
+
+type SourceSelectItem = GraphWidgetSource & { value: InvocationSourceId };
+
+const renderSourceOption = (source: SourceSelectItem) => (
+ <HStack gap="1.5">
+ <WidgetIcon boxSize="3.5" icon={getWidgetById(source.typeId)?.manifest.icon} />
+ <Text as="span">{source.label}</Text>
+ </HStack>
+);
const getNextIconId = (currentIconId: string, key: string): string | null => {
if (key === 'Home') {
@@ -39,26 +73,46 @@ const getNextIconId = (currentIconId: string, key: string): string | null => {
* own layouts apart at a glance, not to browse an icon library.
*/
export const LayoutPresetDialog = ({
+ defaultRoute: initialDefaultRoute,
iconId: initialIconId,
+ isBuiltIn = false,
isOpen,
name: initialName,
onClose,
onSubmit,
+ sourceOptions,
submitLabel,
title,
}: {
+ defaultRoute?: LayoutPresetRoute;
iconId?: string;
+ isBuiltIn?: boolean;
isOpen: boolean;
name: string;
onClose: () => void;
- onSubmit: (value: { iconId: string; name: string }) => void;
+ onSubmit: (value: { defaultRoute: LayoutPresetRoute | null; iconId: string; name: string }) => void;
+ sourceOptions: readonly GraphWidgetSource[];
submitLabel: string;
title: string;
}) => {
const { t } = useTranslation();
const [name, setName] = useState(initialName);
const [iconId, setIconId] = useState(initialIconId ?? DEFAULT_LAYOUT_PRESET_ICON_ID);
+ const [defaultRoute, setDefaultRoute] = useState(() =>
+ getInitialLayoutPresetRoute(initialDefaultRoute, sourceOptions)
+ );
const nameRef = useRef<HTMLInputElement>(null);
+ const sourceCollection = useMemo(
+ () =>
+ createListCollection<SourceSelectItem>({
+ items: sourceOptions.map((source) => ({ ...source, value: source.sourceId })),
+ }),
+ [sourceOptions]
+ );
+ const sourceTriggerProps = useMemo(() => ({ 'aria-label': t('topbar.presets.defaultSource') }), [t]);
+ const selectedSource = sourceOptions.find((source) => source.sourceId === defaultRoute?.sourceId);
+ const sourceValue = useMemo(() => (defaultRoute ? [defaultRoute.sourceId] : []), [defaultRoute]);
+ const canSubmit = (isBuiltIn || name.trim().length > 0) && (sourceOptions.length === 0 || defaultRoute !== undefined);
// Without this the focus trap lands on the header's close button, so opening
// the dialog and typing does nothing. `initialFocusEl` rather than `autoFocus`
@@ -88,10 +142,10 @@ export const LayoutPresetDialog = ({
return;
}
- onSubmit({ iconId, name: trimmed });
+ onSubmit({ defaultRoute: defaultRoute ?? null, iconId, name: trimmed });
onClose();
},
- [iconId, name, onClose, onSubmit]
+ [defaultRoute, iconId, name, onClose, onSubmit]
);
const handleIconKeyDown = useCallback(
(event: KeyboardEvent<HTMLDivElement>) => {
@@ -110,9 +164,34 @@ export const LayoutPresetDialog = ({
},
[iconId]
);
+ const handleSourceChange = useCallback((event: { value: string[] }) => {
+ const sourceId = event.value[0] as InvocationSourceId | undefined;
+
+ if (!sourceId) {
+ return;
+ }
+
+ setDefaultRoute((route) => ({
+ destination: route?.destination ?? getNaturalDestination(sourceId),
+ sourceId,
+ }));
+ }, []);
+ const handleDestinationChange = useCallback((event: { value: string | null }) => {
+ if (!event.value) {
+ return;
+ }
+
+ setDefaultRoute((route) => (route ? { ...route, destination: event.value as ResultDestination } : route));
+ }, []);
return (
- <Dialog.Root initialFocusEl={initialFocusEl} open={isOpen} lazyMount unmountOnExit onOpenChange={handleOpenChange}>
+ <Dialog.Root
+ initialFocusEl={isBuiltIn ? undefined : initialFocusEl}
+ open={isOpen}
+ lazyMount
+ unmountOnExit
+ onOpenChange={handleOpenChange}
+ >
<Portal>
<Dialog.Backdrop />
<Dialog.Positioner>
@@ -126,53 +205,99 @@ export const LayoutPresetDialog = ({
</Dialog.Header>
<Dialog.Body>
<Stack gap="4">
- <Field label={t('topbar.presets.name')}>
- <Input
- ref={nameRef}
- autoComplete="off"
- name="layout-preset-name"
+ {isBuiltIn ? null : (
+ <>
+ <Field label={t('topbar.presets.name')}>
+ <Input
+ ref={nameRef}
+ autoComplete="off"
+ name="layout-preset-name"
+ size="sm"
+ value={name}
+ onChange={handleNameChange}
+ />
+ </Field>
+ <Stack
+ aria-label={t('topbar.presets.iconPicker')}
+ gap="3"
+ role="radiogroup"
+ tabIndex={-1}
+ onKeyDown={handleIconKeyDown}
+ >
+ <Text color="fg.subtle" fontSize="2xs" fontWeight="700" textTransform="uppercase">
+ {t('topbar.presets.icon')}
+ </Text>
+ {layoutPresetIconGroups.map((group) => (
+ <Stack key={group.label} gap="1.5">
+ <Text color="fg.muted" fontSize="2xs">
+ {group.label}
+ </Text>
+ <SimpleGrid columns={8} gap="1">
+ {group.options.map((entry) => (
+ <IconOption
+ key={entry.id}
+ icon={entry.icon}
+ iconId={entry.id}
+ isSelected={entry.id === iconId}
+ label={entry.label}
+ onSelect={setIconId}
+ />
+ ))}
+ </SimpleGrid>
+ </Stack>
+ ))}
+ </Stack>
+ </>
+ )}
+ <Field
+ helpText={sourceOptions.length === 0 ? t('topbar.presets.noInvocationSource') : undefined}
+ label={t('topbar.presets.defaultSource')}
+ >
+ <Select
+ collection={sourceCollection}
+ disabled={sourceOptions.length === 0}
+ renderItem={renderSourceOption}
size="sm"
- value={name}
- onChange={handleNameChange}
+ triggerProps={sourceTriggerProps}
+ value={sourceValue}
+ valueText={
+ selectedSource
+ ? renderSourceOption({ ...selectedSource, value: selectedSource.sourceId })
+ : undefined
+ }
+ onValueChange={handleSourceChange}
/>
</Field>
- <Stack
- aria-label={t('topbar.presets.iconPicker')}
- gap="3"
- role="radiogroup"
- tabIndex={-1}
- onKeyDown={handleIconKeyDown}
- >
- <Text color="fg.subtle" fontSize="2xs" fontWeight="700" textTransform="uppercase">
- {t('topbar.presets.icon')}
- </Text>
- {layoutPresetIconGroups.map((group) => (
- <Stack key={group.label} gap="1.5">
- <Text color="fg.muted" fontSize="2xs">
- {group.label}
- </Text>
- <SimpleGrid columns={8} gap="1">
- {group.options.map((entry) => (
- <IconOption
- key={entry.id}
- icon={entry.icon}
- iconId={entry.id}
- isSelected={entry.id === iconId}
- label={entry.label}
- onSelect={setIconId}
+ <Field disabled={!defaultRoute} label={t('topbar.presets.defaultDestination')}>
+ <SegmentGroup.Root
+ aria-label={t('topbar.presets.defaultDestination')}
+ disabled={!defaultRoute}
+ size="xs"
+ value={defaultRoute?.destination ?? null}
+ onValueChange={handleDestinationChange}
+ >
+ <SegmentGroup.Indicator />
+ {resultDestinations.map((destination) => (
+ <SegmentGroup.Item key={destination.id} flex="1" justifyContent="center" value={destination.id}>
+ <SegmentGroup.ItemHiddenInput />
+ <SegmentGroup.ItemText display="flex" alignItems="center" gap="1.5">
+ <WidgetIcon
+ boxSize="3.5"
+ icon={getWidgetById(destinationWidgetTypeIds[destination.id])?.manifest.icon}
/>
- ))}
- </SimpleGrid>
- </Stack>
- ))}
- </Stack>
+ {getDestinationLabel(destination.id)}
+ </SegmentGroup.ItemText>
+ </SegmentGroup.Item>
+ ))}
+ </SegmentGroup.Root>
+ </Field>
</Stack>
</Dialog.Body>
<Dialog.Footer>
<Button size="sm" type="button" variant="outline" onClick={onClose}>
{t('common.cancel')}
</Button>
- <Button disabled={name.trim().length === 0} size="sm" type="submit">
+ <Button disabled={!canSubmit} size="sm" type="submit">
{submitLabel}
</Button>
</Dialog.Footer>
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.tsx
index a103abc390..6bf80f7f1d 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.tsx
@@ -24,7 +24,12 @@ export const LayoutPresetManagerDialogBody = () => {
const { t } = useTranslation();
const customPresets = useWorkbenchSelector((snapshot) => snapshot.account.customLayoutPresets ?? []);
const overriddenPresetIds = useWorkbenchSelector((snapshot) =>
- Object.keys(snapshot.account.layoutPresetOverrides ?? {})
+ Array.from(
+ new Set([
+ ...Object.keys(snapshot.account.layoutPresetOverrides ?? {}),
+ ...Object.keys(snapshot.account.layoutPresetRouteOverrides ?? {}),
+ ])
+ )
);
const handleOpenChange = useCallback((event: { open: boolean }) => {
@@ -56,6 +61,7 @@ export const LayoutPresetManagerDialogBody = () => {
key={preset.id}
isOverridden={overriddenPresetIds.includes(preset.id)}
preset={preset}
+ onEdit={openLayoutPresetEdit}
/>
))}
</Stack>
@@ -92,12 +98,21 @@ export const LayoutPresetManagerDialogBody = () => {
);
};
-const BuiltInPresetRow = ({ isOverridden, preset }: { isOverridden: boolean; preset: LayoutPreset }) => {
+const BuiltInPresetRow = ({
+ isOverridden,
+ onEdit,
+ preset,
+}: {
+ isOverridden: boolean;
+ onEdit: (presetId: string) => void;
+ preset: LayoutPreset;
+}) => {
const { t } = useTranslation();
const { layout } = useWorkbenchCommands();
const { icon, tooltip } = getLayoutPresetPresentation(preset);
- // Clearing the override restores the shipped arrangement. Saving the shipped
- // snapshot back is exactly that, and needs no second reducer path.
+ const edit = useCallback(() => onEdit(preset.id), [onEdit, preset.id]);
+ // One restore action clears both independently persisted built-in edits: the
+ // spatial arrangement and its default invocation route.
const restoreDefault = useCallback(() => layout.restorePresetDefault(preset.id), [layout, preset.id]);
return (
@@ -111,6 +126,14 @@ const BuiltInPresetRow = ({ isOverridden, preset }: { isOverridden: boolean; pre
{isOverridden ? `${tooltip} · edited` : tooltip}
</Text>
</Stack>
+ <IconButton
+ aria-label={t('topbar.presets.editNamed', { name: preset.label })}
+ size="2xs"
+ variant="ghost"
+ onClick={edit}
+ >
+ <Icon as={PencilIcon} boxSize="3.5" />
+ </IconButton>
{isOverridden ? (
<Tooltip content={t('topbar.presets.restore')} showArrow>
<IconButton
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx
index 61ca7431cf..60fbeac636 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx
@@ -1,4 +1,5 @@
-import type { LayoutPreset } from '@workbench/layoutContracts';
+import type { LayoutPreset, LayoutPresetRoute } from '@workbench/layoutContracts';
+import type { Project } from '@workbench/projectContracts';
import type { KeyboardEvent, MouseEvent } from 'react';
import { Box, HStack, Icon, Menu, Portal, Text, VisuallyHidden } from '@chakra-ui/react';
@@ -6,13 +7,14 @@ import { IconButton } from '@platform/ui/Button';
import { MenuContent } from '@platform/ui/Menu';
import { Tabs } from '@platform/ui/Tabs';
import { Tooltip } from '@platform/ui/Tooltip';
+import { getPlacedWidgetTypeIds, graphWidgetSources } from '@workbench/graphWidgets';
import {
createLayoutPresetActivator,
loadLayoutPresetWidgets,
preloadLayoutPresetWidgets,
} from '@workbench/layoutPresetActivation';
import { layoutPresets } from '@workbench/layoutPresets';
-import { useWorkbenchCommands, useWorkbenchSelector } from '@workbench/WorkbenchContext';
+import { useActiveProjectSelector, useWorkbenchCommands, useWorkbenchSelector } from '@workbench/WorkbenchContext';
import {
ArrowRightIcon,
ChevronDownIcon,
@@ -39,6 +41,12 @@ const PRESET_SCROLL_CSS = { '&::-webkit-scrollbar': { display: 'none' }, scrollb
const createCustomPresetId = (): string =>
`custom-layout-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
+const selectPlacedGraphWidgetSources = (project: Project) => {
+ const placedTypeIds = getPlacedWidgetTypeIds(project);
+
+ return graphWidgetSources.filter((source) => placedTypeIds.has(source.typeId));
+};
+
export const LayoutPresetStrip = () => {
const { t } = useTranslation();
const { activePreset, hasDrifted } = useLayoutDrift();
@@ -47,7 +55,13 @@ export const LayoutPresetStrip = () => {
const [menuTarget, setMenuTarget] = useState<{ anchor: DOMRect; preset: LayoutPreset } | null>(null);
const customPresets = useWorkbenchSelector((snapshot) => snapshot.account.customLayoutPresets ?? []);
+ const invocation = useActiveProjectSelector((project) => project.invocation);
+ const sourceOptions = useActiveProjectSelector(selectPlacedGraphWidgetSources);
const presets = useMemo(() => [...layoutPresets, ...customPresets], [customPresets]);
+ const saveAsDefaultRoute = useMemo(
+ () => ({ destination: invocation.destination, sourceId: invocation.sourceId }),
+ [invocation.destination, invocation.sourceId]
+ );
const activatePreset = useMemo(
() => createLayoutPresetActivator({ apply: layout.applyPreset, load: loadLayoutPresetWidgets }),
[layout.applyPreset]
@@ -74,7 +88,8 @@ export const LayoutPresetStrip = () => {
const openSaveAsDialog = useCallback(() => setIsSaveAsOpen(true), []);
const closeSaveAsDialog = useCallback(() => setIsSaveAsOpen(false), []);
const saveAsNewPreset = useCallback(
- ({ iconId, name }: { iconId: string; name: string }) => layout.createPreset(createCustomPresetId(), name, iconId),
+ ({ defaultRoute, iconId, name }: { defaultRoute: LayoutPresetRoute | null; iconId: string; name: string }) =>
+ layout.createPreset(createCustomPresetId(), name, iconId, defaultRoute),
[layout]
);
const closeMenu = useCallback(() => setMenuTarget(null), []);
@@ -139,14 +154,18 @@ export const LayoutPresetStrip = () => {
onEdit={requestEdit}
/>
- <LayoutPresetDialog
- isOpen={isSaveAsOpen}
- name={`${activePreset.label} copy`}
- submitLabel={t('topbar.presets.save')}
- title={t('topbar.presets.saveAs')}
- onClose={closeSaveAsDialog}
- onSubmit={saveAsNewPreset}
- />
+ {isSaveAsOpen ? (
+ <LayoutPresetDialog
+ defaultRoute={saveAsDefaultRoute}
+ isOpen
+ name={`${activePreset.label} copy`}
+ sourceOptions={sourceOptions}
+ submitLabel={t('topbar.presets.save')}
+ title={t('topbar.presets.saveAs')}
+ onClose={closeSaveAsDialog}
+ onSubmit={saveAsNewPreset}
+ />
+ ) : null}
</>
);
};
@@ -361,17 +380,15 @@ const PresetMenu = ({
</>
) : null}
+ <Menu.Item value="edit-preset" onClick={edit}>
+ <Icon as={PencilIcon} boxSize="3.5" />
+ <Menu.ItemText>{t('topbar.presets.editWithEllipsis')}</Menu.ItemText>
+ </Menu.Item>
{isCustom ? (
- <>
- <Menu.Item value="edit-preset" onClick={edit}>
- <Icon as={PencilIcon} boxSize="3.5" />
- <Menu.ItemText>{t('topbar.presets.editWithEllipsis')}</Menu.ItemText>
- </Menu.Item>
- <Menu.Item color="fg.error" value="delete-preset" _hover={DELETE_HOVER_PROPS} onClick={remove}>
- <Icon as={Trash2Icon} boxSize="3.5" />
- <Menu.ItemText>{t('topbar.presets.deleteWithEllipsis')}</Menu.ItemText>
- </Menu.Item>
- </>
+ <Menu.Item color="fg.error" value="delete-preset" _hover={DELETE_HOVER_PROPS} onClick={remove}>
+ <Icon as={Trash2Icon} boxSize="3.5" />
+ <Menu.ItemText>{t('topbar.presets.deleteWithEllipsis')}</Menu.ItemText>
+ </Menu.Item>
) : null}
<Menu.Separator />
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.ts
new file mode 100644
index 0000000000..aa9fa35aa4
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.ts
@@ -0,0 +1,22 @@
+import { graphWidgetSources } from '@workbench/graphWidgets';
+import { describe, expect, it } from 'vitest';
+
+import { getInitialLayoutPresetRoute } from './layoutPresetDialogModel';
+
+describe('layout preset dialog model', () => {
+ it('keeps an available saved route and repairs a stale source from the first available option', () => {
+ const options = graphWidgetSources.filter(
+ (source) => source.sourceId === 'generate' || source.sourceId === 'canvas'
+ );
+
+ expect(getInitialLayoutPresetRoute({ destination: 'canvas', sourceId: 'canvas' }, options)).toEqual({
+ destination: 'canvas',
+ sourceId: 'canvas',
+ });
+ expect(getInitialLayoutPresetRoute({ destination: 'gallery', sourceId: 'workflow' }, options)).toEqual({
+ destination: 'gallery',
+ sourceId: 'generate',
+ });
+ expect(getInitialLayoutPresetRoute({ destination: 'gallery', sourceId: 'workflow' }, [])).toBeUndefined();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.ts
new file mode 100644
index 0000000000..1767938360
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.ts
@@ -0,0 +1,17 @@
+import type { GraphWidgetSource } from '@workbench/graphWidgets';
+import type { LayoutPresetRoute } from '@workbench/layoutContracts';
+
+import { getNaturalDestination } from '@workbench/graphWidgets';
+
+export const getInitialLayoutPresetRoute = (
+ defaultRoute: LayoutPresetRoute | undefined,
+ sourceOptions: readonly GraphWidgetSource[]
+): LayoutPresetRoute | undefined => {
+ if (defaultRoute && sourceOptions.some((source) => source.sourceId === defaultRoute.sourceId)) {
+ return { ...defaultRoute };
+ }
+
+ const sourceId = sourceOptions[0]?.sourceId;
+
+ return sourceId ? { destination: getNaturalDestination(sourceId), sourceId } : undefined;
+};