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(ui): hide the link picker for unlinkable bases
Josh Corbett3b1762a68c00
diff --git a/invokeai/frontend/webv2/src/features/models/core/relationships.test.ts b/invokeai/frontend/webv2/src/features/models/core/relationships.test.tsindex dc4416d734..378e65815f 100644--- a/invokeai/frontend/webv2/src/features/models/core/relationships.test.ts+++ b/invokeai/frontend/webv2/src/features/models/core/relationships.test.ts@@ -3,7 +3,13 @@ import { describe, expect, it } from 'vitest';import type { RelatableModel } from './relationships';import type { ModelBase, ModelTaxonomyType } from './types';-import { isBaseCompatible, isLinkableType, LINKABLE_TYPES, NULL_BASE_ALLOWANCES } from './relationships';+import {+ hasLinkableBase,+ isBaseCompatible,+ isLinkableType,+ LINKABLE_TYPES,+ NULL_BASE_ALLOWANCES,+} from './relationships';const model = (base: ModelBase, type: ModelTaxonomyType = 'lora'): RelatableModel => ({ base, type });@@ -65,6 +71,16 @@ describe('isBaseCompatible', () => {});});+describe('hasLinkableBase', () => {+ it('accepts concrete bases and allowanced any-based helpers only', () => {+ expect(hasLinkableBase(model('sdxl', 'main'))).toBe(true);+ expect(hasLinkableBase(model('any', 't5_encoder'))).toBe(true);+ expect(hasLinkableBase(model('any', 'spandrel_image_to_image'))).toBe(false);+ expect(hasLinkableBase(model('external', 'main'))).toBe(false);+ expect(hasLinkableBase(model('unknown', 'main'))).toBe(false);+ });+});+describe('LINKABLE_TYPES', () => {it('includes every curated type', () => {for (const type of Object.keys(NULL_BASE_ALLOWANCES)) {diff --git a/invokeai/frontend/webv2/src/features/models/core/relationships.ts b/invokeai/frontend/webv2/src/features/models/core/relationships.tsindex a6f8f796d5..6a59c846c5 100644--- a/invokeai/frontend/webv2/src/features/models/core/relationships.ts+++ b/invokeai/frontend/webv2/src/features/models/core/relationships.ts@@ -65,6 +65,14 @@ const LINKABLE_TYPE_SET: ReadonlySet<ModelTaxonomyType> = new Set(LINKABLE_TYPESexport const isLinkableType = (type: ModelTaxonomyType): boolean => LINKABLE_TYPE_SET.has(type);+/**+ * Whether any candidate could ever be compatible with this model: a concrete+ * base, or an `any` base whose type has a curated allowance. `external` and+ * `unknown` subjects can never take new links.+ */+export const hasLinkableBase = (model: RelatableModel): boolean =>+ !NULL_BASES.has(String(model.base)) || (model.base === 'any' && NULL_BASE_ALLOWANCES[model.type] !== undefined);+const isAllowedHelperFor = (helper: RelatableModel, host: RelatableModel): boolean =>helper.base === 'any' &&!NULL_BASES.has(String(host.base)) &&diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.browser.test.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.browser.test.tsxindex 50f98c5cb4..138f89fe02 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.browser.test.tsx@@ -76,17 +76,20 @@ describe('RelatedModelsSection', () => {setRelationshipsSnapshotForTests({ relatedKeysByModelKey: {} });});- const renderSection = async () => {+ const renderSection = async (model: Parameters<typeof RelatedModelsSection>[0]['model'] = SECTION_MODEL) => {await act(() => {root.render(<ChakraProvider value={system}><ModelsUiProvider adapter={MODELS_UI_ADAPTER}>- <RelatedModelsSection model={SECTION_MODEL} onError={vi.fn()} />+ <RelatedModelsSection model={model} onError={vi.fn()} /></ModelsUiProvider></ChakraProvider>);});+ };+ const renderSectionAndOpenPicker = async () => {+ await renderSection();await act(() => host.querySelector<HTMLButtonElement>('[aria-haspopup="listbox"]')?.click());await expect.poll(() => document.querySelectorAll('[role="option"]').length).toBeGreaterThan(0);};@@ -95,7 +98,7 @@ describe('RelatedModelsSection', () => {[...document.querySelectorAll('[role="option"]')].map((option) => option.textContent ?? '');it('offers only base-compatible candidates for a flux main', async () => {- await renderSection();+ await renderSectionAndOpenPicker();const options = optionTexts().join(' ');@@ -109,7 +112,7 @@ describe('RelatedModelsSection', () => {});it('links a model and renders it without refetching', async () => {- await renderSection();+ await renderSectionAndOpenPicker();const t5Option = [...document.querySelectorAll<HTMLElement>('[role="option"]')].find((option) =>option.textContent?.includes('T5 XXL')@@ -123,4 +126,15 @@ describe('RelatedModelsSection', () => {await expect.poll(() => host.textContent).toContain('T5 XXL');expect(api.getRelatedModelKeys).toHaveBeenCalledTimes(1);});++ it('shows persisted links but no picker for an unlinkable base', async () => {+ api.getRelatedModelKeys.mockResolvedValue(['flux-main']);+ await renderSection({ base: 'external', key: 'gpt-image', type: 'main' });++ // The wildcard-era link renders with its unlink affordance...+ await expect.poll(() => host.textContent).toContain('FLUX Dev');+ expect(host.querySelector('[aria-label*="unlinkNamed"]')).not.toBeNull();+ // ...but an external-base subject can never match, so no add-picker.+ expect(host.querySelector('[aria-haspopup="listbox"]')).toBeNull();+ });});diff --git a/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsxindex 6b3b7dbe78..ab2dc0695c 100644--- a/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx+++ b/invokeai/frontend/webv2/src/features/models/ui/detail/RelatedModelsSection.tsx@@ -3,7 +3,7 @@ import type { ModelConfig } from '@features/models/core/types';import { Badge, Icon, Spinner, Stack, Text } from '@chakra-ui/react';import { getModelBaseColorPalette, getModelBaseLabel } from '@features/models/core/baseIdentity';-import { isBaseCompatible, LINKABLE_TYPES } from '@features/models/core/relationships';+import { hasLinkableBase, isBaseCompatible, LINKABLE_TYPES } from '@features/models/core/relationships';import { getModelTypeLabel } from '@features/models/core/taxonomy';import { useModelsSelector } from '@features/models/data/modelsStore';import {@@ -109,26 +109,35 @@ const RelatedModelsForModel = ({ model, onError }: RelatedModelsSectionProps) =>}};+ // A subject whose base can never match a candidate (external/unknown, or an+ // any-based type with no allowance) keeps its persisted links manageable but+ // gets no add-picker — it would be a permanently empty combobox.+ const canAddLinks = hasLinkableBase(model);+return (<Stack gap="2"><Stack gap="0.5"><FieldLabel>{t('models.relatedModels')}</FieldLabel>- <Text color="fg.subtle" fontSize="2xs">- {t('models.relatedModelsHelp')}- </Text>+ {canAddLinks ? (+ <Text color="fg.subtle" fontSize="2xs">+ {t('models.relatedModelsHelp')}+ </Text>+ ) : null}</Stack>- <ModelSelect- excludeKeys={excludeKeys}- filter={(candidate) => isBaseCompatible(model, candidate)}- modelTypes={LINKABLE_TYPES}- placeholder={t('models.searchCompatibleToLink')}- showManagerButton={false}- size="sm"- value={null}- onChange={(target) => {- void handleAdd(target);- }}- />+ {canAddLinks ? (+ <ModelSelect+ excludeKeys={excludeKeys}+ filter={(candidate) => isBaseCompatible(model, candidate)}+ modelTypes={LINKABLE_TYPES}+ placeholder={t('models.searchCompatibleToLink')}+ showManagerButton={false}+ size="sm"+ value={null}+ onChange={(target) => {+ void handleAdd(target);+ }}+ />+ ) : null}{relatedKeys === null ? (<Spinner color="fg.subtle" size="xs" />) : relatedModels.length === 0 ? (