Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

refactor(control-ui): unify dialog cancellation outcomes

Josué603c8c9b5aa5
diff --git a/control-ui/components/ConfirmDialog/index.tsx b/control-ui/components/ConfirmDialog/index.tsx
index a39f57e49..2e4c314ad 100644
--- a/control-ui/components/ConfirmDialog/index.tsx
+++ b/control-ui/components/ConfirmDialog/index.tsx
@@ -21,7 +21,7 @@ function ConfirmDialog({ request, onResolve }: ConfirmDialogProps) {
cancelButtonRef.current?.focus()
function onKeyDown(event: KeyboardEvent) {
- if (event.key === 'Escape') onResolve('dismiss')
+ if (event.key === 'Escape') onResolve('cancel')
}
window.addEventListener('keydown', onKeyDown)
@@ -49,7 +49,7 @@ function ConfirmDialog({ request, onResolve }: ConfirmDialogProps) {
className="cu-modal-backdrop"
role="presentation"
onMouseDown={event => {
- if (event.target === event.currentTarget) onResolve('dismiss')
+ if (event.target === event.currentTarget) onResolve('cancel')
}}
>
<section
diff --git a/control-ui/components/ConfirmDialog/types.ts b/control-ui/components/ConfirmDialog/types.ts
index fe18c88b9..528588d99 100644
--- a/control-ui/components/ConfirmDialog/types.ts
+++ b/control-ui/components/ConfirmDialog/types.ts
@@ -1,7 +1,7 @@
import type { ReactNode } from 'react'
export type ConfirmDialogTone = 'default' | 'danger'
-export type ConfirmDialogOutcome = 'confirm' | 'cancel' | 'discard' | 'dismiss'
+export type ConfirmDialogOutcome = 'confirm' | 'cancel' | 'discard'
export interface ConfirmDialogOptions {
title?: string
diff --git a/control-ui/components/__tests__/ConfirmDialog.test.tsx b/control-ui/components/__tests__/ConfirmDialog.test.tsx
index f0cfbac40..766ef18a8 100644
--- a/control-ui/components/__tests__/ConfirmDialog.test.tsx
+++ b/control-ui/components/__tests__/ConfirmDialog.test.tsx
@@ -33,6 +33,20 @@ function DismissHarness() {
)
}
+function ChooseOutcomeHarness() {
+ const { choose, confirmDialog } = useConfirmDialog()
+ const [outcome, setOutcome] = useState('pending')
+ useEffect(() => {
+ void choose({ message: 'Save or discard?', title: 'Unsaved changes' }).then(setOutcome)
+ }, [choose])
+ return (
+ <>
+ <output>{outcome}</output>
+ {confirmDialog}
+ </>
+ )
+}
+
describe('ConfirmDialog accessibility', () => {
it('names the details block in the alertdialog accessible description', () => {
render(
@@ -70,4 +84,20 @@ describe('ConfirmDialog accessibility', () => {
await waitFor(() => expect(screen.getByText('dismissed')).toBeInTheDocument())
})
+
+ it('normalizes Escape to the same cancel outcome as the Cancel button', async () => {
+ render(<ChooseOutcomeHarness />)
+
+ fireEvent.keyDown(window, { key: 'Escape' })
+
+ await waitFor(() => expect(screen.getByText('cancel')).toBeInTheDocument())
+ })
+
+ it('normalizes backdrop dismissal to the same cancel outcome as the Cancel button', async () => {
+ render(<ChooseOutcomeHarness />)
+
+ fireEvent.mouseDown(document.querySelector('.cu-modal-backdrop') as HTMLElement)
+
+ await waitFor(() => expect(screen.getByText('cancel')).toBeInTheDocument())
+ })
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 7bca42aad..9ab51c9f9 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.599",
+ "version": "0.1.600",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.599",
+ "version": "0.1.600",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index be007cef7..50e4b134b 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.599",
+ "version": "0.1.600",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",