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(gallery): offer a typed board name in both tiers and ask for names in a dialog
Josh Corbettce6590c1345a
diff --git a/docs/src/content/docs/Users Guide/06.Gallery/introduction.mdx b/docs/src/content/docs/Users Guide/06.Gallery/introduction.mdxindex b530ee2b95..8acf3a6d8e 100644--- a/docs/src/content/docs/Users Guide/06.Gallery/introduction.mdx+++ b/docs/src/content/docs/Users Guide/06.Gallery/introduction.mdx@@ -38,7 +38,7 @@ Each board shows its cover image, its name and a count such as **76 | 12**: 76 i### Creating a board-Type a name into **Search or create boards**. If no board has that name, a **Create board "…" in …** row appears, in the group the board will go to; click it, or press **Enter**. The open project's group and the **Library** group each have a **+** button: press one to choose where the board goes, then type its name — or type the name first and press the **+** of the group you want.+Type a name into **Search or create boards**. If no board has that name, a **Create board "…" in …** row appears in both the open project's group and the **Library** group; click the one where the board should live, or press **Enter** to create it in the project. Each of those two groups also has a **+** button, which asks for the board's name and creates it in that group; anything already typed in the search field is filled in for you.<Image src={createBoard} alt="Typing Seascapes into the board search field shows a Create board "Seascapes" row." width={420} />diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex 91b4fbc704..9fd561d336 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -4005,6 +4005,7 @@},"boardMoved": "Moved board \"{{name}}\" to {{destination}}","changeBoard": "Change Board",+ "createBoardIn": "Create board in {{destination}}","createBoardInLibrary": "Create a board in the Library","createBoardInProject": "Create a board in this project","createBoardNamedIn": "Create board \"{{name}}\" in {{destination}}",@@ -4049,7 +4050,6 @@"clearSemanticSearch": "Clear semantic search","exitSemanticSearch": "Exit semantic search","createBoard": "Create board",- "createBoardNamed": "Create board \"{{name}}\"","collapseStarredItems": "Collapse starred items","dateBoards": "Date boards","dateFilterDay": "{{date}}",diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardFilters.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardFilters.tsxindex c637e2f424..2351018b74 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardFilters.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardFilters.tsx@@ -14,7 +14,7 @@ import {SlidersHorizontalIcon,type LucideIcon,} from 'lucide-react';-import { useCallback, useMemo, type ChangeEvent, type KeyboardEvent, type Ref } from 'react';+import { useCallback, useMemo, type ChangeEvent, type KeyboardEvent } from 'react';import { useTranslation } from 'react-i18next';import { useMenuTriggerIds } from './galleryMenuIds';@@ -24,13 +24,10 @@ const SEARCH_START_ELEMENT = <Icon as={SearchIcon} size="md" />;const SORT_MENU_POSITIONING = { placement: 'bottom-end' } as const;export const GalleryBoardFilters = ({- ref,searchTerm,onSearchChange,onSubmitSearch,}: {- /** The panel focuses the field when "+" is pressed with nothing typed. */- ref?: Ref<HTMLInputElement>;searchTerm: string;onSearchChange: (searchTerm: string) => void;/** Enter on the field; the panel decides whether that means "create". */@@ -102,7 +99,6 @@ export const GalleryBoardFilters = ({<HStack gap="1"><InputGroup endElement={clearSearchButton} flex="1" minW="0" startElement={SEARCH_START_ELEMENT}><Input- ref={ref}aria-label={t('widgets.gallery.searchOrCreateBoards')}placeholder={t('widgets.gallery.searchOrCreateBoards')}value={searchTerm}diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.browser.test.tsxindex 8b31c720a8..402e3479de 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.browser.test.tsx@@ -24,6 +24,8 @@ vi.mock('react-i18next', () => ({'widgets.gallery.boardGroups.byDate': 'Dates','widgets.gallery.boardGroups.library': 'Library','widgets.gallery.boardGroups.otherProjects': 'Other projects',+ 'widgets.gallery.createBoard': 'Create board',+ 'widgets.gallery.createBoardIn': `Create board in ${String(values?.destination)}`,'widgets.gallery.createBoardNamedIn': `Create board "${String(values?.name)}" in ${String(values?.destination)}`,'widgets.gallery.inbox': 'Inbox','widgets.gallery.inboxOf': `${String(values?.project)} / Inbox`,@@ -38,7 +40,7 @@ vi.mock('react-i18next', () => ({}));const actions = {- createBoard: vi.fn(async () => {}),+ createBoard: vi.fn(() => Promise.resolve(true)),selectBoard: vi.fn(),updateSettings: vi.fn(),};@@ -177,6 +179,24 @@ const pressEnter = async (input: HTMLInputElement) => {});};+const getCreateDialog = async () => {+ let dialog: HTMLElement | null = null;++ await vi.waitFor(() => {+ dialog = document.querySelector<HTMLElement>('[role="dialog"][data-state="open"]');+ expect(dialog).not.toBeNull();+ });++ return dialog!;+};+const getDialogInput = (dialog: HTMLElement) => dialog.querySelector<HTMLInputElement>('input[name="renameValue"]')!;+const submit = async (dialog: HTMLElement) => {+ await act(async () => {+ dialog.querySelector('form')!.requestSubmit();+ await Promise.resolve();+ });+};+const click = async (element: HTMLElement) => {await act(async () => {element.click();@@ -285,38 +305,40 @@ describe('GalleryBoardsPanel', () => {expect(getSearchInput().value).toBe('');});- it('creates an unmatched name in the open project by default', async () => {+ it('offers an unmatched name in both tiers, each row creating where it sits', async () => {await renderPanel();await type(getSearchInput(), 'birds');const sections = getRowsBySection();expect(sections['Mahogany House']).toEqual(['Create board "birds" in Mahogany House']);- expect(sections.Library).toEqual([]);+ expect(sections.Library).toEqual(['Create board "birds" in Library']);- await click(getBoardRows().find((row) => row.textContent?.includes('Create board'))!);+ await click(getBoardRows().find((row) => row.textContent?.includes('in Library'))!);+ expect(actions.createBoard).toHaveBeenCalledWith('birds', null);+ expect(getSearchInput().value).toBe('');- expect(actions.createBoard).toHaveBeenCalledWith('birds', 'p1');+ await type(getSearchInput(), 'fish');+ await click(getBoardRows().find((row) => row.textContent?.includes('in Mahogany House'))!);+ expect(actions.createBoard).toHaveBeenLastCalledWith('fish', 'p1');});- it('creates in the Library after its "+" chose that tier, and keeps that choice', async () => {+ it('asks for a name in a dialog from a "+" and creates in that tier', async () => {await renderPanel();await click(getAddButton('widgets.gallery.createBoardInLibrary'));- expect(document.activeElement).toBe(getSearchInput());- await type(getSearchInput(), 'birds');- expect(getRowsBySection().Library).toEqual(['Create board "birds" in Library']);+ const dialog = await getCreateDialog();+ expect(dialog.querySelector('h2')?.textContent).toBe('Create board in Library');+ expect(document.activeElement).toBe(getDialogInput(dialog));+ expect(actions.createBoard).not.toHaveBeenCalled();- await pressEnter(getSearchInput());- expect(actions.createBoard).toHaveBeenCalledWith('birds', null);+ await type(getDialogInput(dialog), 'birds');+ await submit(dialog);- await type(getSearchInput(), 'fish');- await pressEnter(getSearchInput());- expect(actions.createBoard).toHaveBeenLastCalledWith('fish', null);+ expect(actions.createBoard).toHaveBeenCalledExactlyOnceWith('birds', null);+ await vi.waitFor(() => expect(document.querySelector('[role="dialog"]')).toBeNull());await click(getAddButton('widgets.gallery.createBoardInProject'));- await type(getSearchInput(), 'frogs');- await pressEnter(getSearchInput());- expect(actions.createBoard).toHaveBeenLastCalledWith('frogs', 'p1');+ expect((await getCreateDialog()).querySelector('h2')?.textContent).toBe('Create board in Mahogany House');});it('counts the boards made in each tier, not its fixed row', async () => {@@ -337,13 +359,54 @@ describe('GalleryBoardsPanel', () => {expect(row?.textContent).toContain('Inbox');});- it('creates at once from a "+" when an unmatched name is already typed', async () => {+ it('creates nothing from a dismissed dialog or a blank name, and leaves the search as it was', async () => {+ await renderPanel();+ await type(getSearchInput(), 'bir');+ await click(getAddButton('widgets.gallery.createBoardInProject'));++ const dialog = await getCreateDialog();+ await type(getDialogInput(dialog), ' ');+ await submit(dialog);+ expect(actions.createBoard).not.toHaveBeenCalled();+ await vi.waitFor(() => expect(document.querySelector('[role="dialog"]')).toBeNull());++ await click(getAddButton('widgets.gallery.createBoardInLibrary'));+ const reopened = await getCreateDialog();+ await click([...reopened.querySelectorAll('button')].find((button) => button.textContent === 'common.cancel')!);++ await vi.waitFor(() => expect(document.querySelector('[role="dialog"]')).toBeNull());+ expect(actions.createBoard).not.toHaveBeenCalled();+ expect(getSearchInput().value).toBe('bir');+ });++ it('keeps the dialog and its name when the create fails, so it can be tried again', async () => {+ actions.createBoard.mockResolvedValueOnce(false);+ await renderPanel();+ await type(getSearchInput(), 'birds');+ await click(getAddButton('widgets.gallery.createBoardInProject'));++ const dialog = await getCreateDialog();+ await submit(dialog);++ expect(actions.createBoard).toHaveBeenCalledExactlyOnceWith('birds', 'p1');+ expect(document.querySelector('[role="dialog"][data-state="open"]')).toBe(dialog);+ expect(getDialogInput(dialog).value).toBe('birds');+ expect(getSearchInput().value).toBe('birds');+ });++ it('starts the dialog from the typed search, so a name that found nothing is not retyped', async () => {await renderPanel();await type(getSearchInput(), 'birds');await click(getAddButton('widgets.gallery.createBoardInProject'));- expect(actions.createBoard).toHaveBeenCalledWith('birds', 'p1');+ const dialog = await getCreateDialog();+ expect(getDialogInput(dialog).value).toBe('birds');+ expect(actions.createBoard).not.toHaveBeenCalled();++ await submit(dialog);++ expect(actions.createBoard).toHaveBeenCalledExactlyOnceWith('birds', 'p1');expect(getSearchInput().value).toBe('');});diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsxindex 027b2be735..754b95f196 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryBoardsPanel.tsx@@ -7,6 +7,7 @@ import { getGalleryProjectGroupLabel } from '@features/gallery/core/boardLabels'import { toGalleryItemKey } from '@features/gallery/core/items';import { usePreservedScrollOffset } from '@platform/react/usePreservedScrollOffset';import { IconButton } from '@platform/ui/Button';+import { RenameDialog } from '@platform/ui/RenameDialog';import { Tooltip } from '@platform/ui/Tooltip';import { PlusIcon } from 'lucide-react';import { useCallback, useMemo, useRef, useState, type ReactNode } from 'react';@@ -27,16 +28,16 @@ import { useGalleryWidget } from './GalleryWidgetContext';const SCROLL_CONTENT_PROPS = { py: '1' } as const;const CREATE_ROW_COVER = <BoardCoverIcon icon={PlusIcon} />;-/** Which tier a board typed into the search field is created in; each tier's "+" chooses it. */+/** Where a new board goes: the open project or the Library. */type CreateTier = 'library' | 'project';export const GalleryBoardsPanel = () => {const { t } = useTranslation();const { actions, boardsState, gallery, projectId, projectName, projectNames } = useGalleryWidget();const [searchTerm, setSearchTerm] = useState('');- const [createTier, setCreateTier] = useState<CreateTier>('project');+ // The tier whose "+" asked for a name; the dialog it opens creates there.+ const [createDialogTier, setCreateDialogTier] = useState<CreateTier | null>(null);const [boardMenuTarget, setBoardMenuTarget] = useState<GalleryBoardMenuTarget | null>(null);- const searchInputRef = useRef<HTMLInputElement>(null);const boardsViewportRef = useRef<HTMLDivElement>(null);// The shell keeps the gallery mounted across layout switches, and a scroll@@ -75,41 +76,50 @@ export const GalleryBoardsPanel = () => {);const trimmedSearchTerm = searchTerm.trim();+ const tierLabel = useCallback(+ (tier: CreateTier) => (tier === 'project' ? projectName : t('widgets.gallery.boardGroups.library')),+ [projectName, t]+ );+ const createBoardIn = useCallback(+ (name: string, tier: CreateTier) => actions.createBoard(name, tier === 'project' ? projectId : null),+ [actions, projectId]+ );+ // The row goes away as soon as it is taken, so a slow create cannot be taken twice.const createBoardFromSearch = useCallback((tier: CreateTier) => {- if (!groups.canCreateFromSearch) {- return;+ if (groups.canCreateFromSearch) {+ setSearchTerm('');+ void createBoardIn(trimmedSearchTerm, tier);}-- setSearchTerm('');- void actions.createBoard(trimmedSearchTerm, tier === 'project' ? projectId : null);},- [actions, groups.canCreateFromSearch, projectId, trimmedSearchTerm]+ [createBoardIn, groups.canCreateFromSearch, trimmedSearchTerm]);- // Enter creates only with no matches, avoiding accidental near-duplicate boards.+ // Enter creates only with no matches, avoiding accidental near-duplicate boards; it takes the project's row,+ // the first of the two the typed name offers.const handleSubmitSearch = useCallback(() => {if (!groups.hasAnyMatch) {- createBoardFromSearch(createTier);+ createBoardFromSearch('project');}- }, [createBoardFromSearch, createTier, groups.hasAnyMatch]);+ }, [createBoardFromSearch, groups.hasAnyMatch]);- // A "+" with a typed, unmatched name creates at once; otherwise it picks the tier and asks for a name.- const handleAddBoard = useCallback(- (tier: CreateTier) => {- if (groups.canCreateFromSearch) {- createBoardFromSearch(tier);- return;+ // A "+" asks for the name in a dialog, started from whatever is typed so a search that found nothing is not lost.+ const handleAddProjectBoard = useCallback(() => setCreateDialogTier('project'), []);+ const handleAddLibraryBoard = useCallback(() => setCreateDialogTier('library'), []);+ const closeCreateDialog = useCallback(() => setCreateDialogTier(null), []);+ // The dialog keeps the typed name while its submit is pending, and keeps it on a failure the action has already+ // reported, which it learns of as a rejection; the search is cleared only once the board exists.+ const handleCreateDialogSubmit = useCallback(+ async (name: string) => {+ if (!(await createBoardIn(name, createDialogTier ?? 'project'))) {+ throw new Error('The board was not created.');}- setCreateTier(tier);- searchInputRef.current?.focus();+ setSearchTerm('');},- [createBoardFromSearch, groups.canCreateFromSearch]+ [createBoardIn, createDialogTier]);- const handleAddProjectBoard = useCallback(() => handleAddBoard('project'), [handleAddBoard]);- const handleAddLibraryBoard = useCallback(() => handleAddBoard('library'), [handleAddBoard]);const addProjectBoardAction = useMemo(() => <AddBoardButton label={t('widgets.gallery.createBoardInProject')} onClick={handleAddProjectBoard} />,[handleAddProjectBoard, t]@@ -166,14 +176,12 @@ export const GalleryBoardsPanel = () => {onSelectBoard={handleSelectBoard}/>);+ // A typed name no board has is offered in both tiers, so the choice is made where the board will show.const renderCreateRow = (tier: CreateTier) =>- groups.canCreateFromSearch && createTier === tier ? (+ groups.canCreateFromSearch ? (<GalleryBoardRowShellcover={CREATE_ROW_COVER}- label={t('widgets.gallery.createBoardNamedIn', {- destination: tier === 'project' ? projectName : t('widgets.gallery.boardGroups.library'),- name: trimmedSearchTerm,- })}+ label={t('widgets.gallery.createBoardNamedIn', { destination: tierLabel(tier), name: trimmedSearchTerm })}labelWeight="600"onSelect={tier === 'project' ? createProjectBoardFromSearch : createLibraryBoardFromSearch}/>@@ -196,12 +204,7 @@ export const GalleryBoardsPanel = () => {return (<Stack flex="1" gap="1" minH="0" minW="0">- <GalleryBoardFilters- ref={searchInputRef}- searchTerm={searchTerm}- onSearchChange={setSearchTerm}- onSubmitSearch={handleSubmitSearch}- />+ <GalleryBoardFilters searchTerm={searchTerm} onSearchChange={setSearchTerm} onSubmitSearch={handleSubmitSearch} /><ScrollArea.Root flex="1" minH="0" variant="hover" w="full"><ScrollArea.Viewport ref={boardsViewportRef} h="full" w="full"><ScrollArea.Content {...SCROLL_CONTENT_PROPS}>@@ -327,13 +330,24 @@ export const GalleryBoardsPanel = () => {</ScrollArea.Scrollbar></ScrollArea.Root><GalleryBoardMenu target={boardMenuTarget} onClose={handleBoardMenuClose} />+ <RenameDialog+ cancelLabel={t('common.cancel')}+ initialName={trimmedSearchTerm}+ isOpen={createDialogTier !== null}+ label={t('widgets.gallery.boardName')}+ submitLabel={t('widgets.gallery.createBoard')}+ submitUnchanged+ title={t('widgets.gallery.createBoardIn', { destination: tierLabel(createDialogTier ?? 'project') })}+ onClose={closeCreateDialog}+ onSubmit={handleCreateDialogSubmit}+ /></Stack>);};const AddBoardButton = ({ label, onClick }: { label: string; onClick: () => void }): ReactNode => (<Tooltip content={label}>- <IconButton aria-label={label} color="fg.muted" size="sm" variant="ghost" onClick={onClick}>+ <IconButton aria-haspopup="dialog" aria-label={label} color="fg.muted" size="sm" variant="ghost" onClick={onClick}><Icon as={PlusIcon} boxSize="3.5" /></IconButton></Tooltip>diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsxindex d075b2d14c..c74809c971 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/GalleryWidgetContext.tsx@@ -17,7 +17,8 @@ import type { GalleryListingState } from './useGalleryData';export interface GalleryActions {archiveBoard: (boardId: string, archived: boolean) => Promise<void>;/** In the given project, or in the Library for null. */- createBoard: (boardName: string, projectId: string | null) => Promise<void>;+ /** Resolves `true` once the board exists and is selected; a reported failure resolves `false`. */+ createBoard: (boardName: string, projectId: string | null) => Promise<boolean>;deleteBoard: (boardId: string, includeImages: boolean) => Promise<void>;downloadBoard: (boardId: string) => Promise<void>;/** Export the project that owns this board as a complete `.invk` archive. */diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsxindex b2ed97f6e6..976a6ff69e 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.browser.test.tsx@@ -316,7 +316,7 @@ describe('optimistic board updates', () => {expect(mocks.ensureProjectOnServer).not.toHaveBeenCalled();await act(async () => {- await actionsRef.current?.createBoard('New', 'p1');+ await expect(actionsRef.current?.createBoard('New', 'p1')).resolves.toBe(true);});expect(mocks.ensureProjectOnServer).toHaveBeenCalledOnce();expect(mocks.ensureProjectOnServer.mock.invocationCallOrder[0]).toBeLessThan(diff --git a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.ts b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.tsindex 078fd40cb5..6c2da6bc0b 100644--- a/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.ts+++ b/invokeai/frontend/webv2/src/features/gallery/ui/useGalleryActions.ts@@ -105,12 +105,14 @@ export const useGalleryActions = ({gallery.selectBoard(board.id);recordSuccess(t('widgets.gallery.boardCreated', { name: board.name }));refresh();++ return true;} catch (error: unknown) {- if (!isAccountScopeCurrent(owner)) {- return;+ if (isAccountScopeCurrent(owner)) {+ recordError(error);}- recordError(error);+ return false;}},deleteBoard: async (boardId, includeImages) => {diff --git a/invokeai/frontend/webv2/src/platform/ui/RenameDialog.tsx b/invokeai/frontend/webv2/src/platform/ui/RenameDialog.tsxindex ae63bba948..0b2447a3cd 100644--- a/invokeai/frontend/webv2/src/platform/ui/RenameDialog.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/RenameDialog.tsx@@ -8,6 +8,7 @@ import { Field } from './Field';/** Submit only changed, nonempty names; async failures keep the dialog open and callers surface the error. */export const RenameDialog = ({+ cancelLabel = 'Cancel',finalFocusEl,initialName,isOpen,@@ -19,6 +20,7 @@ export const RenameDialog = ({submitUnchanged = false,title = 'Rename project',}: {+ cancelLabel?: string;finalFocusEl?: () => HTMLElement | null;initialName: string;isOpen: boolean;@@ -33,7 +35,7 @@ export const RenameDialog = ({}) => {const [isPending, setIsPending] = useState(false);// Keep the labels the dialog showed while it animates out, even if the host clears its subject on close.- const live = useMemo(() => ({ label, submitLabel, title }), [label, submitLabel, title]);+ const live = useMemo(() => ({ cancelLabel, label, submitLabel, title }), [cancelLabel, label, submitLabel, title]);const shown = useExitRetainedValue(isOpen ? live : null);const text = shown.value ?? live;const { release } = shown;@@ -110,7 +112,7 @@ export const RenameDialog = ({</Dialog.Body><Dialog.Footer><Button disabled={isPending} type="button" variant="ghost" onClick={onClose}>- Cancel+ {text.cancelLabel}</Button><Button loading={isPending} type="submit" variant="solid">{text.submitLabel}