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
feat(webv2): add Find in Gallery to image context menus
Josh Corbettf600eadffc51
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 8a372a009b..da9b31abe8 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@@ -15,6 +15,9 @@ import { EMPTY_IMAGE_RECALL_CAPABILITIES } from './imageRecall';const NO_BOARDS: [] = [];+const findGalleryItem = vi.fn();++vi.mock('@workbench/image-actions/useFindGalleryItem', () => ({ useFindGalleryItem: () => findGalleryItem }));vi.mock('@workbench/useOpenWorkbenchWidget', () => ({ useOpenWorkbenchWidget: () => vi.fn() }));vi.mock('@workbench/WorkbenchContext', () => ({useWorkbenchCommands: () => ({@@ -227,6 +230,32 @@ describe('ImageContextMenu deletion delegation', () => {});});+describe('ImageContextMenu find in gallery', () => {+ it('reveals a single image or video by its gallery reference', async () => {+ findGalleryItem.mockClear();+ await renderMenu(createActions(vi.fn()), [image('still.png')]);+ await interact(() => getMenuItem('widgets.gallery.findInGallery').click());+ expect(findGalleryItem).toHaveBeenCalledExactlyOnceWith({ kind: 'image', name: 'still.png' });++ await interact(() => root?.unmount());+ const video = item('video', 'clip.mp4');+ await renderItemMenu(createActions(vi.fn()), {+ itemRefs: [{ kind: 'video', name: video.name }],+ items: [video],+ x: 20,+ y: 20,+ });+ await interact(() => getMenuItem('widgets.gallery.findInGallery').click());+ expect(findGalleryItem).toHaveBeenLastCalledWith({ kind: 'video', name: 'clip.mp4' });+ });++ it('is absent from bulk menus, which have no single item to reveal', async () => {+ await renderMenu(createActions(vi.fn()), [image('a.png'), image('b.png')]);++ expect(document.body.textContent).not.toContain('widgets.gallery.findInGallery');+ });+});+describe('ImageContextMenu load workflow', () => {it('enables Load Workflow once the image is known to embed one and hands the image to the action', async () => {const actions = createActions(vi.fn());diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsxindex 2196566c0d..95888ff599 100644--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.tsx@@ -12,6 +12,7 @@ import {} from '@features/gallery';import { MenuContent, MenuIconItem } from '@platform/ui';import { MiddleTruncate } from '@platform/ui/MiddleTruncate';+import { useFindGalleryItem } from '@workbench/image-actions/useFindGalleryItem';import { useOpenWorkbenchWidget } from '@workbench/useOpenWorkbenchWidget';import { useWorkbenchCommands } from '@workbench/WorkbenchContext';import {@@ -20,6 +21,7 @@ import {AudioLinesIcon,ChevronRightIcon,CopyIcon,+ CrosshairIcon,DownloadIcon,ExternalLinkIcon,EyeIcon,@@ -496,6 +498,7 @@ const SingleItemMenuItems = ({<Menu.Separator borderColor="border.subtle" /></>) : null}+ <FindInGalleryMenuItem itemRef={itemRef} /><ChangeBoardSubMenu boards={boards} currentBoardId={item.boardId} onMove={handleMove} /><Menu.Separator borderColor="border.subtle" /><ContextMenuItem@@ -730,6 +733,7 @@ const SingleImageMenuItems = ({[actions, image.imageName]);const handleDelete = useCallback(() => onRequestDeletion([image.imageName]), [image.imageName, onRequestDeletion]);+ const imageItemRef = useMemo<GalleryItemRef>(() => ({ kind: 'image', name: image.imageName }), [image.imageName]);const handleRecallAll = useRecallImageDataHandler(actions, image, 'all');const handleRecallRemix = useRecallImageDataHandler(actions, image, 'remix');const handleRecallPrompts = useRecallImageDataHandler(actions, image, 'prompts');@@ -853,6 +857,7 @@ const SingleImageMenuItems = ({/><Menu.Separator borderColor="border.subtle" /><NewFromImageSubMenu actions={actions} images={images} isBulk={false} />+ <FindInGalleryMenuItem itemRef={imageItemRef} /><ChangeBoardSubMenu boards={boards} currentBoardId={image.boardId} onMove={handleMove} /><Menu.Separator borderColor="border.subtle" /><ContextMenuItem isDanger icon={Trash2Icon} label="Delete Image" value="delete-image" onClick={handleDelete} />@@ -1036,6 +1041,21 @@ const GalleryCanvasImportDestinationMenuItem = ({return <ContextMenuItem icon={LayersIcon} label={t(item.label)} value={item.value} onClick={handleClick} />;};+const FindInGalleryMenuItem = ({ itemRef }: { itemRef: GalleryItemRef }) => {+ const { t } = useTranslation();+ const findGalleryItem = useFindGalleryItem();+ const handleClick = useCallback(() => findGalleryItem(itemRef), [findGalleryItem, itemRef]);++ return (+ <ContextMenuItem+ icon={CrosshairIcon}+ label={t('widgets.gallery.findInGallery')}+ value="find-in-gallery"+ onClick={handleClick}+ />+ );+};+const ChangeBoardSubMenu = ({boards,currentBoardId,