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): show add-models results as divided list rows

Josh Corbett0c0a7ec5fda3
diff --git a/invokeai/frontend/webv2/public/locales/en.json b/invokeai/frontend/webv2/public/locales/en.json
index 34e4402594..43f813103e 100644
--- a/invokeai/frontend/webv2/public/locales/en.json
+++ b/invokeai/frontend/webv2/public/locales/en.json
@@ -1099,6 +1099,7 @@
"couldNotLoad": "Could not load models",
"couldNotLoadInstallQueue": "Could not load the install queue",
"couldNotLoadStarterModels": "Could not load starter models",
+ "starterModelsList": "Starter models",
"countToInstall": "{{count}} to install",
"customizeDefaultField": "Customize {{field}} for this model",
"customizedForThisModel": "Customized for this model",
@@ -1193,6 +1194,7 @@
"huggingFaceRejectedToken": "HuggingFace rejected this token. Check that it has read access.",
"huggingFaceToken": "HuggingFace token",
"install": "Install",
+ "installNamed": "Install {{name}}",
"installAllCount": "Install all ({{count}})",
"installAllQueued": "Installs queued",
"installAllQueuedDescription_one": "{{count}} install queued.",
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.tsx
index 33137e1e28..5fbb37ea53 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,10 +2,13 @@
import type { HFLookupState } from '@features/models/ui/uiStore';
import { Stack } from '@chakra-ui/react';
+import { InstallSourceButton } from '@features/models/ui/shared/InstallSourceButton';
import { ResultsListHeader } from '@features/models/ui/shared/ResultsListHeader';
-import { InstallSourceButton, SourceListItem } from '@features/models/ui/shared/SourceListItem';
import { useInstalledSourceKeys } from '@features/models/ui/shared/useInstalledSources';
-import { sourceFileName, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';
+import { sourceFileName, sourceLocation, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';
+import { ListItem } from '@platform/ui/list/ListItem';
+import { ListStack } from '@platform/ui/list/ListStack';
+import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
import { useTranslation } from 'react-i18next';
import { InstallOptions } from './InstallOptions';
@@ -51,21 +54,28 @@ export const HuggingFaceFiles = ({
onInstallAll={installAll}
onSearchChange={setFilter}
/>
- {filteredUrls.map((url) => (
- <SourceListItem
- key={url}
- title={sourceFileName(url)}
- titleTooltip={url}
- trailing={
- <InstallSourceButton
- installedModelKey={installedSourceKeys.get(url) ?? null}
- isPending={pendingSources.has(url)}
- source={url}
- onInstall={() => onInstall(url)}
+ <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)}
/>
- }
- />
- ))}
+ );
+ })}
+ </ListStack>
</Stack>
);
};
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.tsx
index d7fd6cd00e..12d5a15db4 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,11 +2,14 @@
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 { ResultsListHeader } from '@features/models/ui/shared/ResultsListHeader';
-import { InstallSourceButton, SourceListItem } from '@features/models/ui/shared/SourceListItem';
import { useInstalledSourceKeys } from '@features/models/ui/shared/useInstalledSources';
-import { sourceFileName, useSourceNameFilter } from '@features/models/ui/shared/useSourceNameFilter';
+import { sourceFileName, 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';
@@ -86,23 +89,29 @@ export const ScanResults = ({
onInstallAll={installAll}
onSearchChange={setFilter}
/>
- {filteredResults.map((result) => (
- <SourceListItem
- key={result.path}
- description={result.path}
- title={sourceFileName(result.path)}
- titleTooltip={result.path}
- trailing={
- <InstallSourceButton
- installedModelKey={installedSourceKeys.get(result.path) ?? null}
- isInstalled={isRowInstalled(result)}
- isPending={pendingSources.has(result.path)}
- source={result.path}
- onInstall={() => onInstall(result.path)}
+ <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)}
/>
- }
- />
- ))}
+ );
+ })}
+ </ListStack>
</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.tsx
index 27b6ba374f..16fe1fc368 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
@@ -6,9 +6,11 @@ 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, SourceListItem } from '@features/models/ui/shared/SourceListItem';
+import { InstallSourceButton } from '@features/models/ui/shared/InstallSourceButton';
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 { useTranslation } from 'react-i18next';
@@ -79,7 +81,7 @@ export const StarterList = ({
}
return (
- <Stack gap="1.5">
+ <ListStack dividers label={t('models.starterModelsList')}>
{models.map((model) => {
const externalProviderId = getExternalProviderId(model.source);
const dependencyCount = (model.dependencies ?? []).filter(
@@ -87,19 +89,11 @@ export const StarterList = ({
).length;
const trailing = externalProviderId ? (
configuredExternalProviders.has(externalProviderId) ? (
- <Badge colorPalette="green" flexShrink={0} fontSize="2xs" size="sm" variant="surface">
+ <Badge colorPalette="green" fontSize="2xs" size="sm" variant="surface">
{t('models.installed')}
</Badge>
) : (
- <Button
- flexShrink={0}
- size="2xs"
- variant="outline"
- onClick={(event) => {
- event.stopPropagation();
- onConfigureExternalProvider(externalProviderId);
- }}
- >
+ <Button size="2xs" variant="outline" onClick={() => onConfigureExternalProvider(externalProviderId)}>
<Icon as={KeyRoundIcon} boxSize="3" />
{t('common.configure')}
</Button>
@@ -109,38 +103,38 @@ export const StarterList = ({
installedModelKey={findInstalledStarterModelKey(model, installedSourceKeys, installedModels)}
isInstalled={model.is_installed}
isPending={pendingSources.has(model.source)}
+ name={model.name}
source={model.source}
onInstall={() => onInstall(model)}
/>
);
return (
- <SourceListItem
+ <ListItem
key={`${model.source}-${model.name}`}
+ actions={trailing}
badges={
<>
- <Badge
- colorPalette={getModelBaseColorPalette(model.base)}
- flexShrink={0}
- fontSize="2xs"
- size="sm"
- variant="surface"
- >
+ <Badge colorPalette={getModelBaseColorPalette(model.base)} fontSize="2xs" size="sm" variant="surface">
{getModelBaseLabel(model.base)}
</Badge>
- <Badge colorPalette="gray" flexShrink={0} fontSize="2xs" size="sm" variant="surface">
+ <Badge colorPalette="gray" fontSize="2xs" size="sm" variant="surface">
{getModelTypeLabel(model.type)}
</Badge>
</>
}
- description={`${model.description}${
- dependencyCount > 0 ? t('models.installsDependencies', { count: dependencyCount }) : ''
- }`}
+ // 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}
- trailing={trailing}
/>
);
})}
- </Stack>
+ </ListStack>
);
};
diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx
index d5e600d963..17a9e25389 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx
@@ -13,11 +13,12 @@ import {
useRelatedModelKeys,
} from '@features/models/data/relationshipsStore';
import { ModelSelect } from '@features/models/ui/components';
-import { SourceListItem } from '@features/models/ui/shared/SourceListItem';
import { useMountEffect } from '@platform/react/useMountEffect';
import { isAccountScopeCurrent, captureAccountScope } from '@platform/state/accountLifecycle';
import { getApiErrorMessage } from '@platform/transport/http';
import { IconButton, FieldLabel, Tooltip } from '@platform/ui';
+import { ListItem } from '@platform/ui/list/ListItem';
+import { ListStack } from '@platform/ui/list/ListStack';
import { Link2OffIcon } from 'lucide-react';
import { useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
@@ -139,47 +140,46 @@ const RelatedModelsForModel = ({ model, onError }: RelatedModelsSectionProps) =>
{t('models.noRelatedModels')}
</Text>
) : (
- <Stack gap="1.5">
+ <ListStack label={t('models.relatedModels')}>
{relatedModels.map(({ key, model: relatedModel }) => (
- <SourceListItem
+ <ListItem
key={key}
+ actions={
+ <Tooltip content={t('models.unlink')}>
+ <IconButton
+ aria-label={t('models.unlinkNamed', { name: relatedModel?.name ?? key })}
+ disabled={isMutating}
+ size="2xs"
+ variant="ghost"
+ onClick={() => {
+ void handleRemove(key);
+ }}
+ >
+ <Icon as={Link2OffIcon} boxSize="3" />
+ </IconButton>
+ </Tooltip>
+ }
badges={
relatedModel ? (
<>
<Badge
colorPalette={getModelBaseColorPalette(relatedModel.base)}
- flexShrink={0}
fontSize="2xs"
size="sm"
variant="surface"
>
{getModelBaseLabel(relatedModel.base)}
</Badge>
- <Badge colorPalette="gray" flexShrink={0} fontSize="2xs" size="sm" variant="surface">
+ <Badge colorPalette="gray" fontSize="2xs" size="sm" variant="surface">
{getModelTypeLabel(relatedModel.type)}
</Badge>
</>
) : undefined
}
title={relatedModel?.name ?? key}
- trailing={
- <Tooltip content={t('models.unlink')}>
- <IconButton
- aria-label={t('models.unlinkNamed', { name: relatedModel?.name ?? key })}
- disabled={isMutating}
- size="2xs"
- variant="ghost"
- onClick={() => {
- void handleRemove(key);
- }}
- >
- <Icon as={Link2OffIcon} boxSize="3" />
- </IconButton>
- </Tooltip>
- }
/>
))}
- </Stack>
+ </ListStack>
)}
</Stack>
);
diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsx b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsx
new file mode 100644
index 0000000000..a53ab538ff
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/shared/InstallSourceButton.tsx
@@ -0,0 +1,68 @@
+/* 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';
+
+export const InstallSourceButton = ({
+ installedModelKey = null,
+ isInstalled = false,
+ isPending = false,
+ name,
+ onInstall,
+ source,
+}: {
+ /** 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;
+ /** What installs, so repeated Install buttons stay distinguishable to assistive tech. */
+ name: string;
+ onInstall: () => void;
+ /** Source string used to match an active install job. */
+ source: string;
+}) => {
+ const { t } = useTranslation();
+ const activeSources = useActiveInstallSources();
+ const isInstalling = isPending || activeSources.has(source);
+
+ if (isInstalled || installedModelKey !== null) {
+ return (
+ <HStack flexShrink={0} gap="1.5">
+ <Badge colorPalette="green" fontSize="2xs" size="sm" variant="surface">
+ {t('models.installed')}
+ </Badge>
+ {installedModelKey !== null ? (
+ <Button size="2xs" variant="ghost" onClick={() => openModelDetail(installedModelKey)}>
+ {t('models.viewModel')}
+ </Button>
+ ) : null}
+ </HStack>
+ );
+ }
+
+ if (isInstalling) {
+ return (
+ <HStack flexShrink={0} gap="1.5">
+ <Badge colorPalette="blue" fontSize="2xs" size="sm" variant="surface">
+ <Spinner borderWidth="1.5px" boxSize="2.5" />
+ {t('models.installing')}
+ </Badge>
+ <Button size="2xs" variant="ghost" onClick={openInstallQueue}>
+ {t('models.viewQueue')}
+ </Button>
+ </HStack>
+ );
+ }
+
+ return (
+ <Button aria-label={t('models.installNamed', { name })} size="2xs" variant="outline" onClick={onInstall}>
+ <Icon as={DownloadIcon} boxSize="3" />
+ {t('models.install')}
+ </Button>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/SourceListItem.tsx b/invokeai/frontend/webv2/src/features/models/ui/shared/SourceListItem.tsx
deleted file mode 100644
index 5de965d3e4..0000000000
--- a/invokeai/frontend/webv2/src/features/models/ui/shared/SourceListItem.tsx
+++ /dev/null
@@ -1,121 +0,0 @@
-/* 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 { ReactNode } from 'react';
-
-import { Badge, HStack, Icon, Spinner, Stack, Text } from '@chakra-ui/react';
-import { useActiveInstallSources } from '@features/models/data/installsStore';
-import { openInstallQueue, openModelDetail } from '@features/models/ui/uiStore';
-import { Button, Panel } from '@platform/ui';
-import { MiddleTruncate } from '@platform/ui/MiddleTruncate';
-import { DownloadIcon } from 'lucide-react';
-import { useTranslation } from 'react-i18next';
-
-export const SourceListItem = ({
- badges,
- description,
- title,
- titleTooltip,
- trailing,
-}: {
- badges?: ReactNode;
- description?: ReactNode;
- title: string;
- titleTooltip?: string;
- trailing?: ReactNode;
-}) => (
- <Panel alignItems="center" flexDirection="row" gap="3" p="2.5">
- <Stack flex="1" gap="0.5" minW="0">
- <HStack gap="1.5" minW="0">
- <MiddleTruncate fontSize="xs" fontWeight="600" text={title} title={titleTooltip} />
- {badges}
- </HStack>
- {description ? (
- // `fg.subtle` at this size only reaches 3.56:1 on the panel surface,
- // short of WCAG AA. `fg.muted` clears 4.5:1.
- <Text color="fg.muted" fontSize="2xs" lineClamp={2}>
- {description}
- </Text>
- ) : null}
- </Stack>
- {trailing}
- </Panel>
-);
-
-export const InstallSourceButton = ({
- installedModelKey = null,
- isInstalled = false,
- isPending = false,
- onInstall,
- source,
-}: {
- /** 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;
- onInstall: () => void;
- /** Source string used to match an active install job. */
- source: string;
-}) => {
- const { t } = useTranslation();
- const activeSources = useActiveInstallSources();
- const isInstalling = isPending || activeSources.has(source);
-
- if (isInstalled || installedModelKey !== null) {
- return (
- <HStack flexShrink={0} gap="1.5">
- <Badge colorPalette="green" fontSize="2xs" size="sm" variant="surface">
- {t('models.installed')}
- </Badge>
- {installedModelKey !== null ? (
- <Button
- size="2xs"
- variant="ghost"
- onClick={(event) => {
- event.stopPropagation();
- openModelDetail(installedModelKey);
- }}
- >
- {t('models.viewModel')}
- </Button>
- ) : null}
- </HStack>
- );
- }
-
- if (isInstalling) {
- return (
- <HStack flexShrink={0} gap="1.5">
- <Badge colorPalette="blue" fontSize="2xs" size="sm" variant="surface">
- <Spinner borderWidth="1.5px" boxSize="2.5" />
- {t('models.installing')}
- </Badge>
- <Button
- size="2xs"
- variant="ghost"
- onClick={(event) => {
- event.stopPropagation();
- openInstallQueue();
- }}
- >
- {t('models.viewQueue')}
- </Button>
- </HStack>
- );
- }
-
- return (
- <Button
- flexShrink={0}
- size="2xs"
- variant="outline"
- onClick={(event) => {
- event.stopPropagation();
- onInstall();
- }}
- >
- <Icon as={DownloadIcon} boxSize="3" />
- {t('models.install')}
- </Button>
- );
-};
diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.test.ts b/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.test.ts
new file mode 100644
index 0000000000..22c0d2cac6
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.test.ts
@@ -0,0 +1,21 @@
+import { describe, expect, it } from 'vitest';
+
+import { sourceLocation } from './useSourceNameFilter';
+
+describe('sourceLocation', () => {
+ it('keeps the part of a Hugging Face file URL inside the repo', () => {
+ expect(sourceLocation('https://huggingface.co/org/repo/resolve/main/v2/model.safetensors')).toBe(
+ 'v2/model.safetensors'
+ );
+ });
+
+ it('keeps the part of a scanned path below the scan root, with or without a trailing separator', () => {
+ expect(sourceLocation('/mnt/models/loras/a/model.safetensors', '/mnt/models')).toBe('loras/a/model.safetensors');
+ expect(sourceLocation('/mnt/models/loras/a/model.safetensors', '/mnt/models/')).toBe('loras/a/model.safetensors');
+ });
+
+ it('adds nothing when the source sits directly in its root', () => {
+ expect(sourceLocation('https://huggingface.co/org/repo/resolve/main/model.safetensors')).toBeNull();
+ expect(sourceLocation('/mnt/models/model.safetensors', '/mnt/models')).toBeNull();
+ });
+});
diff --git a/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.ts b/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.ts
index 6241b88d9f..cbab2df5cd 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.ts
+++ b/invokeai/frontend/webv2/src/features/models/ui/shared/useSourceNameFilter.ts
@@ -3,6 +3,22 @@ import { useDeferredValue, useMemo, useState } from 'react';
/** Last path/URL segment: install sources display and filter by file name. */
export const sourceFileName = (source: string): string => source.split(/[\\/]/).at(-1) ?? source;
+const HF_RESOLVE_PATH = /\/resolve\/[^/]+\/(.+)$/;
+
+/**
+ * Where a source sits under its repo or scan root: the part that tells same-named files apart. Null when that is
+ * just the file name, which the row already shows.
+ */
+export const sourceLocation = (source: string, root?: string): string | null => {
+ const inRepo = HF_RESOLVE_PATH.exec(source)?.[1];
+ const trimmedRoot = root?.replace(/[\\/]+$/, '');
+ const relative =
+ inRepo ??
+ (trimmedRoot && source.startsWith(trimmedRoot) ? source.slice(trimmedRoot.length).replace(/^[\\/]+/, '') : source);
+
+ return relative === sourceFileName(source) ? null : relative;
+};
+
/** Pass a module-stable sourceOf so deferred filename filtering stays keyed on items. */
export const useSourceNameFilter = <Item>(items: readonly Item[], sourceOf: (item: Item) => string) => {
const [filter, setFilter] = useState('');