π OpenHands: AI-Driven Development
fix(automations): make the delete confirmation a modal dialog that closes on Escape (#18011)
Engel Nyst0eaf645c48a5
diff --git a/__tests__/routes/automation-detail.test.tsx b/__tests__/routes/automation-detail.test.tsxindex 420f40b961..8e1be9d6dd 100644--- a/__tests__/routes/automation-detail.test.tsx+++ b/__tests__/routes/automation-detail.test.tsx@@ -126,6 +126,7 @@ beforeEach(() => {completed_at: null,});+ vi.mocked(AutomationService.deleteAutomation).mockReset();vi.mocked(AutomationService.getAutomation).mockReset();vi.mocked(AutomationService.getAutomation).mockResolvedValue(automation);vi.mocked(AutomationService.getAutomationRuns).mockReset();@@ -190,6 +191,32 @@ describe("AutomationDetail β Edit in the kebab menu", () => {});});+describe("AutomationDetail β delete confirmation", () => {+ it("opens as a named modal dialog with focus inside, and Escape cancels without deleting", async () => {+ // Arrange β open the confirmation from the header kebab.+ const user = userEvent.setup();+ renderDetail();+ await user.click(+ await screen.findByLabelText(I18nKey.AUTOMATIONS$ACTIONS_MENU),+ );+ await user.click(+ screen.getByRole("button", { name: I18nKey.AUTOMATIONS$DELETE }),+ );+ const dialog = await screen.findByRole("dialog", {+ name: I18nKey.AUTOMATIONS$DELETE_CONFIRM_TITLE,+ });+ expect(dialog).toHaveAttribute("aria-modal", "true");+ expect(dialog).toContainElement(document.activeElement as HTMLElement);++ // Act+ await user.keyboard("{Escape}");++ // Assert β same behavior as on the dashboard: closed, nothing deleted.+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ expect(AutomationService.deleteAutomation).not.toHaveBeenCalled();+ });+});+describe("AutomationDetail β not-found handling", () => {it("renders the not-found state when the lookup rejects with an HttpError 404", async () => {// Arrange β cloud transport 404s surface as the shared client's HttpError.diff --git a/__tests__/routes/automations-list.test.tsx b/__tests__/routes/automations-list.test.tsxindex 3c6e7048e4..469a36d07f 100644--- a/__tests__/routes/automations-list.test.tsx+++ b/__tests__/routes/automations-list.test.tsx@@ -131,6 +131,8 @@ beforeEach(() => {vi.mocked(AutomationService.getAutomations).mockResolvedValue(listResponse);vi.mocked(AutomationService.updateAutomation).mockReset();vi.mocked(AutomationService.dispatchAutomation).mockReset();+ vi.mocked(AutomationService.deleteAutomation).mockReset();+ vi.mocked(AutomationService.deleteAutomation).mockResolvedValue(undefined);vi.mocked(ProfilesService.listProfiles).mockReset();vi.mocked(ProfilesService.listProfiles).mockResolvedValue({profiles: [],@@ -202,6 +204,57 @@ describe("AutomationsList β Edit from the row kebab", () => {});});+describe("AutomationsList β delete confirmation", () => {+ async function openDeleteConfirmation() {+ const user = userEvent.setup();+ renderList();+ await screen.findByText(automation.name);+ await user.click(screen.getByLabelText(I18nKey.AUTOMATIONS$ACTIONS_MENU));+ await user.click(+ screen.getByRole("button", { name: I18nKey.AUTOMATIONS$DELETE }),+ );+ const dialog = await screen.findByRole("dialog", {+ name: I18nKey.AUTOMATIONS$DELETE_CONFIRM_TITLE,+ });+ return { user, dialog };+ }++ it("opens as a named modal dialog with focus inside, and Escape cancels without deleting", async () => {+ // Arrange β open the confirmation from the row kebab.+ const { user, dialog } = await openDeleteConfirmation();++ // Assert β exposed as a modal dialog that keyboard users land in.+ expect(dialog).toHaveAttribute("aria-modal", "true");+ expect(dialog).toContainElement(document.activeElement as HTMLElement);++ // Act β dismiss with the keyboard.+ await user.keyboard("{Escape}");++ // Assert β the dialog is gone and nothing was deleted.+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ expect(AutomationService.deleteAutomation).not.toHaveBeenCalled();+ expect(screen.getByText(automation.name)).toBeInTheDocument();+ });++ it("deletes the automation when Delete is confirmed", async () => {+ // Arrange+ const { user, dialog } = await openDeleteConfirmation();++ // Act+ await user.click(+ within(dialog).getByRole("button", { name: I18nKey.AUTOMATIONS$DELETE }),+ );++ // Assert+ await waitFor(() => {+ expect(AutomationService.deleteAutomation).toHaveBeenCalledWith(+ automation.id,+ );+ });+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ });+});+describe("AutomationsList β Git Sync entry point follows manage_automations", () => {it("shows the Git Sync button to an org admin on a cloud backend", async () => {// Git sync is org-level config, not a local-only feature: an admin of thediff --git a/src/components/features/automations/delete-confirmation-modal.tsx b/src/components/features/automations/delete-confirmation-modal.tsxindex 9345ba3866..ca72649c0a 100644--- a/src/components/features/automations/delete-confirmation-modal.tsx+++ b/src/components/features/automations/delete-confirmation-modal.tsx@@ -1,7 +1,14 @@+import React from "react";import { useTranslation } from "react-i18next";import { I18nKey } from "#/i18n/declaration";import XMarkIcon from "#/icons/x-mark.svg?react";+import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";+import {+ MODAL_MAX_WIDTH_VIEWPORT,+ modalWidthClassName,+} from "#/components/shared/modals/modal-body";import { modalTitleLgMediumClassName } from "#/utils/modal-classes";+import { cn } from "#/utils/utils";interface DeleteConfirmationModalProps {automationName: string;@@ -17,20 +24,29 @@ export function DeleteConfirmationModal({onCancel,}: DeleteConfirmationModalProps) {const { t } = useTranslation("openhands");+ const cancelButtonRef = React.useRef<HTMLButtonElement>(null);++ // Move keyboard focus into the dialog when it opens, onto the+ // non-destructive choice, so Enter or Space cannot delete by accident.+ React.useEffect(() => {+ if (isOpen) cancelButtonRef.current?.focus();+ }, [isOpen]);if (!isOpen) return null;+ const title = t(I18nKey.AUTOMATIONS$DELETE_CONFIRM_TITLE);++ // ModalBackdrop exposes the named `role="dialog"` with `aria-modal` and+ // closes on Escape or a backdrop click.return (- <div className="fixed inset-0 z-50 flex items-center justify-center">+ <ModalBackdrop onClose={onCancel} aria-label={title}><div- className="absolute inset-0 bg-black/60"- onClick={onCancel}- onKeyDown={(e) => {- if (e.key === "Escape") onCancel();- }}- role="presentation"- />- <div className="relative w-full max-w-sm rounded-xl border border-border bg-surface p-6">+ className={cn(+ "relative rounded-xl border border-border bg-surface p-6",+ modalWidthClassName("sm"),+ MODAL_MAX_WIDTH_VIEWPORT,+ )}+ ><buttontype="button"onClick={onCancel}@@ -40,9 +56,7 @@ export function DeleteConfirmationModal({<XMarkIcon className="size-5" /></button>- <h2 className={modalTitleLgMediumClassName}>- {t(I18nKey.AUTOMATIONS$DELETE_CONFIRM_TITLE)}- </h2>+ <h2 className={modalTitleLgMediumClassName}>{title}</h2><p className="mt-2 text-sm text-muted">{t(I18nKey.AUTOMATIONS$DELETE_CONFIRM_MESSAGE, {name: automationName,@@ -51,6 +65,7 @@ export function DeleteConfirmationModal({<div className="mt-6 flex justify-end gap-3"><button+ ref={cancelButtonRef}type="button"onClick={onCancel}className="rounded-lg border border-border px-4 py-2 text-sm text-contrast hover:bg-surface-raised"@@ -66,6 +81,6 @@ export function DeleteConfirmationModal({</button></div></div>- </div>+ </ModalBackdrop>);}