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(ui): add an install context menu to Add Models rows
Josh Corbett34532e8972b0
diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/HuggingFaceFiles.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/HuggingFaceFiles.tsxindex 5fbb37ea53..e236698a19 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/HuggingFaceFiles.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/HuggingFaceFiles.tsx@@ -2,13 +2,16 @@import type { HFLookupState } from '@features/models/ui/uiStore';import { Stack } from '@chakra-ui/react';-import { InstallSourceButton } from '@features/models/ui/shared/InstallSourceButton';+import {+ InstallSourceContextMenu,+ type InstallSourceStatus,+ useInstallSourceMenu,+} from '@features/models/ui/shared/InstallSourceMenu';+import { InstallPathRow } from '@features/models/ui/shared/InstallSourceRow';import { ResultsListHeader } from '@features/models/ui/shared/ResultsListHeader';import { useInstalledSourceKeys } from '@features/models/ui/shared/useInstalledSources';-import { sourceFileName, sourceLocation, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';-import { ListItem } from '@platform/ui/list/ListItem';+import { sourceLocation, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';import { ListStack } from '@platform/ui/list/ListStack';-import { MiddleTruncate } from '@platform/ui/MiddleTruncate';import { useTranslation } from 'react-i18next';import { InstallOptions } from './InstallOptions';@@ -36,6 +39,13 @@ export const HuggingFaceFiles = ({const { t } = useTranslation();const { filter, filteredItems: filteredUrls, setFilter } = useSourceNameFilter(lookup.urls, urlOf);const installedSourceKeys = useInstalledSourceKeys();+ const statusOf = (url: string): InstallSourceStatus => ({+ installedModelKey: installedSourceKeys.get(url) ?? null,+ isInstalled: false,+ isPending: pendingSources.has(url),+ });+ const menu = useInstallSourceMenu();+ const menuUrl = menu.shown && filteredUrls.includes(menu.shown.source) ? menu.shown.source : null;const installAll = () => {onInstallAll([...filteredUrls]);@@ -55,27 +65,30 @@ export const HuggingFaceFiles = ({onSearchChange={setFilter}/><ListStack dividers label={lookup.repo}>- {filteredUrls.map((url) => {- const location = sourceLocation(url);-- return (- <ListItem- key={url}- actions={- <InstallSourceButton- installedModelKey={installedSourceKeys.get(url) ?? null}- isPending={pendingSources.has(url)}- name={location ?? sourceFileName(url)}- source={url}- onInstall={() => onInstall(url)}- />- }- description={location ? <MiddleTruncate as="span" text={location} title={url} /> : undefined}- title={sourceFileName(url)}- />- );- })}+ {filteredUrls.map((url) => (+ <InstallPathRow+ key={url}+ {...statusOf(url)}+ isMenuOpen={menuUrl === url}+ location={sourceLocation(url)}+ source={url}+ onInstall={onInstall}+ onOpenMenu={menu.open}+ />+ ))}</ListStack>+ <InstallSourceContextMenu+ status={menuUrl === null ? null : statusOf(menuUrl)}+ isOpen={menu.target !== null}+ target={menu.shown}+ onClose={menu.close}+ onExitComplete={menu.release}+ onInstall={() => {+ if (menuUrl !== null) {+ onInstall(menuUrl);+ }+ }}+ /></Stack>);};diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.browser.test.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.browser.test.tsxindex 8ceb3af5bd..f7f6edeaed 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.browser.test.tsx@@ -5,10 +5,12 @@ import { addInstallJob, replaceInstallJob } from '@features/models/data/installsimport { setModelsSnapshotForTests } from '@features/models/data/modelsStore';import { getModelsUiSnapshotForTests, updateModelsUi } from '@features/models/ui/uiStore';import { accountLifecycle } from '@platform/state/accountLifecycle';+import { closingFrames, recordDialogExit } from '@platform/ui/dialogExit.testing';import { system } from '@theme/system';import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { userEvent } from 'vitest/browser';import { ScanResults } from './ScanResults';@@ -110,3 +112,108 @@ describe('ScanResults install badge lifecycle', () => {expect(getModelsUiSnapshotForTests()).toMatchObject({ activeModelKey: 'installed-key', activeTab: 'details' });});});++describe('ScanResults row context menu', () => {+ let host: HTMLDivElement;+ let root: Root;+ const onInstall = vi.fn<(path: string) => void>();++ const menuItem = (value: string) => document.querySelector<HTMLElement>(`[role="menuitem"][data-value="${value}"]`);+ const openRowMenu = async (value: string) => {+ await act(() => userEvent.click(host.querySelector<HTMLElement>('[data-list-primary]')!, { button: 'right' }));+ await expect.poll(() => menuItem(value)).not.toBeNull();+ };++ beforeEach(async () => {+ accountLifecycle.activate('scan-results-test-b', ':user:scan-results-test-b');+ setModelsSnapshotForTests({ models: [], status: 'loaded' });+ updateModelsUi({ activeModelKey: null, activeTab: 'add', queueExpanded: false });+ onInstall.mockClear();+ host = document.createElement('div');+ document.body.append(host);+ root = createRoot(host);++ await act(() => {+ root.render(+ <ChakraProvider value={system}>+ <ScanResults+ fp8Storage={false}+ inplace+ pendingSources={NO_PENDING}+ scan={SCAN}+ onClear={noop}+ onInstall={onInstall}+ onInstallAll={noop}+ onSetFp8Storage={noop}+ onSetInplace={noop}+ />+ </ChakraProvider>+ );+ });+ });++ afterEach(async () => {+ await act(() => root.unmount());+ host.remove();+ accountLifecycle.invalidate();+ });++ it('keeps the row out of the tab order beside its Install button', async () => {+ const installButton = [...host.querySelectorAll('button')].find(+ (button) => button.textContent === 'models.install'+ )!;+ installButton.focus();++ await userEvent.tab({ shift: true });++ expect(document.activeElement).not.toBe(host.querySelector('[data-list-primary]'));+ });++ it('animates the menu out on close, still offering the row it opened for', async () => {+ await openRowMenu('install');+ const menu = document.querySelector('[role="menu"]')!;++ const frames = closingFrames(await recordDialogExit(menu, () => act(() => userEvent.keyboard('{Escape}'))));++ expect(frames).not.toHaveLength(0);+ for (const frame of frames) {+ expect(frame.text).toContain('models.install');+ }+ });++ it('installs the row from its context menu', async () => {+ await openRowMenu('install');++ await act(() => userEvent.click(menuItem('install')!));++ expect(onInstall).toHaveBeenCalledExactlyOnceWith(SCANNED_PATH);+ });++ it('follows an install that starts while the menu is open to the queue', async () => {+ await openRowMenu('install');++ await act(async () => {+ addInstallJob(queuedJob);+ await Promise.resolve();+ });++ await expect.poll(() => menuItem('view-queue')).not.toBeNull();+ expect(menuItem('install')).toBeNull();+ await act(() => userEvent.click(menuItem('view-queue')!));++ expect(getModelsUiSnapshotForTests().queueExpanded).toBe(true);+ expect(onInstall).not.toHaveBeenCalled();+ });++ it('opens the model an installed row became', async () => {+ await act(async () => {+ setModelsSnapshotForTests({ models: [installedModel], status: 'loaded' });+ await Promise.resolve();+ });+ await openRowMenu('view-model');++ await act(() => userEvent.click(menuItem('view-model')!));++ expect(getModelsUiSnapshotForTests()).toMatchObject({ activeModelKey: 'installed-key', activeTab: 'details' });+ });+});diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.tsxindex 9d04eaabf5..a6b38b4022 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/ScanResults.tsx@@ -2,14 +2,17 @@import type { FoundModel } from '@features/models/core/types';import { HStack, Icon, Stack, Text } from '@chakra-ui/react';-import { InstallSourceButton } from '@features/models/ui/shared/InstallSourceButton';+import {+ InstallSourceContextMenu,+ type InstallSourceStatus,+ useInstallSourceMenu,+} from '@features/models/ui/shared/InstallSourceMenu';+import { InstallPathRow } from '@features/models/ui/shared/InstallSourceRow';import { ResultsListHeader } from '@features/models/ui/shared/ResultsListHeader';import { useInstalledSourceKeys } from '@features/models/ui/shared/useInstalledSources';-import { sourceFileName, sourceLocation, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';+import { sourceLocation, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';import { IconButton } from '@platform/ui';-import { ListItem } from '@platform/ui/list/ListItem';import { ListStack } from '@platform/ui/list/ListStack';-import { MiddleTruncate } from '@platform/ui/MiddleTruncate';import { XIcon } from 'lucide-react';import { useTranslation } from 'react-i18next';@@ -45,6 +48,13 @@ export const ScanResults = ({// installed from this list would otherwise keep offering Install forever.const installedSourceKeys = useInstalledSourceKeys();const isRowInstalled = (result: FoundModel) => result.is_installed || installedSourceKeys.has(result.path);+ const statusOf = (result: FoundModel): InstallSourceStatus => ({+ installedModelKey: installedSourceKeys.get(result.path) ?? null,+ isInstalled: isRowInstalled(result),+ isPending: pendingSources.has(result.path),+ });+ const menu = useInstallSourceMenu();+ const menuResult = menu.shown ? filteredResults.find((result) => result.path === menu.shown?.source) : undefined;const notInstalledCount = scan.results.filter((result) => !isRowInstalled(result)).length;const installable = filteredResults.filter((result) => !isRowInstalled(result));@@ -90,28 +100,30 @@ export const ScanResults = ({onSearchChange={setFilter}/><ListStack dividers label={scan.path}>- {filteredResults.map((result) => {- const location = sourceLocation(result.path, scan.path);-- return (- <ListItem- key={result.path}- actions={- <InstallSourceButton- installedModelKey={installedSourceKeys.get(result.path) ?? null}- isInstalled={isRowInstalled(result)}- isPending={pendingSources.has(result.path)}- name={location ?? sourceFileName(result.path)}- source={result.path}- onInstall={() => onInstall(result.path)}- />- }- description={location ? <MiddleTruncate as="span" text={location} title={result.path} /> : undefined}- title={sourceFileName(result.path)}- />- );- })}+ {filteredResults.map((result) => (+ <InstallPathRow+ key={result.path}+ {...statusOf(result)}+ isMenuOpen={menuResult?.path === result.path}+ location={sourceLocation(result.path, scan.path)}+ source={result.path}+ onInstall={onInstall}+ onOpenMenu={menu.open}+ />+ ))}</ListStack>+ <InstallSourceContextMenu+ status={menuResult ? statusOf(menuResult) : null}+ isOpen={menu.target !== null}+ target={menu.shown}+ onClose={menu.close}+ onExitComplete={menu.release}+ onInstall={() => {+ if (menuResult) {+ onInstall(menuResult.path);+ }+ }}+ /></Stack>);};diff --git a/invokeai/frontend/webv2/src/features/models/ui/add-models/StarterList.tsx b/invokeai/frontend/webv2/src/features/models/ui/add-models/StarterList.tsxindex a02262ee3a..6101fc899e 100644--- a/invokeai/frontend/webv2/src/features/models/ui/add-models/StarterList.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/add-models/StarterList.tsx@@ -1,17 +1,24 @@import type { ModelConfig, StarterModel } from '@features/models/core/types';/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */import type { StartersSnapshot } from '@features/models/data/startersStore';+import type { ListContextMenuAnchor } from '@platform/ui/list/ListItem';import { Badge, Flex, Icon, Spinner, Stack, Text } from '@chakra-ui/react';import { getModelBaseColorPalette, getModelBaseLabel } from '@features/models/core/baseIdentity';import { getModelTypeLabel } from '@features/models/core/taxonomy';import { useModelsSelector } from '@features/models/data/modelsStore';-import { InstallSourceButton } from '@features/models/ui/shared/InstallSourceButton';+import {+ InstallSourceContextMenu,+ type InstallSourceStatus,+ useInstallSourceMenu,+} from '@features/models/ui/shared/InstallSourceMenu';+import { InstallSourceRow } from '@features/models/ui/shared/InstallSourceRow';import { findInstalledStarterModelKey, useInstalledSourceKeys } from '@features/models/ui/shared/useInstalledSources';import { Button } from '@platform/ui';import { ListItem } from '@platform/ui/list/ListItem';import { ListStack } from '@platform/ui/list/ListStack';import { KeyRoundIcon } from 'lucide-react';+import { memo } from 'react';import { useTranslation } from 'react-i18next';const getExternalProviderId = (source: string): string | null => {@@ -50,6 +57,14 @@ export const StarterList = ({const { t } = useTranslation();const installedSourceKeys = useInstalledSourceKeys();const installedModels = useModelsSelector(selectModels);+ const statusOf = (model: StarterModel): InstallSourceStatus => ({+ installedModelKey: findInstalledStarterModelKey(model, installedSourceKeys, installedModels),+ isInstalled: model.is_installed,+ isPending: pendingSources.has(model.source),+ });+ const menu = useInstallSourceMenu();+ // External-provider rows have no menu, so only an installable source can be the target.+ const menuModel = menu.shown ? models.find((model) => model.source === menu.shown?.source) : undefined;if (status === 'error' && loadError) {return (@@ -81,60 +96,110 @@ export const StarterList = ({}return (- <ListStack dividers label={t('models.starterModelsList')}>- {models.map((model) => {- const externalProviderId = getExternalProviderId(model.source);- const dependencyCount = (model.dependencies ?? []).filter(- (dependency) => !dependency.is_installed && !selectedBundleSources?.has(dependency.source)- ).length;- const trailing = externalProviderId ? (- configuredExternalProviders.has(externalProviderId) ? (- <Badge colorPalette="green" fontSize="xs" size="lg" variant="surface">- {t('models.installed')}- </Badge>- ) : (- <Button size="sm" variant="outline" onClick={() => onConfigureExternalProvider(externalProviderId)}>- <Icon as={KeyRoundIcon} boxSize="3" />- {t('common.configure')}- </Button>- )- ) : (- <InstallSourceButton- installedModelKey={findInstalledStarterModelKey(model, installedSourceKeys, installedModels)}- isInstalled={model.is_installed}- isPending={pendingSources.has(model.source)}- name={model.name}- source={model.source}- onInstall={() => onInstall(model)}- />- );+ <>+ <ListStack dividers label={t('models.starterModelsList')}>+ {models.map((model) => {+ const externalProviderId = getExternalProviderId(model.source);+ const dependencyCount = (model.dependencies ?? []).filter(+ (dependency) => !dependency.is_installed && !selectedBundleSources?.has(dependency.source)+ ).length;+ const description = `${model.description}${+ dependencyCount > 0 ? t('models.installsDependencies', { count: dependencyCount }) : ''+ }`;- return (- <ListItem- key={`${model.source}-${model.name}`}- actions={trailing}- badges={- <>- <Badge colorPalette={getModelBaseColorPalette(model.base)} fontSize="xs" size="lg" variant="surface">- {getModelBaseLabel(model.base)}- </Badge>- <Badge colorPalette="gray" fontSize="xs" size="lg" variant="surface">- {getModelTypeLabel(model.type)}- </Badge>- </>- }- // Starter descriptions carry the dependency note; allow a second line rather than cutting it off.- description={- <Text as="span" lineClamp={2}>- {`${model.description}${- dependencyCount > 0 ? t('models.installsDependencies', { count: dependencyCount }) : ''- }`}- </Text>- }- title={model.name}- />- );- })}- </ListStack>+ if (!externalProviderId) {+ return (+ <StarterSourceRow+ key={`${model.source}-${model.name}`}+ {...statusOf(model)}+ description={description}+ isMenuOpen={menuModel === model}+ model={model}+ source={model.source}+ onInstall={onInstall}+ onOpenMenu={menu.open}+ />+ );+ }++ return (+ <ListItem+ key={`${model.source}-${model.name}`}+ actions={+ configuredExternalProviders.has(externalProviderId) ? (+ <Badge colorPalette="green" fontSize="xs" size="lg" variant="surface">+ {t('models.installed')}+ </Badge>+ ) : (+ <Button size="sm" variant="outline" onClick={() => onConfigureExternalProvider(externalProviderId)}>+ <Icon as={KeyRoundIcon} boxSize="3" />+ {t('common.configure')}+ </Button>+ )+ }+ badges={<StarterBadges model={model} />}+ description={<StarterDescription text={description} />}+ title={model.name}+ />+ );+ })}+ </ListStack>+ <InstallSourceContextMenu+ status={menuModel ? statusOf(menuModel) : null}+ isOpen={menu.target !== null}+ target={menu.shown}+ onClose={menu.close}+ onExitComplete={menu.release}+ onInstall={() => {+ if (menuModel) {+ onInstall(menuModel);+ }+ }}+ />+ </>);};++const StarterBadges = ({ model }: { model: StarterModel }) => (+ <>+ <Badge colorPalette={getModelBaseColorPalette(model.base)} fontSize="xs" size="lg" variant="surface">+ {getModelBaseLabel(model.base)}+ </Badge>+ <Badge colorPalette="gray" fontSize="xs" size="lg" variant="surface">+ {getModelTypeLabel(model.type)}+ </Badge>+ </>+);++/** Starter descriptions carry the dependency note; allow a second line rather than cutting it off. */+const StarterDescription = ({ text }: { text: string }) => (+ <Text as="span" lineClamp={2}>+ {text}+ </Text>+);++/** Memoized so opening the list's menu re-renders only the targeted row; the list passes stable callbacks. */+const StarterSourceRow = memo(function StarterSourceRow({+ description,+ model,+ onInstall,+ ...row+}: InstallSourceStatus & {+ description: string;+ isMenuOpen: boolean;+ model: StarterModel;+ onInstall: (model: StarterModel) => void;+ onOpenMenu: (source: string, anchor: ListContextMenuAnchor) => void;+ source: string;+}) {+ return (+ <InstallSourceRow+ {...row}+ badges={<StarterBadges model={model} />}+ description={<StarterDescription text={description} />}+ name={model.name}+ title={model.name}+ onInstall={() => onInstall(model)}+ />+ );+});diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsx b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsxindex e3259642ea..c74c50ccd5 100644--- a/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsx@@ -1,11 +1,12 @@/* eslint-disable react-perf/jsx-no-new-function-as-prop */import { Badge, HStack, Icon, Spinner } from '@chakra-ui/react';-import { useActiveInstallSources } from '@features/models/data/installsStore';import { openInstallQueue, openModelDetail } from '@features/models/ui/uiStore';import { Button } from '@platform/ui';import { DownloadIcon } from 'lucide-react';import { useTranslation } from 'react-i18next';+import { useInstallSourceStage } from './InstallSourceMenu';+export const InstallSourceButton = ({installedModelKey = null,isInstalled = false,@@ -27,17 +28,18 @@ export const InstallSourceButton = ({source: string;}) => {const { t } = useTranslation();- const activeSources = useActiveInstallSources();- const isInstalling = isPending || activeSources.has(source);+ const stage = useInstallSourceStage(source, { installedModelKey, isInstalled, isPending });++ if (stage.kind === 'installed') {+ const { modelKey } = stage;- if (isInstalled || installedModelKey !== null) {return (<HStack flexShrink={0} gap="1.5"><Badge colorPalette="green" fontSize="xs" size="lg" variant="surface">{t('models.installed')}</Badge>- {installedModelKey !== null ? (- <Button size="sm" variant="ghost" onClick={() => openModelDetail(installedModelKey)}>+ {modelKey !== null ? (+ <Button size="sm" variant="ghost" onClick={() => openModelDetail(modelKey)}>{t('models.viewModel')}</Button>) : null}@@ -45,7 +47,7 @@ export const InstallSourceButton = ({);}- if (isInstalling) {+ if (stage.kind === 'installing') {return (<HStack flexShrink={0} gap="1.5"><Badge colorPalette="blue" fontSize="xs" size="lg" variant="surface">diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceMenu.tsx b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceMenu.tsxnew file mode 100644index 0000000000..7479bca12f--- /dev/null+++ b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceMenu.tsx@@ -0,0 +1,160 @@+/* eslint-disable react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */+import type { ListContextMenuAnchor } from '@platform/ui/list/ListItem';++import { Menu, Portal } from '@chakra-ui/react';+import { useActiveInstallSources } from '@features/models/data/installsStore';+import { openInstallQueue, openModelDetail } from '@features/models/ui/uiStore';+import { useExitRetainedValue } from '@platform/react/useExitRetainedValue';+import { MenuActionItem, MenuContent } from '@platform/ui/Menu';+import { CheckIcon, DownloadIcon, ListIcon, SquareArrowOutUpRightIcon } from 'lucide-react';+import { useCallback, useState } from 'react';+import { useTranslation } from 'react-i18next';++/** What a list knows about one installable source; active install jobs are read live by its controls. */+export interface InstallSourceStatus {+ /** The library model this source landed as; implies installed. */+ installedModelKey: string | null;+ /** Already in the library, without a known model to open. */+ isInstalled: boolean;+ /** The install POST is in flight (before a job exists). */+ isPending: boolean;+}++/** The next step a source offers; the row's button and its menu both follow it. */+export type InstallSourceStage =+ | { kind: 'installed'; modelKey: string | null }+ | { kind: 'installing' }+ | { kind: 'available' };++export const useInstallSourceStage = (+ source: string,+ { installedModelKey, isInstalled, isPending }: InstallSourceStatus+): InstallSourceStage => {+ const activeSources = useActiveInstallSources();++ if (isInstalled || installedModelKey !== null) {+ return { kind: 'installed', modelKey: installedModelKey };+ }++ return isPending || activeSources.has(source) ? { kind: 'installing' } : { kind: 'available' };+};++export interface InstallSourceMenuTarget extends ListContextMenuAnchor {+ source: string;+}++/**+ * One context menu per list: `target` is the row that was right-clicked, until the menu closes; `shown` keeps it+ * through the menu's exit animation. `open` keeps its identity so memoized rows skip re-rendering when only the+ * target changes.+ */+export const useInstallSourceMenu = () => {+ const [target, setTarget] = useState<InstallSourceMenuTarget | null>(null);+ const { release, value: shown } = useExitRetainedValue(target);+ const open = useCallback((source: string, anchor: ListContextMenuAnchor) => setTarget({ ...anchor, source }), []);++ return {+ close: () => {+ target?.restoreFocus();+ setTarget(null);+ },+ open,+ release,+ shown,+ target,+ };+};++/**+ * The list's single row menu. The list resolves `status` for the target on every render, so the menu follows the+ * source while it is open; it offers the same next step as the row's install button.+ */+export const InstallSourceContextMenu = ({+ isOpen,+ onClose,+ onExitComplete,+ onInstall,+ status,+ target,+}: {+ isOpen: boolean;+ onClose: () => void;+ /** Releases the retained target once the menu has animated out. */+ onExitComplete: () => void;+ /** Installs the target source. */+ onInstall: () => void;+ /** Null when the target is no longer listed. */+ status: InstallSourceStatus | null;+ /** The shown target, kept while the menu animates out. */+ target: InstallSourceMenuTarget | null;+}) => (+ <Menu.Root+ key={target ? target.source : 'none'}+ lazyMount+ open={isOpen}+ positioning={{+ getAnchorRect: () => (target ? { height: 1, width: 1, x: target.x, y: target.y } : null),+ placement: 'bottom-start',+ }}+ unmountOnExit+ onExitComplete={onExitComplete}+ onOpenChange={(event) => {+ if (!event.open) {+ onClose();+ }+ }}+ >+ <Portal>+ <Menu.Positioner>+ {target && status ? (+ <MenuContent minW="10rem">+ <InstallSourceMenuItem source={target.source} status={status} onInstall={onInstall} />+ </MenuContent>+ ) : null}+ </Menu.Positioner>+ </Portal>+ </Menu.Root>+);++/** Mounted only while the menu is open, so the list holds no install-job subscription for it otherwise. */+const InstallSourceMenuItem = ({+ onInstall,+ source,+ status,+}: {+ onInstall: () => void;+ source: string;+ status: InstallSourceStatus;+}) => {+ const { t } = useTranslation();+ const stage = useInstallSourceStage(source, status);++ if (stage.kind === 'installed' && stage.modelKey !== null) {+ const { modelKey } = stage;++ return (+ <MenuActionItem+ icon={SquareArrowOutUpRightIcon}+ label={t('models.viewModel')}+ value="view-model"+ onSelect={() => openModelDetail(modelKey)}+ />+ );+ }++ if (stage.kind === 'installed') {+ // A status rather than a dead end: the row's own control is the same badge, and keeping a menu keeps right-click+ // consistent across rows (no browser menu on some of them) and across an install finishing while it is open.+ return <MenuActionItem disabled icon={CheckIcon} label={t('models.installed')} value="installed" onSelect={noop} />;+ }++ if (stage.kind === 'installing') {+ return (+ <MenuActionItem icon={ListIcon} label={t('models.viewQueue')} value="view-queue" onSelect={openInstallQueue} />+ );+ }++ return <MenuActionItem icon={DownloadIcon} label={t('models.install')} value="install" onSelect={onInstall} />;+};++const noop = () => undefined;diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceRow.tsx b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceRow.tsxnew file mode 100644index 0000000000..93faee4ba5--- /dev/null+++ b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceRow.tsx@@ -0,0 +1,79 @@+/* oxlint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-function-as-prop -- ListItem slots take JSX; the React Compiler memoizes them. */+import type { ListContextMenuAnchor } from '@platform/ui/list/ListItem';+import type { ReactNode } from 'react';++import { ListItem } from '@platform/ui/list/ListItem';+import { MiddleTruncate } from '@platform/ui/MiddleTruncate';+import { memo } from 'react';++import type { InstallSourceStatus } from './InstallSourceMenu';++import { InstallSourceButton } from './InstallSourceButton';+import { sourceFileName } from './useSourceNameFilter';++interface InstallSourceRowProps extends InstallSourceStatus {+ /** This row is the target of its list's context menu. */+ isMenuOpen: boolean;+ onOpenMenu: (source: string, anchor: ListContextMenuAnchor) => void;+ /** Source string used to match an active install job. */+ source: string;+}++/**+ * An installable source and its Install button. Right-click opens the list's shared menu for this source; the row+ * itself is not a tab stop, since the button already offers the same action to the keyboard.+ */+export const InstallSourceRow = ({+ badges,+ description,+ isMenuOpen,+ name,+ onInstall,+ onOpenMenu,+ source,+ title,+ ...status+}: InstallSourceRowProps & {+ badges?: ReactNode;+ description?: ReactNode;+ /** What installs, so repeated Install controls stay distinguishable to assistive tech. */+ name: string;+ onInstall: () => void;+ title: string;+}) => (+ <ListItem+ actions={<InstallSourceButton {...status} name={name} source={source} onInstall={onInstall} />}+ badges={badges}+ description={description}+ isMenuOpen={isMenuOpen}+ tabIndex={-1}+ title={title}+ onContextMenu={(anchor) => onOpenMenu(source, anchor)}+ />+);++/**+ * A file source (a scanned path or a repository URL), memoized so opening the list's menu re-renders only the+ * targeted row; callers pass stable callbacks.+ */+export const InstallPathRow = memo(function InstallPathRow({+ location,+ onInstall,+ ...row+}: InstallSourceRowProps & {+ /** Where the file sits under its scan root or repository, shown under the file name. */+ location: string | null;+ onInstall: (source: string) => void;+}) {+ const fileName = sourceFileName(row.source);++ return (+ <InstallSourceRow+ {...row}+ description={location ? <MiddleTruncate as="span" text={location} title={row.source} /> : undefined}+ name={location ?? fileName}+ title={fileName}+ onInstall={() => onInstall(row.source)}+ />+ );+});