Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function ModelSelectorTrigger({
</Tooltip>
)

if (!showClear) return trigger
if (!onClear) return trigger

return (
<div
Expand All @@ -265,19 +265,21 @@ function ModelSelectorTrigger({
)}
>
{trigger}
<IconButton
aria-label={clearLabel ?? t(($) => $['operation.reset'], { ns: 'common' })}
size="sm"
disabled={isDisabled}
onClick={onClear}
className={cn(
'pointer-events-none absolute top-1/2 -translate-y-1/2 opacity-0 group-focus-within/model-selector-clearable:pointer-events-auto group-focus-within/model-selector-clearable:opacity-100 group-hover/model-selector-clearable:pointer-events-auto group-hover/model-selector-clearable:opacity-100',
'text-text-quaternary hover:bg-transparent hover:text-text-tertiary focus-visible:bg-components-input-bg-hover focus-visible:ring-inset',
shape === 'split' ? 'right-1' : size === 'small' ? 'right-4.5' : 'right-5',
)}
>
<span aria-hidden="true" className="i-ri-close-circle-fill size-4" />
</IconButton>
{showClear && (
<IconButton
aria-label={clearLabel ?? t(($) => $['operation.reset'], { ns: 'common' })}
size="sm"
disabled={isDisabled}
onClick={onClear}
className={cn(
'pointer-events-none absolute top-1/2 -translate-y-1/2 opacity-0 group-focus-within/model-selector-clearable:pointer-events-auto group-focus-within/model-selector-clearable:opacity-100 group-hover/model-selector-clearable:pointer-events-auto group-hover/model-selector-clearable:opacity-100',
'text-text-quaternary hover:bg-transparent hover:text-text-tertiary focus-visible:bg-components-input-bg-hover focus-visible:ring-inset',
shape === 'split' ? 'right-1' : size === 'small' ? 'right-4.5' : 'right-5',
)}
>
<span aria-hidden="true" className="i-ri-close-circle-fill size-4" />
</IconButton>
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ vi.mock('react-i18next', async () => {
'modelProvider.systemModelSettingsTitle': 'Default Model Settings',
'modelProvider.systemReasoningModel.key': 'System Reasoning Model',
'modelProvider.ttsModel.key': 'TTS Model',
'modelProvider.embeddingModel.key': 'Embedding Model',
'modelProvider.rerankModel.key': 'Rerank Model',
'modelProvider.clearDefaultModel.title': 'Clear {{modelType}}?',
'operation.cancel': 'Cancel',
'operation.clear': 'Clear',
Expand All @@ -48,53 +50,63 @@ vi.mock('react-i18next', async () => {
beforeEach(() => vi.stubGlobal('BASE_UI_ANIMATIONS_DISABLED', false))
afterEach(() => vi.unstubAllGlobals())

it('keeps nested settings visible and returns focus to the TTS selector when clearing removes its clear button', async () => {
// The clear button unmounts on confirmation; browser focus must stay on this field in the parent dialog.
const { queryClient, wrapper: Wrapper } = createConsoleQueryWrapper({
workspacePermissionKeys: ['plugin.model_config'],
})
seedModelProviderQueries(queryClient, [
createModelCatalogFixture({
models: (['llm', 'text-embedding', 'rerank', 'speech2text', 'tts'] as const).map(
(model_type) =>
createCatalogModelFixture({
model: `${model_type}-model`,
model_type,
label: { en_US: `${model_type} model` },
}),
),
}),
])
try {
const screen = await render(
<NuqsTestingAdapter>
<Wrapper>
<SystemModel notConfigured={false} />
</Wrapper>
</NuqsTestingAdapter>,
)
await screen.getByRole('button', { name: 'System Model Settings' }).click()
const settings = screen.getByRole('dialog', { name: 'Default Model Settings' })
await settings.getByRole('button', { name: /^tts model/ }).hover()
const clearButton = settings.getByRole('button', { name: 'Clear TTS Model' })
const settingsPopup = settings.element()
await clearButton.click()
const confirmation = screen.getByRole('alertdialog', { name: 'Clear TTS Model?' })
await expect.element(confirmation).toBeVisible()
await expect.element(settingsPopup).toBeVisible()
await confirmation.getByRole('button', { name: 'Cancel' }).click()
await expect.element(confirmation).not.toBeInTheDocument()
await expect.element(clearButton).toHaveFocus()

await clearButton.click()
await confirmation.getByRole('button', { name: 'Clear' }).click()
await expect.element(confirmation).not.toBeInTheDocument()
await expect.element(clearButton).not.toBeInTheDocument()
// All other defaults remain configured, so the only empty selector is the cleared TTS field.
await expect
.element(settings.getByRole('button', { name: 'plugin.detailPanel.configureModel' }))
.toHaveFocus()
} finally {
queryClient.clear()
}
})
it.each([
{ modelType: 'tts', label: 'TTS Model', requiresConfirmation: true },
{ modelType: 'text-embedding', label: 'Embedding Model', requiresConfirmation: false },
{ modelType: 'rerank', label: 'Rerank Model', requiresConfirmation: false },
])(
'returns focus to the $label selector after clearing',
async ({ modelType, label, requiresConfirmation }) => {
// The clear button unmounts on clearing; browser focus must stay on this field in the parent dialog.
const { queryClient, wrapper: Wrapper } = createConsoleQueryWrapper({
workspacePermissionKeys: ['plugin.model_config'],
})
seedModelProviderQueries(queryClient, [
createModelCatalogFixture({
models: (['llm', 'text-embedding', 'rerank', 'speech2text', 'tts'] as const).map(
(model_type) =>
createCatalogModelFixture({
model: `${model_type}-model`,
model_type,
label: { en_US: `${model_type} model` },
}),
),
}),
])
try {
const screen = await render(
<NuqsTestingAdapter>
<Wrapper>
<SystemModel notConfigured={false} />
</Wrapper>
</NuqsTestingAdapter>,
)
await screen.getByRole('button', { name: 'System Model Settings' }).click()
const settings = screen.getByRole('dialog', { name: 'Default Model Settings' })
await settings.getByRole('button', { name: new RegExp(`^${modelType} model`) }).hover()
const clearButton = settings.getByRole('button', { name: `Clear ${label}` })
const settingsPopup = settings.element()
await clearButton.click()
if (requiresConfirmation) {
const confirmation = screen.getByRole('alertdialog', { name: `Clear ${label}?` })
await expect.element(confirmation).toBeVisible()
await expect.element(settingsPopup).toBeVisible()
await confirmation.getByRole('button', { name: 'Cancel' }).click()
await expect.element(confirmation).not.toBeInTheDocument()
await expect.element(clearButton).toHaveFocus()
await clearButton.click()
await confirmation.getByRole('button', { name: 'Clear' }).click()
await expect.element(confirmation).not.toBeInTheDocument()
} else {
await expect.element(screen.getByRole('alertdialog')).not.toBeInTheDocument()
}
await expect.element(clearButton).not.toBeInTheDocument()
// All other defaults remain configured, so the only empty selector is the cleared field.
await expect
.element(settings.getByRole('button', { name: 'plugin.detailPanel.configureModel' }))
.toHaveFocus()
} finally {
queryClient.clear()
}
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ function SystemModelSession({
setClearConfirmation({ modelType, labelKey, open: true })
return
}
modelTriggersRef.current[modelType]?.focus()
handleChangeDefaultModel(modelType, undefined)
}
: undefined,
Expand Down
Loading