为默认模型增加标识
ConversationModelSelect 记录 defaultModelId,在下拉选项中对默认模型显示「默认」小标签 首页与项目右侧对话共用同一组件,默认模型标识两处同时生效 补充默认模型标识的回归测试
This commit is contained in:
+8
-1
@@ -21,6 +21,7 @@ export function ConversationModelSelect({
|
||||
}) {
|
||||
const [models, setModels] = useState<ClientLlmModel[]>([]);
|
||||
const [selected, setSelected] = useState('');
|
||||
const [defaultModelId, setDefaultModelId] = useState('');
|
||||
const [busy, setBusy] = useState(!lazy);
|
||||
const [error, setError] = useState('');
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -38,6 +39,7 @@ export function ConversationModelSelect({
|
||||
invoke<GameCreatorAppConfigView>('read_game_creator_app_config'),
|
||||
]);
|
||||
setModels(catalog.models);
|
||||
setDefaultModelId(catalog.defaultModelId);
|
||||
const id = config.config.selectedModelId || catalog.defaultModelId;
|
||||
setSelected(id);
|
||||
const available = catalog.models.some((model) => model.id === id);
|
||||
@@ -164,7 +166,12 @@ export function ConversationModelSelect({
|
||||
void select(model.id);
|
||||
}}
|
||||
>
|
||||
<span>{model.displayName}</span>
|
||||
<span className="conversation-model-menu-option-main">
|
||||
<span>{model.displayName}</span>
|
||||
{model.id === defaultModelId ? (
|
||||
<em className="conversation-model-menu-default">默认</em>
|
||||
) : null}
|
||||
</span>
|
||||
{model.id === selected ? (
|
||||
<Check size={13} aria-hidden="true" />
|
||||
) : null}
|
||||
|
||||
@@ -8482,6 +8482,24 @@ iframe.preview-frame {
|
||||
color: var(--platform-text-strong, #111827);
|
||||
outline: none;
|
||||
}
|
||||
.conversation-model-menu-option-main {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.conversation-model-menu-default {
|
||||
flex: 0 0 auto;
|
||||
padding: 0 5px;
|
||||
border: 1px solid var(--platform-line-soft, #e2cbb8);
|
||||
border-radius: 5px;
|
||||
background: var(--platform-button-secondary-fill, rgba(255, 253, 250, 0.78));
|
||||
color: var(--platform-text-soft, #988476);
|
||||
font-size: 10px;
|
||||
font-style: normal;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.conversation-model-menu-loading {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react';
|
||||
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
||||
|
||||
@@ -114,3 +115,15 @@ test('closes the menu on Escape', async () => {
|
||||
expect(screen.queryByRole('option', { name: '快速' })).toBeNull(),
|
||||
);
|
||||
});
|
||||
|
||||
test('marks the default model in the menu', async () => {
|
||||
const onReady = vi.fn();
|
||||
render(<ConversationModelSelect disabled={false} onReady={onReady} />);
|
||||
await screen.findByRole('button', { name: '对话模型' });
|
||||
fireEvent.click(screen.getByRole('button', { name: '对话模型' }));
|
||||
|
||||
const qualityOption = screen.getByRole('option', { name: /高质量/ });
|
||||
expect(within(qualityOption).getByText('默认')).not.toBeNull();
|
||||
const fastOption = screen.getByRole('option', { name: '快速' });
|
||||
expect(within(fastOption).queryByText('默认')).toBeNull();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user