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.

refactor(webv2): render both workflow dropdowns through one menu item fragment

joshistoast2b5b6fd8a0f0
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/MenuActionItem.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/MenuActionItem.tsx
new file mode 100644
index 0000000000..fd2e1d5f26
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/MenuActionItem.tsx
@@ -0,0 +1,58 @@
+import type { ElementType } from 'react';
+
+import { Icon, Menu, Stack, Text } from '@chakra-ui/react';
+
+/**
+ * The one menu-item composition every workflow dropdown renders through: a
+ * leading glyph, a label, and — for menus whose choices need explaining — a
+ * second hint line under it. The graph preview's "Open as" menu and the
+ * library rail's overflow menu keep their own, distinct item *sets*; what they
+ * share is this layout, which was hand-rolled twice and drifted (icon
+ * alignment, padding, disabled opacity) between the two.
+ *
+ * A hint switches the row to two lines, so the icon top-aligns with the label
+ * instead of floating centered against both.
+ */
+
+const DISABLED_ITEM = { opacity: 0.4 } as const;
+const SINGLE_LINE_LAYOUT = { alignItems: 'center', gap: '2.5', py: '1' } as const;
+const TWO_LINE_LAYOUT = { alignItems: 'flex-start', gap: '2.5', py: '1.5' } as const;
+const SINGLE_LINE_ICON = { boxSize: '3.5', flexShrink: 0 } as const;
+const TWO_LINE_ICON = { boxSize: '3.5', flexShrink: 0, mt: '0.5' } as const;
+
+export interface MenuActionItemProps {
+ /** Second line under the label, for choices whose consequences are not obvious. */
+ hint?: string;
+ icon: ElementType;
+ isDisabled?: boolean;
+ label: string;
+ /** `'danger'` is reserved for destructive choices (delete). */
+ tone?: 'danger';
+ /** Ark's item value, also mirrored to `data-menu-item` so tests can address the row. */
+ value: string;
+ onSelect: () => void;
+}
+
+export const MenuActionItem = ({ hint, icon, isDisabled, label, tone, value, onSelect }: MenuActionItemProps) => (
+ <Menu.Item
+ {...(hint ? TWO_LINE_LAYOUT : SINGLE_LINE_LAYOUT)}
+ _disabled={DISABLED_ITEM}
+ color={tone === 'danger' ? 'fg.error' : undefined}
+ data-menu-item={value}
+ disabled={isDisabled}
+ value={value}
+ onClick={onSelect}
+ >
+ <Icon as={icon} {...(hint ? TWO_LINE_ICON : SINGLE_LINE_ICON)} />
+ {hint ? (
+ <Stack gap="0" minW="0">
+ <Menu.ItemText>{label}</Menu.ItemText>
+ <Text color="fg.subtle" fontSize="2xs">
+ {hint}
+ </Text>
+ </Stack>
+ ) : (
+ <Menu.ItemText>{label}</Menu.ItemText>
+ )}
+ </Menu.Item>
+);
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewOpenAsMenu.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewOpenAsMenu.tsx
index 6802c059a9..b46164b7f0 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewOpenAsMenu.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/graph-preview/GraphPreviewOpenAsMenu.tsx
@@ -1,10 +1,11 @@
import type { WorkflowInvocationSourceId, WorkflowPreviewGraph } from '@features/workflow/ui/contracts';
import type { ReactNode } from 'react';
-import { Icon, Menu, Portal, Stack, Text } from '@chakra-ui/react';
+import { Menu, Portal } from '@chakra-ui/react';
import { previewGraphToDocument } from '@features/workflow/core/graphToDocument';
import { useInvocationTemplatesSnapshot } from '@features/workflow/react';
import { useSaveWorkflowToLibrary } from '@features/workflow/ui/library/useSaveWorkflowToLibrary';
+import { MenuActionItem } from '@features/workflow/ui/MenuActionItem';
import {
useWorkflowGraphPreview,
useWorkflowHostCommands,
@@ -16,11 +17,6 @@ import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
const MENU_POSITIONING = { placement: 'top-end' } as const;
-const DISABLED_PROPS = { opacity: 0.4 };
-// Items carry a two-line body (label + hint), so the icon top-aligns with the
-// label line instead of floating centered against both.
-const MENU_ITEM_LAYOUT = { alignItems: 'flex-start', gap: '2.5', py: '1.5' } as const;
-const MENU_ITEM_ICON_PROPS = { boxSize: '3.5', flexShrink: 0, mt: '0.5' } as const;
interface GraphPreviewOpenAsMenuProps {
children: ReactNode;
@@ -31,15 +27,6 @@ interface GraphPreviewOpenAsMenuProps {
onClose: () => void;
}
-const MenuItemBody = ({ hint, label }: { hint: string; label: string }) => (
- <Stack gap="0" minW="0">
- <Menu.ItemText>{label}</Menu.ItemText>
- <Text color="fg.subtle" fontSize="2xs">
- {hint}
- </Text>
- </Stack>
-);
-
/**
* The graph preview dialog's "Open as" menu — four ways to hand a
* read-only preview graph off to something that keeps it: convert it into an
@@ -146,41 +133,38 @@ export const GraphPreviewOpenAsMenu = ({
<Menu.Positioner>
<Menu.Content minW="16rem">
{canEditInEditor ? (
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- _disabled={DISABLED_PROPS}
- disabled={!isTemplatesLoaded}
+ <MenuActionItem
+ hint={t('graphPreview.editInEditorHint')}
+ icon={PencilRulerIcon}
+ isDisabled={!isTemplatesLoaded}
+ label={t('graphPreview.editInEditor')}
value="edit-in-editor"
- onClick={handleEditInEditor}
- >
- <Icon as={PencilRulerIcon} {...MENU_ITEM_ICON_PROPS} />
- <MenuItemBody hint={t('graphPreview.editInEditorHint')} label={t('graphPreview.editInEditor')} />
- </Menu.Item>
+ onSelect={handleEditInEditor}
+ />
) : null}
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- _disabled={DISABLED_PROPS}
- disabled={!isTemplatesLoaded}
+ <MenuActionItem
+ hint={t('graphPreview.saveToLibraryHint')}
+ icon={BookmarkIcon}
+ isDisabled={!isTemplatesLoaded}
+ label={t('graphPreview.saveToLibrary')}
value="save-to-library"
- onClick={handleSaveToLibrary}
- >
- <Icon as={BookmarkIcon} {...MENU_ITEM_ICON_PROPS} />
- <MenuItemBody hint={t('graphPreview.saveToLibraryHint')} label={t('graphPreview.saveToLibrary')} />
- </Menu.Item>
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- _disabled={DISABLED_PROPS}
- disabled={!isTemplatesLoaded}
+ onSelect={handleSaveToLibrary}
+ />
+ <MenuActionItem
+ hint={t('graphPreview.forkIntoProjectHint')}
+ icon={GitForkIcon}
+ isDisabled={!isTemplatesLoaded}
+ label={t('graphPreview.forkIntoProject')}
value="fork-into-project"
- onClick={handleForkIntoProject}
- >
- <Icon as={GitForkIcon} {...MENU_ITEM_ICON_PROPS} />
- <MenuItemBody hint={t('graphPreview.forkIntoProjectHint')} label={t('graphPreview.forkIntoProject')} />
- </Menu.Item>
- <Menu.Item {...MENU_ITEM_LAYOUT} value="download-json" onClick={handleDownloadJson}>
- <Icon as={DownloadIcon} {...MENU_ITEM_ICON_PROPS} />
- <MenuItemBody hint={t('graphPreview.downloadJsonHint')} label={t('graphPreview.downloadJson')} />
- </Menu.Item>
+ onSelect={handleForkIntoProject}
+ />
+ <MenuActionItem
+ hint={t('graphPreview.downloadJsonHint')}
+ icon={DownloadIcon}
+ label={t('graphPreview.downloadJson')}
+ value="download-json"
+ onSelect={handleDownloadJson}
+ />
</Menu.Content>
</Menu.Positioner>
</Portal>
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx
index f64090cfdb..fd80966112 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx
@@ -10,7 +10,12 @@ import {
getLibraryWorkflowCached,
invalidateWorkflowLibraryCache,
} from '@features/workflow/queries';
-import { useWorkflowGraphPreview, useWorkflowNotifications } from '@features/workflow/ui/WorkflowUiContext';
+import { MenuActionItem } from '@features/workflow/ui/MenuActionItem';
+import {
+ useOpenAddModels,
+ useWorkflowGraphPreview,
+ useWorkflowNotifications,
+} from '@features/workflow/ui/WorkflowUiContext';
import { parseWorkflowJson } from '@features/workflow/utility';
import { downloadText } from '@platform/browser/downloadBlob';
import {
@@ -54,10 +59,18 @@ import {
const DETAIL_RAIL_WIDTH = '18rem';
const THUMBNAIL_ASPECT_RATIO = 3 / 2;
-const DISABLED_ITEM = { opacity: 0.4 } as const;
const INSTALL_HOVER = { opacity: 0.85 } as const;
-const MENU_ITEM_LAYOUT = { alignItems: 'center', gap: '2.5', py: '1' } as const;
-const MENU_ITEM_ICON_PROPS = { boxSize: '3.5', flexShrink: 0 } as const;
+/**
+ * zag sets `min-width: fit-content` inline on every scroll-area content box, so
+ * the box grows to its *min-content* width — and a long workflow name
+ * contributes its full unbroken width there, however hard the heading itself
+ * truncates. The rail then scrolled sideways (with no horizontal scrollbar,
+ * since this area is vertical) and clipped every row in it. An inline override
+ * is what it takes to beat an inline style; zeroing it makes the content box
+ * stretch to the viewport and nothing more, so the heading's truncation is what
+ * actually gives.
+ */
+const RAIL_CONTENT_PROPS = { style: { minWidth: 0 } } as const;
export interface WorkflowLibraryDetailPanelProps {
entry: WorkflowLibraryEntry | null;
@@ -84,6 +97,7 @@ export const WorkflowLibraryDetailPanel = ({
const deps = useModelRequirementDeps();
const notify = useWorkflowNotifications();
const { openDocumentInNewProject } = useWorkflowGraphPreview();
+ const openAddModels = useOpenAddModels();
const { installMany } = useInstallActions();
// Keyed by URL rather than a boolean, so a selection change re-arms the
// thumbnail without an effect resetting the flag.
@@ -119,6 +133,16 @@ export const WorkflowLibraryDetailPanel = ({
const handleThumbnailError = useCallback(() => setFailedThumbnailUrl(entry?.item.thumbnail_url ?? null), [entry]);
+ // Add Models is a different page, so the library has to get out of the way —
+ // the same handoff a fork into a new project makes.
+ const handleFindModel = useCallback(
+ (query: string) => {
+ openAddModels(query);
+ onClose();
+ },
+ [onClose, openAddModels]
+ );
+
const install = useCallback(async () => {
const owner = captureAccountScope();
const starterBySource = new Map(deps.starterModels.map((starter) => [starter.source, starter]));
@@ -307,7 +331,7 @@ export const WorkflowLibraryDetailPanel = ({
rounded="md"
w={DETAIL_RAIL_WIDTH}
>
- <Scrollable flex="1" label={name} minH="0">
+ <Scrollable contentProps={RAIL_CONTENT_PROPS} flex="1" label={name} minH="0" minW="0">
<Stack gap="2" minW="0" p="2.5">
<Stack gap="1" minW="0">
<Box aspectRatio={THUMBNAIL_ASPECT_RATIO} bg="bg.muted" overflow="hidden" rounded="md" w="full">
@@ -357,6 +381,7 @@ export const WorkflowLibraryDetailPanel = ({
<WorkflowRequirementsList
errorMessage={enrichment?.status === 'error' ? enrichment.message : null}
resolved={resolved}
+ onFindModel={handleFindModel}
/>
</Stack>
</Scrollable>
@@ -392,51 +417,40 @@ export const WorkflowLibraryDetailPanel = ({
<Portal>
<Menu.Positioner>
<MenuContent minW="12rem">
- <Menu.Item {...MENU_ITEM_LAYOUT} data-menu-item="open" value="open" onClick={handleOpen}>
- <Icon as={WorkflowIcon} {...MENU_ITEM_ICON_PROPS} />
- <Menu.ItemText>{t('workflowLibrary.open')}</Menu.ItemText>
- </Menu.Item>
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- _disabled={DISABLED_ITEM}
- data-menu-item="duplicate"
- disabled={isDuplicatePending}
+ <MenuActionItem
+ icon={WorkflowIcon}
+ label={t('workflowLibrary.open')}
+ value="open"
+ onSelect={handleOpen}
+ />
+ <MenuActionItem
+ icon={CopyIcon}
+ isDisabled={isDuplicatePending}
+ label={t('workflowLibrary.duplicate')}
value="duplicate"
- onClick={handleDuplicate}
- >
- <Icon as={CopyIcon} {...MENU_ITEM_ICON_PROPS} />
- <Menu.ItemText>{t('workflowLibrary.duplicate')}</Menu.ItemText>
- </Menu.Item>
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- data-menu-item="fork-into-project"
+ onSelect={handleDuplicate}
+ />
+ <MenuActionItem
+ icon={GitForkIcon}
+ label={t('workflowLibrary.forkIntoProject')}
value="fork-into-project"
- onClick={handleFork}
- >
- <Icon as={GitForkIcon} {...MENU_ITEM_ICON_PROPS} />
- <Menu.ItemText>{t('workflowLibrary.forkIntoProject')}</Menu.ItemText>
- </Menu.Item>
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- data-menu-item="download-json"
+ onSelect={handleFork}
+ />
+ <MenuActionItem
+ icon={DownloadIcon}
+ label={t('workflowLibrary.downloadJson')}
value="download-json"
- onClick={handleDownload}
- >
- <Icon as={DownloadIcon} {...MENU_ITEM_ICON_PROPS} />
- <Menu.ItemText>{t('workflowLibrary.downloadJson')}</Menu.ItemText>
- </Menu.Item>
+ onSelect={handleDownload}
+ />
{item.category === 'user' ? (
// Bundled defaults are not the account's to delete.
- <Menu.Item
- {...MENU_ITEM_LAYOUT}
- color="fg.error"
- data-menu-item="delete"
+ <MenuActionItem
+ icon={Trash2Icon}
+ label={t('workflowLibrary.delete')}
+ tone="danger"
value="delete"
- onClick={openDeleteConfirm}
- >
- <Icon as={Trash2Icon} {...MENU_ITEM_ICON_PROPS} />
- <Menu.ItemText>{t('workflowLibrary.delete')}</Menu.ItemText>
- </Menu.Item>
+ onSelect={openDeleteConfirm}
+ />
) : null}
</MenuContent>
</Menu.Positioner>