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(workflow): right-click actions on library cards

Josh Corbett41a0d4b865a8
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx
index 3a1e43f7c5..0f6e99883d 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryCard.tsx
@@ -4,7 +4,7 @@ import { Badge, Box, Flex, HStack, Icon, Image, Skeleton, Stack, Text } from '@c
import { getModelBaseLabel } from '@features/models';
import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
import { ImageOffIcon } from 'lucide-react';
-import { useCallback, useState } from 'react';
+import { useCallback, useState, type MouseEvent } from 'react';
import { useTranslation } from 'react-i18next';
/**
@@ -14,9 +14,10 @@ import { useTranslation } from 'react-i18next';
* run it.
*
* A single click selects (the right rail follows the selection); a double
- * click opens. Enrichment fills the footer in asynchronously per entry, so
- * the strip reserves its height from the first paint and never reflows the
- * grid as counts arrive.
+ * click opens; a right click selects and asks for the rail's actions at the
+ * pointer. Enrichment fills the footer in asynchronously per entry, so the
+ * strip reserves its height from the first paint and never reflows the grid
+ * as counts arrive.
*/
const CARD_HOVER = { bg: 'bg.muted', borderColor: 'border.emphasized' } as const;
@@ -25,11 +26,15 @@ const CARD_TRANSITION =
'border-color var(--wb-motion-duration-medium) ease, background var(--wb-motion-duration-medium) ease';
const THUMBNAIL_ASPECT_RATIO = 3 / 2;
+/** The card's DOM id, which the rail's context menu names as its trigger so it nests under the dialog's layer. */
+export const getWorkflowLibraryCardId = (workflowId: string): string => `workflow-library-card-${workflowId}`;
+
export interface WorkflowLibraryCardProps {
entry: WorkflowLibraryEntry;
isSelected: boolean;
/** Models this workflow needs that are not installed; 0 hides the badge. */
missingCount: number;
+ onContextMenu: (workflowId: string, point: { x: number; y: number }) => void;
onOpen: (workflowId: string) => void;
onSelect: (workflowId: string) => void;
}
@@ -38,6 +43,7 @@ export const WorkflowLibraryCard = ({
entry,
isSelected,
missingCount,
+ onContextMenu,
onOpen,
onSelect,
}: WorkflowLibraryCardProps) => {
@@ -48,6 +54,22 @@ export const WorkflowLibraryCard = ({
const handleSelect = useCallback(() => onSelect(workflowId), [onSelect, workflowId]);
const handleOpen = useCallback(() => onOpen(workflowId), [onOpen, workflowId]);
+ const handleContextMenu = useCallback(
+ (event: MouseEvent<HTMLElement>) => {
+ event.preventDefault();
+
+ // A keyboard-raised menu (Shift+F10, the Menu key) carries no pointer
+ // position; anchor it inside the card instead of at the viewport corner.
+ const rect = event.currentTarget.getBoundingClientRect();
+ const fromKeyboard = event.clientX === 0 && event.clientY === 0;
+
+ onContextMenu(
+ workflowId,
+ fromKeyboard ? { x: rect.left + 16, y: rect.top + 16 } : { x: event.clientX, y: event.clientY }
+ );
+ },
+ [onContextMenu, workflowId]
+ );
const handleThumbnailError = useCallback(() => setHasThumbnailFailed(true), []);
// A broken <img> reads worse than the glyph, so a load failure falls back to
@@ -63,6 +85,7 @@ export const WorkflowLibraryCard = ({
borderColor={isSelected ? 'accent.solid' : 'border.subtle'}
borderWidth="1px"
data-workflow-card={workflowId}
+ id={getWorkflowLibraryCardId(workflowId)}
minW="0"
overflow="hidden"
rounded="lg"
@@ -72,6 +95,7 @@ export const WorkflowLibraryCard = ({
_focusVisible={CARD_FOCUS_VISIBLE}
_hover={CARD_HOVER}
onClick={handleSelect}
+ onContextMenu={handleContextMenu}
onDoubleClick={handleOpen}
>
<Box aspectRatio={THUMBNAIL_ASPECT_RATIO} bg="bg.muted" overflow="hidden" w="full">
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx
index b7d1958726..e386eaa297 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.browser.test.tsx
@@ -128,6 +128,8 @@ vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: translate }) }));
(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+const NOOP = () => {};
+
// #region Fixtures
const WAN_VAE_DEPENDENCY = {
@@ -282,8 +284,10 @@ describe('WorkflowLibraryDetailPanel', () => {
<WorkflowUiProvider adapter={ADAPTER}>
<WorkflowGraphPreviewProvider adapter={GRAPH_PREVIEW}>
<WorkflowLibraryDetailPanel
+ contextMenuPoint={null}
entry={selected}
onClose={onClose}
+ onContextMenuClose={NOOP}
onDeleted={onDeleted}
onDuplicated={onDuplicated}
onOpen={onOpen}
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 232e1ec6f0..07028a566f 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDetailPanel.tsx
@@ -38,6 +38,7 @@ import { useCallback, useMemo, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { formatRelativeTime } from './relativeTime';
+import { getWorkflowLibraryCardId } from './WorkflowLibraryCard';
import {
resolveEntryRequirements,
useModelRequirementDeps,
@@ -61,9 +62,12 @@ const THUMBNAIL_ASPECT_RATIO = 3 / 2;
const INSTALL_HOVER = { opacity: 0.85 } as const;
export interface WorkflowLibraryDetailPanelProps {
+ /** Where a card's right-click asked for the actions menu; null while it is closed. */
+ contextMenuPoint: { x: number; y: number } | null;
entry: WorkflowLibraryEntry | null;
/** The shell closes the library when a fork takes the user to a new project. */
onClose: () => void;
+ onContextMenuClose: () => void;
onDeleted: () => void;
/** Carries the copy's id so the shell can select it once the list refreshes. */
onDuplicated: (workflowId: string) => void;
@@ -71,11 +75,25 @@ export interface WorkflowLibraryDetailPanelProps {
onPreview: (entry: WorkflowLibraryEntry) => void;
}
+/** A right-click on another card moves the menu there (its own handler re-anchors it) rather than dismissing it. */
+const keepOpenForCardRightClick = (event: { detail: { originalEvent: Event }; preventDefault(): void }) => {
+ const original = event.detail.originalEvent;
+
+ if (original instanceof PointerEvent && original.button === 2 && isCardTarget(original.target)) {
+ event.preventDefault();
+ }
+};
+
+const isCardTarget = (target: EventTarget | null): boolean =>
+ target instanceof Element && target.closest('[data-workflow-card]') !== null;
+
const toFileSlug = (name: string): string => name.trim().replaceAll(/\s+/g, '-').toLowerCase() || 'workflow';
export const WorkflowLibraryDetailPanel = ({
+ contextMenuPoint,
entry,
onClose,
+ onContextMenuClose,
onDeleted,
onDuplicated,
onOpen,
@@ -270,6 +288,27 @@ export const WorkflowLibraryDetailPanel = ({
const openDeleteConfirm = useCallback(() => setIsDeleteConfirmOpen(true), []);
const closeDeleteConfirm = useCallback(() => setIsDeleteConfirmOpen(false), []);
+ const contextMenuPositioning = useMemo(
+ () => ({
+ getAnchorRect: () =>
+ contextMenuPoint ? { height: 1, width: 1, x: contextMenuPoint.x, y: contextMenuPoint.y } : null,
+ placement: 'bottom-start' as const,
+ }),
+ [contextMenuPoint]
+ );
+ const handleContextMenuOpenChange = useCallback(
+ (event: { open: boolean }) => {
+ if (!event.open) {
+ onContextMenuClose();
+ }
+ },
+ [onContextMenuClose]
+ );
+ const contextMenuIds = useMemo(
+ () => (entry ? { trigger: getWorkflowLibraryCardId(entry.item.workflow_id) } : undefined),
+ [entry]
+ );
+
const confirmDelete = useCallback(async () => {
if (!entry) {
return;
@@ -308,6 +347,52 @@ export const WorkflowLibraryDetailPanel = ({
? t('workflowLibrary.sampleOutput')
: null;
+ // One item set behind both the rail's overflow button and a card's right-click.
+ const actionItems = (
+ <>
+ <MenuActionItem
+ hint={t('workflowLibrary.openHint')}
+ icon={WorkflowIcon}
+ label={t('workflowLibrary.open')}
+ value="open"
+ onSelect={handleOpen}
+ />
+ <MenuActionItem
+ hint={t('workflowLibrary.duplicateHint')}
+ icon={CopyIcon}
+ isDisabled={isDuplicatePending}
+ label={t('workflowLibrary.duplicate')}
+ value="duplicate"
+ onSelect={handleDuplicate}
+ />
+ <MenuActionItem
+ hint={t('workflowLibrary.forkIntoProjectHint')}
+ icon={GitForkIcon}
+ label={t('workflowLibrary.forkIntoProject')}
+ value="fork-into-project"
+ onSelect={handleFork}
+ />
+ <MenuActionItem
+ hint={t('workflowLibrary.downloadJsonHint')}
+ icon={DownloadIcon}
+ label={t('workflowLibrary.downloadJson')}
+ value="download-json"
+ onSelect={handleDownload}
+ />
+ {item.category === 'user' ? (
+ // Bundled defaults are not the account's to delete.
+ <MenuActionItem
+ hint={t('workflowLibrary.deleteHint')}
+ icon={Trash2Icon}
+ label={t('workflowLibrary.delete')}
+ tone="danger"
+ value="delete"
+ onSelect={openDeleteConfirm}
+ />
+ ) : null}
+ </>
+ );
+
return (
<Stack
borderColor="border.subtle"
@@ -412,48 +497,7 @@ export const WorkflowLibraryDetailPanel = ({
</Menu.Trigger>
<Portal>
<Menu.Positioner>
- <MenuContent minW="16rem">
- <MenuActionItem
- hint={t('workflowLibrary.openHint')}
- icon={WorkflowIcon}
- label={t('workflowLibrary.open')}
- value="open"
- onSelect={handleOpen}
- />
- <MenuActionItem
- hint={t('workflowLibrary.duplicateHint')}
- icon={CopyIcon}
- isDisabled={isDuplicatePending}
- label={t('workflowLibrary.duplicate')}
- value="duplicate"
- onSelect={handleDuplicate}
- />
- <MenuActionItem
- hint={t('workflowLibrary.forkIntoProjectHint')}
- icon={GitForkIcon}
- label={t('workflowLibrary.forkIntoProject')}
- value="fork-into-project"
- onSelect={handleFork}
- />
- <MenuActionItem
- hint={t('workflowLibrary.downloadJsonHint')}
- icon={DownloadIcon}
- label={t('workflowLibrary.downloadJson')}
- value="download-json"
- onSelect={handleDownload}
- />
- {item.category === 'user' ? (
- // Bundled defaults are not the account's to delete.
- <MenuActionItem
- hint={t('workflowLibrary.deleteHint')}
- icon={Trash2Icon}
- label={t('workflowLibrary.delete')}
- tone="danger"
- value="delete"
- onSelect={openDeleteConfirm}
- />
- ) : null}
- </MenuContent>
+ <MenuContent minW="16rem">{actionItems}</MenuContent>
</Menu.Positioner>
</Portal>
</Menu.Root>
@@ -464,6 +508,24 @@ export const WorkflowLibraryDetailPanel = ({
</Button>
</Stack>
+ {/* Naming the card as the trigger makes this a nested layer of the dialog: the
+ dialog's focus trap then lets the menu keep focus, and closing returns it to the card. */}
+ <Menu.Root
+ ids={contextMenuIds}
+ open={contextMenuPoint !== null}
+ positioning={contextMenuPositioning}
+ onOpenChange={handleContextMenuOpenChange}
+ onPointerDownOutside={keepOpenForCardRightClick}
+ >
+ <Portal>
+ <Menu.Positioner>
+ <MenuContent data-workflow-context-menu minW="16rem">
+ {actionItems}
+ </MenuContent>
+ </Menu.Positioner>
+ </Portal>
+ </Menu.Root>
+
<ConfirmDialog
body={t('workflowLibrary.deleteConfirmBody', { name })}
confirmLabel={t('workflowLibrary.delete')}
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx
index 06c597afb9..e0d592e9a1 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.browser.test.tsx
@@ -15,6 +15,7 @@ import { system } from '@theme/system';
import { act, StrictMode } from 'react';
import { createRoot, type Root } from 'react-dom/client';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { userEvent } from 'vitest/browser';
// A plain static import of the (mocked) module the dialog `lazy()`-loads, so
// its dynamic `import()` resolves against an already-loaded module record
// instead of paying a first-time compile cost mid-test — that cost is what
@@ -660,6 +661,47 @@ describe('WorkflowLibraryDialog', () => {
expect(detail()?.textContent).toContain('Landscape Pass');
});
+ it('opens the rail actions for a card from a right-click and runs them', async () => {
+ await openWith(LOADED_SNAPSHOT);
+
+ await act(() =>
+ card('wf-landscape')?.dispatchEvent(
+ new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 120, clientY: 80 })
+ )
+ );
+
+ // The right-click selects the card, so the rail (which owns the actions) shows it.
+ expect(document.querySelector<HTMLElement>('[data-workflow-detail]')?.dataset.workflowDetail).toBe('wf-landscape');
+
+ const open = () => document.querySelector<HTMLElement>('[data-workflow-context-menu] [data-menu-item="open"]');
+
+ await vi.waitFor(() => expect(open()).not.toBeNull());
+ await act(() => open()?.click());
+
+ expect(loader.load).toHaveBeenCalledWith(LANDSCAPE.item);
+ });
+
+ it('closes the card context menu on Escape and hands focus back to the card', async () => {
+ await openWith(LOADED_SNAPSHOT);
+
+ // A keyboard-raised menu reports no pointer position.
+ await act(() =>
+ card('wf-landscape')?.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true }))
+ );
+
+ const menu = () => document.querySelector<HTMLElement>('[data-workflow-context-menu]');
+
+ await vi.waitFor(() => expect(menu()).not.toBeNull());
+ expect(menu()!.getBoundingClientRect().left).toBeGreaterThan(card('wf-landscape')!.getBoundingClientRect().left);
+
+ await act(async () => {
+ await userEvent.keyboard('{Escape}');
+ });
+
+ await vi.waitFor(() => expect(menu()).toBeNull());
+ await vi.waitFor(() => expect(document.activeElement).toBe(card('wf-landscape')));
+ });
+
it('opens the selected workflow from the rail, the keyboard-reachable path', async () => {
await openWith(LOADED_SNAPSHOT);
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx
index 03516e31df..f55fea5467 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryDialog.tsx
@@ -102,6 +102,9 @@ export const WorkflowLibraryDialog = ({
// what keeps the lazy dialog mounted) is only released once the transition
// has finished.
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
+ // A right-click selects the card so the rail (which owns the actions) shows
+ // that workflow, then the rail opens its menu at the pointer.
+ const [contextMenuPoint, setContextMenuPoint] = useState<{ x: number; y: number } | null>(null);
const searchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const closeDialog = useCallback(() => {
@@ -109,6 +112,7 @@ export const WorkflowLibraryDialog = ({
// is nothing left to animate against, so this drops the mount outright.
setPreviewEntry(null);
setIsPreviewOpen(false);
+ setContextMenuPoint(null);
onOpenChange(false);
}, [onOpenChange]);
const { load, loadPhase } = useLoadLibraryWorkflow(closeDialog);
@@ -210,7 +214,26 @@ export const WorkflowLibraryDialog = ({
// The deleted row is gone from the next refresh; dropping the selection lets
// the head of the list take over, the same way a filter change does.
- const handleDeleted = useCallback(() => setSelectedWorkflowId(null), []);
+ const handleDeleted = useCallback(() => {
+ setSelectedWorkflowId(null);
+ setContextMenuPoint(null);
+ }, []);
+ const handleCardContextMenu = useCallback(
+ (workflowId: string, point: { x: number; y: number }) => {
+ setSelectedWorkflowId(workflowId);
+
+ // An open menu does not follow a new anchor: close it and reopen it at the
+ // new point once that close has rendered, as a native menu relocates.
+ if (contextMenuPoint) {
+ setContextMenuPoint(null);
+ requestAnimationFrame(() => setContextMenuPoint(point));
+ } else {
+ setContextMenuPoint(point);
+ }
+ },
+ [contextMenuPoint]
+ );
+ const closeContextMenu = useCallback(() => setContextMenuPoint(null), []);
return (
<>
@@ -295,12 +318,15 @@ export const WorkflowLibraryDialog = ({
missingCounts={missingCounts}
selectedWorkflowId={activeWorkflowId}
status={status}
+ onContextMenu={handleCardContextMenu}
onOpen={handleOpenWorkflow}
onSelect={setSelectedWorkflowId}
/>
<WorkflowLibraryDetailPanel
+ contextMenuPoint={contextMenuPoint}
entry={activeEntry}
onClose={closeDialog}
+ onContextMenuClose={closeContextMenu}
onDeleted={handleDeleted}
onDuplicated={setSelectedWorkflowId}
onOpen={handleOpenItem}
diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx
index 888cc3c3a3..d5b4e8ad19 100644
--- a/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx
+++ b/invokeai/frontend/webv2/src/features/workflow/ui/library/WorkflowLibraryGrid.tsx
@@ -7,7 +7,7 @@ import { Scrollable } from '@platform/ui';
import { useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
-import { WorkflowLibraryCard } from './WorkflowLibraryCard';
+import { WorkflowLibraryCard, type WorkflowLibraryCardProps } from './WorkflowLibraryCard';
/**
* The scrolling card grid. Paging is server side and append-only: reaching the
@@ -27,6 +27,7 @@ export interface WorkflowLibraryGridProps {
missingCounts?: ReadonlyMap<string, number>;
selectedWorkflowId: string | null;
status: WorkflowLibraryBrowseSnapshot['status'];
+ onContextMenu: WorkflowLibraryCardProps['onContextMenu'];
onOpen: (workflowId: string) => void;
onSelect: (workflowId: string) => void;
}
@@ -54,6 +55,7 @@ export const WorkflowLibraryGrid = ({
entries,
error,
missingCounts = NO_MISSING_COUNTS,
+ onContextMenu,
onOpen,
onSelect,
selectedWorkflowId,
@@ -109,6 +111,7 @@ export const WorkflowLibraryGrid = ({
entry={entry}
isSelected={entry.item.workflow_id === selectedWorkflowId}
missingCount={missingCounts.get(entry.item.workflow_id) ?? 0}
+ onContextMenu={onContextMenu}
onOpen={onOpen}
onSelect={onSelect}
/>