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(webv2): align prompt trigger empty state
joshistoastcd943bfaee1b
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.browser.test.tsxnew file mode 100644index 0000000000..7b4d1c3a5c--- /dev/null+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.browser.test.tsx@@ -0,0 +1,97 @@+/* oxlint-disable react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop */+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 ensureModelsLoaded = vi.fn();+const openModelManager = vi.fn();++vi.mock('@features/generation/ui/GenerationUiContext', async (importOriginal) => ({+ ...(await importOriginal<object>()),+ useGenerationUi: () => ({+ models: { catalog: [], ensureLoaded: ensureModelsLoaded, openManager: openModelManager },+ }),+}));++vi.mock('@features/generation/ui/useWildcards', async (importOriginal) => ({+ ...(await importOriginal<object>()),+ useWildcards: () => ({ wildcards: [] }),+}));++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string) =>+ ({+ 'widgets.generate.noPromptTriggersAvailable': 'No prompt triggers available',+ 'widgets.generate.openModelManager': 'Open model manager',+ 'widgets.generate.promptTriggerOptions': 'Prompt trigger options',+ 'widgets.generate.searchPromptTriggers': 'Search prompt triggers',+ })[key] ?? key,+ }),+}));++import { PromptTriggerPopover } from './PositivePromptActions';++const POSITIONING = {+ getAnchorRect: () => ({ height: 32, width: 32, x: 100, y: 100 }),+};++let host: HTMLDivElement | null = null;+let root: Root | null = null;+(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;++afterEach(async () => {+ await act(() => root?.unmount());+ host?.remove();+ host = null;+ root = null;+});++describe('PromptTriggerPopover', () => {+ it('keeps empty-state copy and its action together', async () => {+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);++ await act(async () => {+ root?.render(+ <ChakraProvider value={system}>+ <PromptTriggerPopover+ loras={[]}+ open+ positioning={POSITIONING}+ selectedModel={undefined}+ onClose={vi.fn()}+ onSelect={vi.fn()}+ />+ </ChakraProvider>+ );+ await new Promise<void>((resolve) => {+ globalThis.setTimeout(resolve, 50);+ });+ });++ const region = document.querySelector<HTMLElement>('[aria-label="Prompt trigger options"]');+ const message = [...document.querySelectorAll<HTMLElement>('p')].find(+ (element) => element.textContent === 'No prompt triggers available'+ );+ const action = [...document.querySelectorAll<HTMLButtonElement>('button')].find(+ (element) => element.textContent === 'Open model manager'+ );++ if (!region || !message || !action) {+ throw new Error('prompt-trigger empty state did not render');+ }++ const regionBounds = region.getBoundingClientRect();+ const messageBounds = message.getBoundingClientRect();+ const actionBounds = action.getBoundingClientRect();+ const contentCenter = (messageBounds.top + actionBounds.bottom) / 2;++ expect(Math.abs(messageBounds.left - actionBounds.left)).toBeLessThanOrEqual(1);+ expect(actionBounds.top - messageBounds.bottom).toBeLessThanOrEqual(8);+ expect(contentCenter).toBeCloseTo(regionBounds.top + regionBounds.height / 2, -1);+ });+});diff --git a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsxindex 8480ca1c50..cc4b87d469 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/promptFields/PositivePromptActions.tsx@@ -42,6 +42,7 @@ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'import { useTranslation } from 'react-i18next';const POPOVER_POSITIONING_BOTTOM_END = { placement: 'bottom-end' } as const;+const PROMPT_TRIGGER_EMPTY_SCROLL_CONTENT_PROPS = { h: 'full' } as const;const TEXT_LLM_MODEL_TYPES = ['text_llm'];const LLAVA_MODEL_TYPES = ['llava_onevision'];/**@@ -297,12 +298,14 @@ export const PromptTriggerPopover = ({onChange={handleSearchChange}/><Separator />- <Scrollable flex="1" label={t('widgets.generate.promptTriggerOptions')} minH="0">+ <Scrollable+ contentProps={options.length === 0 ? PROMPT_TRIGGER_EMPTY_SCROLL_CONTENT_PROPS : undefined}+ flex="1"+ label={t('widgets.generate.promptTriggerOptions')}+ minH="0"+ >{options.length === 0 ? (- <Stack align="start" gap="1" px="2">- <PromptHistoryEmptyText>{t('widgets.generate.noPromptTriggersAvailable')}</PromptHistoryEmptyText>- <OpenModelManagerButton />- </Stack>+ <PromptTriggerEmptyState />) : filteredOptions.length === 0 ? (<PromptHistoryEmptyText>{t('widgets.generate.noMatchingTriggers')}</PromptHistoryEmptyText>) : (@@ -333,6 +336,19 @@ export const PromptTriggerPopover = ({);};+const PromptTriggerEmptyState = () => {+ const { t } = useTranslation();++ return (+ <Stack align="start" gap="1" h="full" justify="center" px="2">+ <Text color="fg.subtle" fontSize="xs">+ {t('widgets.generate.noPromptTriggersAvailable')}+ </Text>+ <OpenModelManagerButton />+ </Stack>+ );+};+const PromptTriggerOptionButton = ({onSelect,option,