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
refactor(webv2): make the workflow panel mode a real tablist
joshistoaste9a8d4763fde
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.jsonindex f4b92f1f47..c990f0b5d8 100644--- a/invokeai/frontend/webv2/public/locales/en.json+++ b/invokeai/frontend/webv2/public/locales/en.json@@ -1748,6 +1748,7 @@"openLibrary": "Open workflow library. Current workflow: {{name}}","pack": "Pack","panelContent": "Workflow panel content",+ "panelMode": "Workflow panel mode","resizeNodeInspector": "Resize node inspector","runOutputsNotRecorded": "Run outputs are not recorded per node yet; results currently route to the Gallery or Canvas. This tab will show the node's outputs from its most recent run once run records land.","newWorkflowWithEllipsis": "New workflow…",diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsxindex 43cb7838a2..9cdfd0e3a2 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.browser.test.tsx@@ -24,7 +24,7 @@ describe('Workflow Linear panel mode toggle', () => {host.remove();});- it('activates View and Edit with pointer and keyboard button semantics', async () => {+ const renderToggle = async () => {const Harness = () => {const [mode, setMode] = useState<'view' | 'edit'>('view');return <PanelModeToggle mode={mode} onChange={setMode} />;@@ -38,20 +38,31 @@ describe('Workflow Linear panel mode toggle', () => {);});- const buttons = host.querySelectorAll<HTMLButtonElement>('button[aria-pressed]');- expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['true', 'false']);+ return [...host.querySelectorAll<HTMLButtonElement>('[role="tab"]')];+ };- await act(() => userEvent.click(buttons[1]!));- expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['false', 'true']);+ const selection = (tabs: HTMLButtonElement[]) => tabs.map((tab) => tab.getAttribute('aria-selected'));- buttons[0]?.focus();- await act(() => userEvent.keyboard('{Enter}'));- expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['true', 'false']);+ it('exposes View and Edit as a labelled tablist', async () => {+ const tabs = await renderToggle();- await act(() => userEvent.tab());- expect(document.activeElement).toBe(buttons[1]);+ expect(tabs).toHaveLength(2);+ expect(host.querySelector('[role="tablist"]')?.getAttribute('aria-label')).toBeTruthy();+ expect(selection(tabs)).toEqual(['true', 'false']);+ });++ it('activates View and Edit with pointer and arrow keys', async () => {+ const tabs = await renderToggle();++ await act(() => userEvent.click(tabs[1]!));+ expect(selection(tabs)).toEqual(['false', 'true']);++ // Roving focus: the tablist is one tab stop and arrows move within it.+ tabs[1]?.focus();+ await act(() => userEvent.keyboard('{ArrowLeft}'));+ expect(selection(tabs)).toEqual(['true', 'false']);- await act(() => userEvent.keyboard(' '));- expect([...buttons].map((button) => button.getAttribute('aria-pressed'))).toEqual(['false', 'true']);+ await act(() => userEvent.keyboard('{ArrowRight}'));+ expect(selection(tabs)).toEqual(['false', 'true']);});});diff --git a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsx b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsxindex 8a6039dda4..0c5107a97c 100644--- a/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsx+++ b/invokeai/frontend/webv2/src/features/workflow/ui/linear/WorkflowLinearPanel.tsx@@ -2,7 +2,7 @@ import { Flex, HStack, Icon, Splitter } from '@chakra-ui/react';import { ensureInvocationTemplatesLoaded } from '@features/workflow/react';import { useWorkflowHostCommands, useWorkflowProjectSelector } from '@features/workflow/ui/WorkflowUiContext';import { useMountEffect } from '@platform/react/useMountEffect';-import { Button, Scrollable, Tabs } from '@platform/ui';+import { Scrollable, Tabs } from '@platform/ui';import { EyeIcon, PencilIcon } from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -64,66 +64,33 @@ export const getWorkflowPanelState = (values: Record<string, unknown>): Workflowexport const areWorkflowPanelStatesEqual = (left: WorkflowPanelState, right: WorkflowPanelState): boolean =>left.mode === right.mode && left.editTab === right.editTab && left.inspectorSizePct === right.inspectorSizePct;-export const PanelModeToggle = ({- mode: currentMode,- onChange,-}: {- mode: PanelMode;- onChange: (mode: PanelMode) => void;-}) => {+/**+ * View / Edit selection. These swap the whole panel body, so they are tabs+ * rather than a pressed-button pair: the tablist carries roving focus and+ * arrow-key selection for free, which the hand-rolled `aria-pressed` group it+ * replaced could not. Like the edit-tab strip below, it renders the list only —+ * the panels are siblings, since edit mode drives its own splitter layout.+ */+export const PanelModeToggle = ({ mode, onChange }: { mode: PanelMode; onChange: (mode: PanelMode) => void }) => {const { t } = useTranslation();-- return (- <HStack- aria-label="Workflow panel mode"- borderColor="border"- borderRadius="md"- borderWidth="1px"- gap="0"- overflow="hidden"- role="group"- >- {PANEL_MODES.map(({ labelKey, icon, mode: itemMode }) => (- <PanelModeButton- key={itemMode}- currentMode={currentMode}- icon={icon}- label={t(labelKey)}- mode={itemMode}- onChange={onChange}- />- ))}- </HStack>+ const onValueChange = useCallback(+ (event: { value: string }) => onChange(event.value === 'edit' ? 'edit' : 'view'),+ [onChange]);-};--const PanelModeButton = ({- currentMode,- icon,- label,- mode,- onChange,-}: {- currentMode: PanelMode;- icon: typeof EyeIcon;- label: string;- mode: PanelMode;- onChange: (mode: PanelMode) => void;-}) => {- const onClick = useCallback(() => onChange(mode), [mode, onChange]);return (- <Button- aria-pressed={mode === currentMode}- borderRadius="0"- colorPalette={mode === currentMode ? 'accent' : 'bg'}- size="xs"- variant={mode === currentMode ? 'solid' : 'ghost'}- onClick={onClick}- >- <Icon as={icon} boxSize="3" />- {label}- </Button>+ // `mb="-1"` tucks the active-tab indicator onto the header's own bottom+ // rule, the same trick the edit tabs use.+ <Tabs.Root mb="-1" size="sm" value={mode} variant="line" onValueChange={onValueChange}>+ <Tabs.List aria-label={t('widgets.workflow.panelMode')}>+ {PANEL_MODES.map(({ labelKey, icon, mode: itemMode }) => (+ <Tabs.Trigger key={itemMode} value={itemMode}>+ <Icon as={icon} boxSize="3" />+ {t(labelKey)}+ </Tabs.Trigger>+ ))}+ </Tabs.List>+ </Tabs.Root>);};