Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/approve-once-direct-click.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@truefoundry/trueforge-ui': patch
---

Approve once now approves on click; the chevron beside it opens the menu for other approval options and Deny.
104 changes: 59 additions & 45 deletions packages/trueforge-ui/src/atoms/ToolApprovalBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,51 +122,65 @@ export function ToolApprovalBar({
)}
</div>
{!isDecided && !readOnly && !selectedDenyOption && (
<DropdownMenu
align="end"
trigger={
<Button
size="small"
variant={defaultApproval == null ? 'secondary' : optionVariant(defaultApproval)}
disabled={interactionsLocked || defaultApproval == null}
>
<Icon name="check" size="0.75rem" />
{defaultApproval?.label ?? 'Approve'}
<Icon name="chevron-down" className="size-3" />
</Button>
}
className="w-max min-w-[16.25rem]"
>
{approveOptions.map((option, index) => (
<DropdownMenuItem
key={option.id}
disabled={interactionsLocked}
onClick={() => onSelect(option.id)}
className="whitespace-nowrap"
>
<span className="w-3 shrink-0">{index === 0 ? <Icon name="check" size="0.75rem" /> : null}</span>
{option.label}
</DropdownMenuItem>
))}
{approveOptions.length > 0 && denyOptions.length > 0 ? <DropdownMenuSeparator /> : null}
{denyOptions.map(option => (
<DropdownMenuItem
key={option.id}
disabled={interactionsLocked}
onClick={() => {
if (option.requiresReason) {
onDenyOptionChange?.(option.id);
} else {
onSelect(option.id);
}
}}
className="whitespace-nowrap"
>
<span className="w-3 shrink-0" />
{option.label}
</DropdownMenuItem>
))}
</DropdownMenu>
<div className="inline-flex items-stretch">
<Button
size="small"
variant={defaultApproval == null ? 'secondary' : optionVariant(defaultApproval)}
disabled={interactionsLocked || defaultApproval == null}
className="rounded-r-none"
onClick={() => {
if (defaultApproval != null) onSelect(defaultApproval.id);
}}
>
<Icon name="check" size="0.75rem" />
{defaultApproval?.label ?? 'Approve'}
</Button>
<DropdownMenu
align="end"
trigger={
<Button
size="small"
variant={defaultApproval == null ? 'secondary' : optionVariant(defaultApproval)}
disabled={interactionsLocked || defaultApproval == null}
aria-label="More approval options"
className="rounded-l-none border-l border-l-current/30 px-1.5"
>
<Icon name="chevron-down" className="size-3" />
</Button>
}
className="w-max min-w-[16.25rem]"
>
{approveOptions.map((option, index) => (
<DropdownMenuItem
key={option.id}
disabled={interactionsLocked}
onClick={() => onSelect(option.id)}
className="whitespace-nowrap"
>
<span className="w-3 shrink-0">{index === 0 ? <Icon name="check" size="0.75rem" /> : null}</span>
{option.label}
</DropdownMenuItem>
))}
{approveOptions.length > 0 && denyOptions.length > 0 ? <DropdownMenuSeparator /> : null}
{denyOptions.map(option => (
<DropdownMenuItem
key={option.id}
disabled={interactionsLocked}
onClick={() => {
if (option.requiresReason) {
onDenyOptionChange?.(option.id);
} else {
onSelect(option.id);
}
}}
className="whitespace-nowrap"
>
<span className="w-3 shrink-0" />
{option.label}
</DropdownMenuItem>
))}
</DropdownMenu>
</div>
)}
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions packages/trueforge-ui/test/atoms/ToolApprovalBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ describe('ToolApprovalBar', () => {
);

fireEvent.click(screen.getByRole('button', { name: 'Allow once' }));
expect(screen.queryByRole('menu')).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'More approval options' }));
expect(screen.getByRole('menuitem', { name: 'Allow once' })).not.toHaveAttribute('aria-selected');
fireEvent.click(screen.getByRole('menuitem', { name: 'Allow once' }));
fireEvent.click(screen.getByRole('button', { name: 'Allow once' }));
fireEvent.click(screen.getByRole('button', { name: 'More approval options' }));
fireEvent.click(screen.getByRole('menuitem', { name: 'Reject' }));
expect(onSelect).toHaveBeenNthCalledWith(1, 'allow-once');
expect(onSelect).toHaveBeenNthCalledWith(2, 'reject');
expect(onSelect).toHaveBeenNthCalledWith(2, 'allow-once');
expect(onSelect).toHaveBeenNthCalledWith(3, 'reject');
});

it('drives the controlled denial-reason workflow and error state', () => {
Expand All @@ -49,7 +52,7 @@ describe('ToolApprovalBar', () => {
/>,
);

fireEvent.click(screen.getByRole('button', { name: 'Approve once' }));
fireEvent.click(screen.getByRole('button', { name: 'More approval options' }));
fireEvent.click(screen.getByRole('menuitem', { name: 'Deny' }));
expect(onDenyOptionChange).toHaveBeenCalledWith('deny-with-reason');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ vi.mock('@truefoundry/trueforge-assistant-ui-runtime', async importOriginal => {
});

function openApprovalMenu() {
fireEvent.click(screen.getByRole('button', { name: 'Approve once' }));
fireEvent.click(screen.getByRole('button', { name: 'More approval options' }));
}

function renderToolCallMessage(content: ThreadMessageLike['content'], overrides?: SlotOverrides) {
Expand Down
Loading