🔇 fix: Mute the Create Assistant Empty State in the Assistant Picker (#16338)

* fix: mute the Create Assistant empty state in the assistant picker

AssistantSelect passed its "Create Assistant" label as the dropdown value,
so it rendered in the primary value tone. Pass it as the placeholder with an
empty value instead, which SelectDropDown already renders in
text-text-secondary. SelectDropDown no longer checkmarks an option whose
value is empty when nothing is selected, so the loading row stays unmarked.

* test: reach the assistant builder through the mobile control panel
This commit is contained in:
Marco Beretta 2026-09-25 01:17:59 +02:00 • committed by GitHub
parent 3fa4cf1925
commit ea2b5f756d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 155 additions and 2 deletions

View file

@ -244,7 +244,8 @@ export default function AssistantSelect({
const createAssistant = localize('com_ui_create_assistant');
return (
<SelectDropDown
value={!value ? createAssistant : value}
value={value || null}
placeholder={createAssistant}
setValue={createDropdownSetter(onSelect)}
availableValues={
query.data ?? [

View file

@ -0,0 +1,99 @@
import { expect, test } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import { getAccessToken, requestJson } from '../helpers';
import { probeStyle } from './style.helpers';
import { openSidebar } from './sidebar';
/**
* The Assistant Builder's picker shows "Create Assistant" until an assistant is
* chosen. That label is an empty state, not a value, so it takes the muted tone
* `SelectDropDown` gives its placeholder, while a chosen assistant reads as the
* primary value. Both expected colours are resolved from the app's stylesheet,
* so the assertions hold in light and dark mode alike.
*/
type CreatedAssistant = { id: string };
const ASSISTANT_NAME = 'E2E muted picker assistant';
async function openBuilder(page: Page): Promise<Locator> {
await page.goto('/c/new?endpoint=assistants&model=gpt-4o-mini', { timeout: 10000 });
await openSidebar(page);
/** The mobile drawer opens on chat history; its panels are items of the Control Panel menu. */
const controlPanel = page.getByRole('button', { name: 'Control Panel' });
if (await controlPanel.isVisible()) {
await controlPanel.click();
await page.getByRole('menuitemcheckbox', { name: 'Assistant Builder' }).click();
} else {
await page.getByRole('button', { name: 'Assistant Builder' }).first().click();
}
const picker = page.getByTestId('select-dropdown-button').first();
await expect(picker).toBeVisible();
return picker;
}
async function colorOf(locator: Locator): Promise<string> {
return locator.evaluate((element) => getComputedStyle(element).color);
}
async function createAssistant(page: Page): Promise<CreatedAssistant> {
await page.goto('/c/new', { timeout: 10000 });
const token = await getAccessToken(page);
return requestJson<CreatedAssistant>(page, {
path: '/api/assistants/v2',
token,
method: 'POST',
body: { endpoint: 'assistants', model: 'gpt-4o-mini', name: ASSISTANT_NAME },
});
}
async function deleteAssistant(page: Page, assistantId: string) {
const token = await getAccessToken(page);
await requestJson(page, {
path: `/api/assistants/v2/${encodeURIComponent(assistantId)}?endpoint=assistants&model=gpt-4o-mini`,
token,
method: 'DELETE',
body: { endpoint: 'assistants' },
});
}
test.describe('assistant picker empty state', () => {
test('the Create Assistant label is muted until an assistant is chosen @scenario:assistant-select-empty-muted', async ({
page,
}) => {
test.setTimeout(60000);
const assistant = await createAssistant(page);
try {
const picker = await openBuilder(page);
const secondary = await probeStyle(page, 'text-text-secondary', 'color');
const primary = await probeStyle(page, 'text-text-primary', 'color');
expect(secondary).not.toBe(primary);
const chosen = picker.getByText(ASSISTANT_NAME, { exact: true });
await expect(chosen).toBeVisible();
expect(await colorOf(chosen)).toBe(primary);
await picker.click();
const listbox = page.getByRole('listbox');
await expect(listbox).toBeVisible();
const option = listbox.getByRole('option', { name: ASSISTANT_NAME });
await expect(option.locator('svg')).toHaveCount(1);
await listbox.getByRole('option', { name: 'Create Assistant' }).click();
const emptyLabel = picker.getByText('Create Assistant', { exact: true });
await expect(emptyLabel).toBeVisible();
await expect(picker.getByText(ASSISTANT_NAME, { exact: true })).toHaveCount(0);
expect(await colorOf(emptyLabel)).toBe(secondary);
await picker.focus();
await page.keyboard.press('Enter');
await expect(listbox).toBeVisible();
await expect(option.locator('svg')).toHaveCount(0);
await page.keyboard.press('Escape');
await expect(listbox).toBeHidden();
} finally {
await deleteAssistant(page, assistant.id);
}
});
});

View file

@ -256,7 +256,7 @@ function SelectDropDown({
)}
{currentLabel}
</span>
{currentValue === activeValue && (
{value != null && currentValue === activeValue && (
<span
className={cn(
'text-text-primary absolute inset-y-0 flex items-center',

View file

@ -0,0 +1,53 @@
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import SelectDropDown from '../SelectDropDown';
const OPTIONS = [
{ label: 'Loading...', value: '' },
{ label: 'Second', value: 'second' },
];
async function openList() {
await userEvent.setup().click(screen.getByTestId('select-dropdown-button'));
}
describe('SelectDropDown', () => {
it('renders the placeholder in the muted tone when no value is chosen', () => {
render(
<SelectDropDown
value={null}
setValue={jest.fn()}
availableValues={OPTIONS}
placeholder="Create Assistant"
showLabel={false}
emptyTitle={true}
/>,
);
expect(screen.getByText('Create Assistant')).toHaveClass('text-text-secondary');
});
it('does not mark an empty-valued option as selected when no value is chosen', async () => {
render(
<SelectDropDown
value={null}
setValue={jest.fn()}
availableValues={OPTIONS}
placeholder="Create Assistant"
/>,
);
await openList();
const empty = await screen.findByRole('option', { name: 'Loading...' });
expect(empty.querySelector('svg')).toBeNull();
});
it('marks the chosen option as selected', async () => {
render(<SelectDropDown value={OPTIONS[1]} setValue={jest.fn()} availableValues={OPTIONS} />);
await openList();
const chosen = await screen.findByRole('option', { name: 'Second' });
expect(chosen.querySelector('svg')).not.toBeNull();
expect(screen.getByRole('option', { name: 'Loading...' }).querySelector('svg')).toBeNull();
});
});