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(webv2): complete mixed gallery action behavior
joshistoastc7168bfa842c
diff --git a/.superpowers/sdd/mixed-media-gallery-parity/task-7b-report.md b/.superpowers/sdd/mixed-media-gallery-parity/task-7b-report.mdindex df593a970d..4246bfc9f0 100644--- a/.superpowers/sdd/mixed-media-gallery-parity/task-7b-report.md+++ b/.superpowers/sdd/mixed-media-gallery-parity/task-7b-report.md@@ -307,3 +307,137 @@ architecture: 3 files passed, 34 tests passed## ConcernsNone.++## Independent review fix round++An independent review of `a1ec2acbcb` found two action-integration gaps:++1. After a partial deletion confirmed the primary item deleted,+ `removeItems()` retained failed qualified refs, but+ `selectItem(successor)` replaced that surviving selection.+2. Video-only and mixed common bulk menus omitted the required primary-item+ `Open in new tab` and `Open in preview` actions.++### Fix-round RED++The partial-deletion selection regression was added first:++```sh+pnpm test:browser src/workbench/image-actions/useImageActions.browser.test.tsx+```++```text+Test Files 1 failed (1)+Tests 1 failed | 18 passed (19)+```++The failure showed that no atomic multi-selection write occurred after a+same-name image primary succeeded while ordered image/video failures remained+selected.++The two common bulk-menu regressions then produced:++```sh+pnpm test:browser src/workbench/image-actions/ImageContextMenu.browser.test.tsx+```++```text+Test Files 1 failed (1)+Tests 2 failed | 5 passed (7)+```++Both a video-only multi-selection and a mixed selection with an unresolved+secondary ref lacked the primary open actions.++### Fix-round implementation++- Partial delete now intersects `result.failed` with the original ordered+ requested refs by qualified key. When a successor exists, one+ `setItemMultiSelection` write retains those failed keys in their original+ order, appends the successor key, and makes the eligible successor primary.+- Same-name image/video failures remain separate. A failed ref is never chosen+ as primary. When no eligible successor exists, the confirmed-only+ `removeItems` write leaves failed keys materialized/selected without+ promoting one.+- Common bulk menus now receive the already-loaded canonical primary item and+ expose `Open in new tab` and `Open in preview` against it.+- The bulk path still renders no image clipboard, comparison, canvas,+ prompt-template, or metadata-recall group. Native video preview rendering+ remains Task 8.++### Fix-round focused GREEN++```sh+pnpm test:browser \+ src/workbench/image-actions/useImageActions.browser.test.tsx \+ src/workbench/image-actions/ImageContextMenu.browser.test.tsx+```++```text+Test Files 2 passed (2)+Tests 26 passed (26)+```++### Fix-round full verification++```sh+pnpm lint:tsc+```++```text+tsc --noEmit: passed+```++```sh+pnpm test+```++```text+Test Files 376 passed (376)+Tests 4973 passed (4973)+```++```sh+pnpm test:browser+```++```text+Test Files 64 passed (64)+Tests 292 passed (292)+```++The browser suite retained its existing React `act(...)`,+missing-i18n-instance, and intentional error-boundary diagnostics and exited+successfully.++```sh+pnpm test:fixtures+```++```text+Tests 4 passed (4)+```++```sh+pnpm architecture:check+```++```text+Test Files 3 passed (3)+Tests 34 passed (34)+```++```sh+pnpm lint+```++```text+format: all matched files correctly formatted+oxlint: zero warnings/errors+tsc --noEmit: passed+architecture: 3 files passed, 34 tests passed+```++The fix-round diff changes only the two existing action implementations, their+browser tests, and this report. `git diff --check` is clean, and no Task 8++surface or architecture exception was added.diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsxindex a0fd1bb0c7..f5e50c618c 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx@@ -280,6 +280,38 @@ describe('ImageContextMenu mixed-media action visibility', () => {expect(document.body.textContent).not.toContain('New from Image');});+ it('opens the primary video from a video-only multi-selection and keeps image-only actions hidden', async () => {+ const primaryVideo = item('video', 'primary.mp4');+ const secondaryVideo = item('video', 'secondary.mp4');+ const actions = createActions(vi.fn());+ await renderItemMenu(actions, {+ itemRefs: [+ { kind: 'video', name: primaryVideo.name },+ { kind: 'video', name: secondaryVideo.name },+ ],+ items: [primaryVideo, secondaryVideo],+ x: 20,+ y: 20,+ });++ const openInNewTab = document.querySelector<HTMLButtonElement>('[aria-label="Open in new tab"]');+ const openInPreview = document.querySelector<HTMLButtonElement>('[aria-label="Open in preview"]');+ expect(openInNewTab).not.toBeNull();+ expect(openInPreview).not.toBeNull();++ await interact(() => {+ openInNewTab?.click();+ openInPreview?.click();+ });++ expect(actions.openItemInNewTab).toHaveBeenCalledWith(primaryVideo);+ expect(actions.openItemInPreview).toHaveBeenCalledWith(primaryVideo);+ expect(document.body.textContent).not.toContain('Copy to clipboard');+ expect(document.body.textContent).not.toContain('Recall Metadata');+ expect(document.body.textContent).not.toContain('Select for Compare');+ expect(document.body.textContent).not.toContain('New from Images');+ });+it('keeps complete mixed refs for common bulk actions and hides image-only bulk actions when a ref is unresolved', async () => {const loadedImage = item('image', 'still.png');const actions = createActions(vi.fn());@@ -300,6 +332,17 @@ describe('ImageContextMenu mixed-media action visibility', () => {expect(document.body.textContent).toContain('Change Board');expect(document.body.textContent).toContain('Delete Selection');expect(document.body.textContent).not.toContain('New from Images');+ const openInNewTab = document.querySelector<HTMLButtonElement>('[aria-label="Open in new tab"]');+ const openInPreview = document.querySelector<HTMLButtonElement>('[aria-label="Open in preview"]');+ expect(openInNewTab).not.toBeNull();+ expect(openInPreview).not.toBeNull();++ await interact(() => {+ openInNewTab?.click();+ openInPreview?.click();+ });+ expect(actions.openItemInNewTab).toHaveBeenCalledWith(loadedImage);+ expect(actions.openItemInPreview).toHaveBeenCalledWith(loadedImage);await interact(() => getMenuItem('Star All').click());expect(actions.setItemsStarred).toHaveBeenCalledWith(refs, true);diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsxindex 8fe28c5023..be5743097f 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx@@ -293,6 +293,7 @@ const GalleryItemContextMenuContent = ({boards={boards}itemRefs={target.itemRefs}loadedItems={target.items}+ primaryItem={item}onRequestDeletion={onRequestDeletion}/>) : (@@ -380,15 +381,19 @@ const BulkItemMenuItems = ({boards,itemRefs,loadedItems,+ primaryItem,onRequestDeletion,}: {actions: ImageActions;boards: GalleryBoard[];itemRefs: GalleryItemRef[];loadedItems: GalleryItem[];+ primaryItem: GalleryItem;onRequestDeletion: (itemRefs: GalleryItemRef[]) => void;}) => {const allStarred = loadedItems.length === itemRefs.length && loadedItems.every((item) => item.starred);+ const handleOpenInNewTab = useCallback(() => actions.openItemInNewTab(primaryItem), [actions, primaryItem]);+ const handleOpenPreview = useCallback(() => actions.openItemInPreview(primaryItem), [actions, primaryItem]);const handleToggleStarred = useCallback(() => void actions.setItemsStarred(itemRefs, !allStarred),[actions, allStarred, itemRefs]@@ -409,6 +414,21 @@ const BulkItemMenuItems = ({{itemRefs.length} items selected</Text><Menu.Separator borderColor="border.subtle" />+ <HStack gap="1">+ <QuickMenuItem+ icon={ExternalLinkIcon}+ label="Open in new tab"+ value="open-primary-in-new-tab"+ onClick={handleOpenInNewTab}+ />+ <QuickMenuItem+ icon={EyeIcon}+ label="Open in preview"+ value="open-primary-in-preview"+ onClick={handleOpenPreview}+ />+ </HStack>+ <Menu.Separator borderColor="border.subtle" /><ContextMenuItemicon={StarIcon}label={allStarred ? 'Unstar All' : 'Star All'}diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsxindex 589d4bee2f..42aa69a70b 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.browser.test.tsx@@ -18,6 +18,7 @@ const mocks = vi.hoisted(() => ({galleryRemoveItems: vi.fn(),galleryPatchItems: vi.fn(),gallerySelectItem: vi.fn(),+ gallerySetItemMultiSelection: vi.fn(),invalidateGallery: vi.fn(),invalidateGalleryItems: vi.fn(),itemDelete: vi.fn(),@@ -85,6 +86,7 @@ vi.mock('@workbench/WorkbenchContext', () => ({removeItems: (...args: unknown[]) => mocks.galleryRemoveItems(...args),selectImage: vi.fn(),selectItem: (...args: unknown[]) => mocks.gallerySelectItem(...args),+ setItemMultiSelection: (...args: unknown[]) => mocks.gallerySetItemMultiSelection(...args),setCompareImage: vi.fn(),},generation: { patchSettings: vi.fn() },@@ -436,8 +438,14 @@ describe('primary successor after confirmed deletion', () => {]);});- expect(mocks.gallerySelectItem).toHaveBeenCalledWith(survivingBefore, 'project-1');+ expect(mocks.gallerySetItemMultiSelection).toHaveBeenCalledWith(+ ['video:failed-before.mp4', 'image:surviving-before.png'],+ survivingBefore,+ 'project-1'+ );+ expect(mocks.gallerySelectItem).not.toHaveBeenCalled();+ mocks.gallerySetItemMultiSelection.mockClear();mocks.gallerySelectItem.mockClear();mocks.itemDelete.mockResolvedValue({affectedBoardIds: [],@@ -449,6 +457,49 @@ describe('primary successor after confirmed deletion', () => {await getItemActions().deleteItems([{ kind: 'image', name: primary.name }]);});+ expect(mocks.gallerySetItemMultiSelection).not.toHaveBeenCalled();+ expect(mocks.gallerySelectItem).not.toHaveBeenCalled();+ });++ it('atomically retains failed qualified selections while promoting a surviving successor', async () => {+ const successor = galleryItem('image', 'successor.png');+ const primary = galleryItem('image', 'shared');+ const failedSameNameVideo = galleryItem('video', 'shared');+ const failedImage = galleryItem('image', 'failed.png');+ const requested = [+ { kind: 'image' as const, name: failedImage.name },+ { kind: 'image' as const, name: primary.name },+ { kind: 'video' as const, name: failedSameNameVideo.name },+ ];+ currentItemActionContext = {+ filterIdentity: 'filter-a',+ items: [successor, primary, failedSameNameVideo, failedImage],+ loadOrderedRefs: () =>+ Promise.resolve([+ { kind: 'image' as const, name: successor.name },+ { kind: 'video' as const, name: failedSameNameVideo.name },+ { kind: 'image' as const, name: primary.name },+ { kind: 'image' as const, name: failedImage.name },+ ]),+ selectedItemKey: 'image:shared',+ };+ const result = {+ affectedBoardIds: ['board-1'],+ failed: [requested[0], requested[2]],+ succeeded: [requested[1]],+ };+ mocks.itemDelete.mockResolvedValue(result);++ await act(async () => {+ await getItemActions().deleteItems(requested);+ });++ expect(mocks.galleryRemoveItems).toHaveBeenCalledWith(['image:shared']);+ expect(mocks.gallerySetItemMultiSelection).toHaveBeenCalledWith(+ ['image:failed.png', 'video:shared', 'image:successor.png'],+ successor,+ 'project-1'+ );expect(mocks.gallerySelectItem).not.toHaveBeenCalled();});diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.tsindex 64a54746bc..1a479249e2 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts+++ b/invokeai/frontend/webv2/src/workbench/image-actions/useImageActions.ts@@ -308,7 +308,16 @@ export const useImageActions = ({patchGalleryItemCaches(queryClient, { kind: 'delete', result });gallery.removeItems(result.succeeded.map(toGalleryItemKey));if (successor) {- gallery.selectItem(successor, projectId);+ const failedKeys = new Set(result.failed.map(toGalleryItemKey));+ const retainedFailedKeys = items+ .filter((item) => failedKeys.has(toGalleryItemKey(item)))+ .map(toGalleryItemKey);++ if (retainedFailedKeys.length > 0) {+ gallery.setItemMultiSelection([...retainedFailedKeys, toGalleryItemKey(successor)], successor, projectId);+ } else {+ gallery.selectItem(successor, projectId);+ }}onImagesDeleted?.(result.succeeded.filter((item) => item.kind === 'image').map((item) => item.name));},