fix(assistant): taking a proposal needs place rights, and a card's choices wait while a change runs

Plan this checks place_edit like the tour routes, the include choices of a
run or group stay disabled while the chat applies a change, and a follow-up
can say when it applies, so Confirm the pending bookings shows only when the
card holds a pending booking of this trip.
This commit is contained in:
Maurice
2026-10-22 22:46:35 +00:00
parent cf8cf9058d
commit 3eded5f5be
13 changed files with 195 additions and 39 deletions
@@ -1,10 +1,11 @@
/**
* FE-AI-PACKRUN-001 to FE-AI-PACKRUN-003
* FE-AI-PACKRUN-001 to FE-AI-PACKRUN-004
*
* A run of single-row packing changes reads as one checklist inside the
* change card: each category's head once, a row per change with its own
* include choice and the tile of what it does, and the facts of the change
* with old values struck through. A change switched off fades.
* with old values struck through. A change switched off fades, and the
* choices wait while the chat runs.
*/
import type { PackingCardItem, PackingListCard } from '@trek/shared';
import type { ReactNode } from 'react';
@@ -74,7 +75,7 @@ function inView(ui: ReactNode, view: Partial<AssistantView> = {}) {
describe('PackingChangeRun', () => {
it("FE-AI-PACKRUN-001: each category's head shows once, a row per change with what it does", () => {
inView(<PackingChangeRun items={ITEMS} excluded={new Set()} onToggle={vi.fn()} />);
inView(<PackingChangeRun items={ITEMS} excluded={new Set()} disabled={false} onToggle={vi.fn()} />);
expect(screen.getAllByText('Toiletries')).toHaveLength(1);
expect(screen.getAllByText('Clothes')).toHaveLength(1);
expect(screen.getAllByText('New')).toHaveLength(2);
@@ -87,7 +88,7 @@ describe('PackingChangeRun', () => {
it('FE-AI-PACKRUN-002: every row has its own include choice, and a switched-off one fades', () => {
const onToggle = vi.fn();
inView(<PackingChangeRun items={ITEMS} excluded={new Set(['c5'])} onToggle={onToggle} />);
inView(<PackingChangeRun items={ITEMS} excluded={new Set(['c5'])} disabled={false} onToggle={onToggle} />);
const choices = screen.getAllByRole('button', { name: 'Include this change' });
expect(choices).toHaveLength(5);
expect(choices[4]).toHaveAttribute('aria-pressed', 'false');
@@ -98,11 +99,27 @@ describe('PackingChangeRun', () => {
it('FE-AI-PACKRUN-003: on the phone the choice gets a larger hit area; a change without a card is left out', () => {
const plain: ChangeItem = { toolCallId: 'c9', preview: null, applied: null, state: 'pending', card: null };
inView(<PackingChangeRun items={[...ITEMS.slice(0, 2), plain]} excluded={new Set()} onToggle={vi.fn()} />, {
variant: 'fullscreen',
});
inView(
<PackingChangeRun
items={[...ITEMS.slice(0, 2), plain]}
excluded={new Set()}
disabled={false}
onToggle={vi.fn()}
/>,
{ variant: 'fullscreen' }
);
const choices = screen.getAllByRole('button', { name: 'Include this change' });
expect(choices).toHaveLength(2);
expect(choices[0]).toHaveClass('h-8', 'w-8');
});
it('FE-AI-PACKRUN-004: while the chat runs every include choice waits', () => {
const onToggle = vi.fn();
inView(<PackingChangeRun items={ITEMS} excluded={new Set()} disabled onToggle={onToggle} />);
const choices = screen.getAllByRole('button', { name: 'Include this change' });
expect(choices).toHaveLength(5);
for (const choice of choices) expect(choice).toBeDisabled();
fireEvent.click(choices[0] as HTMLElement);
expect(onToggle).not.toHaveBeenCalled();
});
});
@@ -188,7 +188,7 @@ describe('TodoListCard', () => {
pending('c1', one(task(null, 'Book the train', { change: 'add' }))),
pending('c2', one(task(22, 'Travel insurance', { change: 'check', checked: true }))),
];
inView(<TodoChangeRun items={items} excluded={new Set()} onToggle={onToggle} />);
inView(<TodoChangeRun items={items} excluded={new Set()} disabled={false} onToggle={onToggle} />);
expect(screen.getAllByText('Bookings')).toHaveLength(1);
expect(screen.getByText('New')).toBeInTheDocument();
expect(screen.getByText('Done')).toBeInTheDocument();
@@ -138,8 +138,18 @@ export interface RunEntry {
facts: ReactNode;
}
/** A change in a run: the round include choice, the tile of what it does, and the row. */
function RunRow({ entry, excluded, onToggle }: { entry: RunEntry; excluded: boolean; onToggle: (id: string) => void }) {
/** A change in a run: the round include choice (waiting while the chat runs), the tile of what it does, and the row. */
function RunRow({
entry,
excluded,
disabled,
onToggle,
}: {
entry: RunEntry;
excluded: boolean;
disabled: boolean;
onToggle: (id: string) => void;
}) {
const { t } = useTranslation();
const { variant } = useAssistantView();
const glyph = ROW_GLYPH[entry.change];
@@ -152,9 +162,10 @@ function RunRow({ entry, excluded, onToggle }: { entry: RunEntry; excluded: bool
<button
type="button"
onClick={() => onToggle(entry.item.toolCallId)}
disabled={disabled}
aria-pressed={!excluded}
aria-label={t('assistant.change.include')}
className={`grid flex-none place-items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-accent ${
className={`grid flex-none place-items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50 ${
variant === 'fullscreen' ? 'h-8 w-8' : 'h-[18px] w-[18px]'
}`}
>
@@ -179,6 +190,8 @@ function RunRow({ entry, excluded, onToggle }: { entry: RunEntry; excluded: bool
export interface RunProps {
items: readonly ChangeItem[];
excluded: ReadonlySet<string>;
/** The include choices wait while the chat runs. */
disabled: boolean;
onToggle(id: string): void;
}
@@ -191,6 +204,7 @@ export interface RunProps {
export function ChecklistRun({
items,
excluded,
disabled,
onToggle,
entryOf,
}: RunProps & { entryOf: (item: ChangeItem) => RunEntry | null }) {
@@ -200,7 +214,12 @@ export function ChecklistRun({
{entries.map((entry, i) => (
<div key={entry.item.toolCallId}>
{entries[i - 1]?.headKey !== entry.headKey && entry.head}
<RunRow entry={entry} excluded={excluded.has(entry.item.toolCallId)} onToggle={onToggle} />
<RunRow
entry={entry}
excluded={excluded.has(entry.item.toolCallId)}
disabled={disabled}
onToggle={onToggle}
/>
</div>
))}
</div>