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.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
fix(ui): normalize preset icons
joshistoast2ca58719503b
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsxindex 0c069194b6..6df2fc76a5 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetAdminDialogs.tsx@@ -8,6 +8,8 @@ import { useWorkbenchCommands, useWorkbenchSelector } from '@workbench/Workbenchimport { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import type { LayoutPresetDialogValue } from './layoutPresetDialogModel';+import { LayoutPresetDialog } from './LayoutPresetDialog';import { closeLayoutPresetAdmin, layoutPresetManagerStore } from './layoutPresetManagerStore';@@ -37,15 +39,7 @@ export const LayoutPresetAdminDialogs = () => {const sourceOptions = useMemo(() => (editTarget ? getLayoutPresetSourceOptions(editTarget) : []), [editTarget]);const submitEdit = useCallback(- ({- defaultRoute,- iconId,- name,- }: {- defaultRoute: Parameters<typeof layout.setPresetRoute>[1];- iconId: string;- name: string;- }) => {+ ({ defaultRoute, iconId, name }: LayoutPresetDialogValue) => {if (editTarget) {layout.setPresetRoute(editTarget.id, defaultRoute);layout.renamePreset(editTarget.id, name);diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsxindex d9def54b73..453f3251f8 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetDialog.tsx@@ -27,8 +27,10 @@ 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';+import type { LayoutPresetDialogValue } from './layoutPresetDialogModel';++import { getInitialLayoutPresetIconId, getInitialLayoutPresetRoute } from './layoutPresetDialogModel';+import { layoutPresetIconGroups } from './layoutPresetIcons';const layoutPresetIconIds = layoutPresetIconGroups.flatMap((group) => group.options.map((option) => option.id));const destinationWidgetTypeIds: Record<ResultDestination, 'canvas' | 'gallery'> = {@@ -86,14 +88,14 @@ export const LayoutPresetDialog = ({isOpen: boolean;name: string;onClose: () => void;- onSubmit: (value: { defaultRoute: LayoutPresetRoute | null; iconId: string; name: string }) => void;+ onSubmit: (value: LayoutPresetDialogValue) => 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 [iconId, setIconId] = useState(() => getInitialLayoutPresetIconId(initialIconId));const [defaultRoute, setDefaultRoute] = useState(() =>getInitialLayoutPresetRoute(initialDefaultRoute, sourceOptions));diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsxindex b1ede9f802..9e92c5324f 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetStrip.tsx@@ -1,5 +1,5 @@import type { DragEndEvent } from '@dnd-kit/core';-import type { LayoutPreset, LayoutPresetId, LayoutPresetRoute } from '@workbench/layoutContracts';+import type { LayoutPreset, LayoutPresetId } from '@workbench/layoutContracts';import type { Project } from '@workbench/projectContracts';import type { KeyboardEvent, MouseEvent } from 'react';@@ -29,6 +29,8 @@ import {import { useCallback, useMemo, useState } from 'react';import { useTranslation } from 'react-i18next';+import type { LayoutPresetDialogValue } from './layoutPresetDialogModel';+import { LayoutPresetDialog } from './LayoutPresetDialog';import { resolveLayoutPresetIcon } from './layoutPresetIcons';import { openLayoutPresetDelete, openLayoutPresetEdit, openLayoutPresetManager } from './layoutPresetManagerStore';@@ -88,7 +90,7 @@ export const LayoutPresetStrip = () => {const openSaveAsDialog = useCallback(() => setIsSaveAsOpen(true), []);const closeSaveAsDialog = useCallback(() => setIsSaveAsOpen(false), []);const saveAsNewPreset = useCallback(- ({ defaultRoute, iconId, name }: { defaultRoute: LayoutPresetRoute | null; iconId: string; name: string }) =>+ ({ defaultRoute, iconId, name }: LayoutPresetDialogValue) =>layout.createPreset(createCustomPresetId(), name, iconId, defaultRoute),[layout]);diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.tsindex aa9fa35aa4..dd18a77af4 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.ts+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.test.ts@@ -1,9 +1,15 @@import { graphWidgetSources } from '@workbench/graphWidgets';import { describe, expect, it } from 'vitest';-import { getInitialLayoutPresetRoute } from './layoutPresetDialogModel';+import { getInitialLayoutPresetIconId, getInitialLayoutPresetRoute } from './layoutPresetDialogModel';describe('layout preset dialog model', () => {+ it('falls back to a focusable icon when a persisted icon id is unknown', () => {+ expect(getInitialLayoutPresetIconId('star')).toBe('star');+ expect(getInitialLayoutPresetIconId('retired-icon')).toBe('layout-grid');+ expect(getInitialLayoutPresetIconId(undefined)).toBe('layout-grid');+ });+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'diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.ts b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.tsindex 1767938360..63c9955a54 100644--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.ts+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/layoutPresetDialogModel.ts@@ -3,6 +3,17 @@ import type { LayoutPresetRoute } from '@workbench/layoutContracts';import { getNaturalDestination } from '@workbench/graphWidgets';+import { DEFAULT_LAYOUT_PRESET_ICON_ID, isLayoutPresetIconId } from './layoutPresetIcons';++export interface LayoutPresetDialogValue {+ defaultRoute: LayoutPresetRoute | null;+ iconId: string;+ name: string;+}++export const getInitialLayoutPresetIconId = (iconId: unknown): string =>+ isLayoutPresetIconId(iconId) ? iconId : DEFAULT_LAYOUT_PRESET_ICON_ID;+export const getInitialLayoutPresetRoute = (defaultRoute: LayoutPresetRoute | undefined,sourceOptions: readonly GraphWidgetSource[]