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(webv2): list the current project first among open projects

Josh Corbett8b00a224d870
diff --git a/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.browser.test.tsx
new file mode 100644
index 0000000000..35b26459d7
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.browser.test.tsx
@@ -0,0 +1,76 @@
+/* oxlint-disable react-perf/jsx-no-new-object-as-prop */
+import type * as openProjects from '@workbench/projects/openProjects';
+
+import { ChakraProvider } from '@chakra-ui/react';
+import { system } from '@theme/system';
+import { act } from 'react';
+import { createRoot, type Root } from 'react-dom/client';
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+const snapshot = vi.hoisted(() => ({
+ current: { activeId: 'three', ids: ['one', 'two', 'three'], status: 'ready' } as openProjects.OpenProjectsSnapshot,
+}));
+
+vi.mock('@workbench/projects/openProjects', () => ({
+ refreshOpenProjects: () => Promise.resolve(),
+ useOpenProjectsSelector: <T,>(select: (value: openProjects.OpenProjectsSnapshot) => T) => select(snapshot.current),
+}));
+
+vi.mock('@workbench/projects/library', () => ({
+ useProjectLibrarySelector: <T,>(select: (value: { summaries: { id: string; name: string }[] }) => T) =>
+ select({
+ summaries: [
+ { id: 'one', name: 'First' },
+ { id: 'two', name: 'Second' },
+ { id: 'three', name: 'Third' },
+ ],
+ }),
+}));
+
+vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: (key: string) => key }) }));
+
+vi.mock('@tanstack/react-router', () => ({
+ Link: ({ children, search, to, ...props }: { children?: unknown; search?: { project?: string }; to: string }) => (
+ <a data-project={search?.project} href={to} {...props}>
+ {children as never}
+ </a>
+ ),
+}));
+
+const { OpenProjectsNavSection } = await import('./OpenProjectsControl');
+
+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+
+let host: HTMLDivElement;
+let root: Root;
+
+const renderedOrder = async () => {
+ host = document.createElement('div');
+ document.body.append(host);
+ root = createRoot(host);
+ await act(() =>
+ root.render(
+ <ChakraProvider value={system}>
+ <OpenProjectsNavSection headingCss={{}} itemProps={{ justifyContent: 'start', size: 'sm', w: 'full' }} />
+ </ChakraProvider>
+ )
+ );
+ return [...host.querySelectorAll('a[data-project]')].map((link) => link.getAttribute('data-project'));
+};
+
+afterEach(async () => {
+ await act(() => root.unmount());
+ host.remove();
+});
+
+describe('Launchpad open projects', () => {
+ it('lists the current project first and keeps the others in their open order', async () => {
+ snapshot.current = { activeId: 'three', ids: ['one', 'two', 'three'], status: 'ready' };
+ expect(await renderedOrder()).toEqual(['three', 'one', 'two']);
+ });
+
+ it('keeps the open order when no open project is current', async () => {
+ snapshot.current = { activeId: 'gone', ids: ['one', 'two', 'three'], status: 'ready' };
+ expect(await renderedOrder()).toEqual(['one', 'two', 'three']);
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.tsx b/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.tsx
index 68e7356d2e..815f7297e3 100644
--- a/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.tsx
+++ b/invokeai/frontend/webv2/src/workbench/launchpad/OpenProjectsControl.tsx
@@ -55,9 +55,14 @@ export const OpenProjectsNavSection = ({
}
const nameById = new Map(summaries.map((summary) => [summary.id, summary.name]));
+ // The current project leads; the rest keep their open order.
+ const ordered =
+ activeProjectId && openProjectIds.includes(activeProjectId)
+ ? [activeProjectId, ...openProjectIds.filter((id) => id !== activeProjectId)]
+ : openProjectIds;
- return openProjectIds.map((id) => ({ id, name: nameById.get(id) ?? null }));
- }, [openProjectIds, summaries]);
+ return ordered.map((id) => ({ id, name: nameById.get(id) ?? null }));
+ }, [activeProjectId, openProjectIds, summaries]);
if (status !== 'ready' || (openProjectIds !== null && openProjects.length === 0)) {
return null;