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(gallery): exit similarity search when the view moves
Lincoln Steinef92fea7f676
diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.test.tsindex c11ee181fb..78f4aaa648 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.test.ts@@ -4112,6 +4112,138 @@ describe('workbenchReducer Phase 5 generation flow', () => {expect(getActiveProject(state).settings.showProgressImagesInViewer).toBe(false);});+ it('exits a similarity search when the view moves to another board', () => {+ // A ranking answers with images from wherever they live, so it is not a+ // view OF any board; left up, a board click would be answered with the+ // same results under a new board name.+ let state = createInitialWorkbenchState();++ state = workbenchReducer(state, { boardId: 'board-a', type: 'selectGalleryBoard' });+ state = workbenchReducer(state, {+ type: 'patchWidgetValues',+ values: { galleryPage: 4, semanticImageQuery: { kind: 'text', query: 'sunset' } },+ widgetId: 'gallery',+ });++ state = workbenchReducer(state, { boardId: 'board-b', type: 'selectGalleryBoard' });++ const values = getProjectWidgetValues(getActiveProject(state), 'gallery');++ expect(values.semanticImageQuery).toBeNull();+ expect(values.selectedBoardId).toBe('board-b');+ expect(values.galleryPage).toBe(0);+ });++ it('keeps a similarity search when the board already shown is picked again', () => {+ // A text or image reference survives a reload, so a click that changes+ // nothing about the view must not erase persisted state — and autosave+ // the loss — on what reads as a no-op.+ let state = createInitialWorkbenchState();++ state = workbenchReducer(state, { boardId: 'board-a', type: 'selectGalleryBoard' });+ state = workbenchReducer(state, {+ type: 'patchWidgetValues',+ values: { semanticImageQuery: { kind: 'text', query: 'sunset' } },+ widgetId: 'gallery',+ });++ state = workbenchReducer(state, { boardId: 'board-a', type: 'selectGalleryBoard' });++ expect(getProjectWidgetValues(getActiveProject(state), 'gallery').semanticImageQuery).toEqual({+ kind: 'text',+ query: 'sunset',+ });+ });++ it('leaves the page stamped on the selection alone when a search is dismissed by a board move', () => {+ // The selection here was made BEFORE the search, so its page is a real+ // board position that the search never rewrote (setSemanticImageQuery+ // touches only the grid's page). Zeroing it — as the adoption path must,+ // having no better information — would cost Preview the cursor it still+ // has and strand its arrows at the top of the board.+ let state = createInitialWorkbenchState();++ state = workbenchReducer(state, { boardId: 'board-a', type: 'selectGalleryBoard' });+ state = workbenchReducer(state, {+ item: createGalleryImageItem('deep.png'),+ selectionPage: 7,+ type: 'selectGalleryItem',+ });+ state = workbenchReducer(state, {+ type: 'patchWidgetValues',+ values: { semanticImageQuery: { kind: 'text', query: 'sunset' } },+ widgetId: 'gallery',+ });++ state = workbenchReducer(state, { boardId: 'board-b', type: 'selectGalleryBoard' });++ const values = getProjectWidgetValues(getActiveProject(state), 'gallery');++ expect(values.semanticImageQuery).toBeNull();+ expect(values.selectedImagePage).toBe(7);+ expect((values.selectedImageQuery as { boardId: string; page: number }).page).toBe(7);+ expect((values.selectedImageQuery as { boardId: string; page: number }).boardId).toBe('board-a');+ });++ it('exits a similarity search when the Images/Assets tab is switched, but not when it is re-clicked', () => {+ // The two tabs are two listings and the ranking is a view of neither. A+ // gallery that never touched the setting has no galleryView at all, and+ // that reads as Images — so clicking Images there is not a switch.+ let state = createInitialWorkbenchState();++ state = workbenchReducer(state, {+ type: 'patchWidgetValues',+ values: { semanticImageQuery: { kind: 'text', query: 'sunset' } },+ widgetId: 'gallery',+ });++ state = workbenchReducer(state, { galleryView: 'images', type: 'setGalleryView' });++ expect(getProjectWidgetValues(getActiveProject(state), 'gallery').semanticImageQuery).toEqual({+ kind: 'text',+ query: 'sunset',+ });++ state = workbenchReducer(state, { galleryView: 'assets', type: 'setGalleryView' });++ const values = getProjectWidgetValues(getActiveProject(state), 'gallery');++ expect(values.semanticImageQuery).toBeNull();+ expect(values.galleryView).toBe('assets');+ });++ it('exits a similarity search when the board being viewed is deleted', () => {+ // Deleting the viewed board moves the view to Uncategorized without+ // going through `selectGalleryBoard`, so the rule has to be applied here+ // too — otherwise the ranking survives under a board name that is gone.+ let state = createInitialWorkbenchState();++ state = workbenchReducer(state, { boardId: 'doomed-board', type: 'selectGalleryBoard' });+ state = workbenchReducer(state, {+ type: 'patchWidgetValues',+ values: { semanticImageQuery: { kind: 'text', query: 'sunset' } },+ widgetId: 'gallery',+ });++ state = workbenchReducer(state, {+ outcome: {+ boardId: 'doomed-board',+ deletedBoardImageNames: [],+ deletedBoardVideoNames: [],+ deletedImageNames: [],+ deletedVideoNames: [],+ failedImageNames: [],+ failedVideoNames: [],+ },+ type: 'reconcileDeletedGalleryBoard',+ });++ const values = getProjectWidgetValues(getActiveProject(state), 'gallery');++ expect(values.selectedBoardId).toBe('none');+ expect(values.semanticImageQuery).toBeNull();+ });+it('stores selected backend board id for gallery submissions', () => {let state = createInitialWorkbenchState();diff --git a/invokeai/frontend/webv2/src/workbench/workbenchState.ts b/invokeai/frontend/webv2/src/workbench/workbenchState.tsindex 667315949c..e3a2d36066 100644--- a/invokeai/frontend/webv2/src/workbench/workbenchState.ts+++ b/invokeai/frontend/webv2/src/workbench/workbenchState.ts@@ -2797,7 +2797,9 @@ const reconcileDeletedGalleryBoard = (return {...values,- ...(selectedBoardWasDeleted ? { galleryPage: 0, selectedBoardId: 'none' } : {}),+ // Same rule as `selectGalleryBoard`: the view is moving to another+ // board, so a ranking shown against the old one goes with it.+ ...(selectedBoardWasDeleted ? { galleryPage: 0, selectedBoardId: 'none', semanticImageQuery: null } : {}),...(projectBoardWasDeleted ? { projectBoardId: null } : {}),};});@@ -4581,6 +4583,20 @@ export const __workbenchReducerInternal = (galleryPage: 0,selectedBoardId: action.boardId,selectedImageNames: [],+ // A similarity ranking answers with images from wherever they live,+ // so it is not a view OF any board: moving to one asks for that+ // board's listing, and leaving the ranking up would answer with the+ // same results under a new board name. Dismissed exactly as the+ // chip's own clear does it — the query alone. The positions on the+ // selection are NOT rewritten here: a selection made before the+ // search carries a real board page that the search never touched,+ // and zeroing it would cost Preview the cursor it still has.+ //+ // Only on an actual move. Re-picking the board already shown is not+ // a change of view, and a text or image reference survives a reload,+ // so treating that click as a dismissal would erase persisted state+ // (and autosave the loss) on what reads as a no-op.+ ...(values.selectedBoardId !== action.boardId ? { semanticImageQuery: null } : {}),}),action.projectId);@@ -4600,6 +4616,15 @@ export const __workbenchReducerInternal = (galleryPage: 0,galleryView: action.galleryView,selectedImageNames: [],+ // Same rule as `selectGalleryBoard`, and for the same reason: the+ // Images/Assets tabs are two listings, and a ranking is a view of+ // neither, so switching tabs asks for the listing rather than the+ // same results relabelled. Only on an actual switch — an absent+ // `galleryView` reads as Images, so re-clicking the tab already+ // shown must stay the no-op it is today.+ ...((values.galleryView === 'assets' ? 'assets' : 'images') !== action.galleryView+ ? { semanticImageQuery: null }+ : {}),}),action.projectId);