#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Confirm before deleting a policy from the detail drawer (#7854)
Anthony Stirling3a90da0a55e3
diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex cdcc26ad39..6eea40aec6 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -8972,6 +8972,13 @@ cancel = "Cancel"confirm = "Clear history"title = "Clear processed history?"+[portal.policies.detail.delete]+bodyActive = "\"{{name}}\" is active and enforcing on your documents. Deleting it stops that immediately and cannot be undone. Pause it instead if you only want it to stop running."+bodyPaused = "\"{{name}}\" will be removed for everyone. This cannot be undone."+cancel = "Cancel"+confirm = "Delete"+title = "Delete this pipeline?"+[portal.policies.detail.emptyActivity]description = "Documents will appear here once this pipeline runs."title = "No activity yet"diff --git a/frontend/editor/src/portal/components/policies/PolicyDetailPanel.test.tsx b/frontend/editor/src/portal/components/policies/PolicyDetailPanel.test.tsxnew file mode 100644index 0000000000..6c696f4c15--- /dev/null+++ b/frontend/editor/src/portal/components/policies/PolicyDetailPanel.test.tsx@@ -0,0 +1,69 @@+import { describe, expect, it, vi } from "vitest";+import {+ fireEvent,+ render as baseRender,+ screen,+} from "@testing-library/react";+import { PortalTestProviders } from "@portal/test/TestQueryProvider";+import { decorateForStory } from "@portal/components/policies/storyFixtures";+import { PolicyDetailPanel } from "@portal/components/policies/PolicyDetailPanel";++const render = (ui: Parameters<typeof baseRender>[0]) =>+ baseRender(ui, { wrapper: PortalTestProviders });++vi.mock("react-i18next", () => ({+ useTranslation: () => ({+ t: (key: string) => key,+ i18n: { changeLanguage: vi.fn() },+ }),+ initReactI18next: { type: "3rdParty", init: vi.fn() },+}));++function renderPanel() {+ const base = decorateForStory("security");+ const onDelete = vi.fn();+ render(+ <PolicyDetailPanel+ policy={{+ ...base,+ state: { ...base.state, isDefault: false, name: "QA Security Export" },+ }}+ onClose={vi.fn()}+ onEdit={vi.fn()}+ onTogglePause={vi.fn()}+ onDelete={onDelete}+ />,+ );+ return { onDelete };+}++describe("PolicyDetailPanel", () => {+ it("asks before deleting an active policy instead of removing it on one click", () => {+ const { onDelete } = renderPanel();++ fireEvent.click(screen.getByText("portal.policies.detail.actions.delete"));++ expect(onDelete).not.toHaveBeenCalled();+ expect(+ screen.getByText("portal.policies.detail.delete.title"),+ ).toBeInTheDocument();+ });++ it("deletes once the confirmation is accepted", () => {+ const { onDelete } = renderPanel();++ fireEvent.click(screen.getByText("portal.policies.detail.actions.delete"));+ fireEvent.click(screen.getByText("portal.policies.detail.delete.confirm"));++ expect(onDelete).toHaveBeenCalledTimes(1);+ });++ it("leaves the policy alone when the confirmation is dismissed", () => {+ const { onDelete } = renderPanel();++ fireEvent.click(screen.getByText("portal.policies.detail.actions.delete"));+ fireEvent.click(screen.getByText("portal.policies.detail.delete.cancel"));++ expect(onDelete).not.toHaveBeenCalled();+ });+});diff --git a/frontend/editor/src/portal/components/policies/PolicyDetailPanel.tsx b/frontend/editor/src/portal/components/policies/PolicyDetailPanel.tsxindex 36177a9f55..70da22aef1 100644--- a/frontend/editor/src/portal/components/policies/PolicyDetailPanel.tsx+++ b/frontend/editor/src/portal/components/policies/PolicyDetailPanel.tsx@@ -113,6 +113,7 @@ export function PolicyDetailPanel({}: PolicyDetailPanelProps) {const { t } = useTranslation();const [confirmingClear, setConfirmingClear] = useState(false);+ const [confirmingDelete, setConfirmingDelete] = useState(false);if (!policy) return null;const { category, config, state, steps, stats, activity } = policy;const isPaused = state.status === "paused";@@ -155,7 +156,7 @@ export function PolicyDetailPanel({variant="tertiary"accent="danger"size="sm"- onClick={onDelete}+ onClick={() => setConfirmingDelete(true)}disabled={busy}style={{ marginRight: "auto" }}>@@ -353,6 +354,43 @@ export function PolicyDetailPanel({>{t("portal.policies.detail.clearHistory.body")}</Modal>+ <Modal+ open={confirmingDelete}+ onClose={() => setConfirmingDelete(false)}+ width="sm"+ title={t("portal.policies.detail.delete.title")}+ footer={+ <div className="portal-policies__detail-foot">+ <Button+ variant="secondary"+ size="sm"+ onClick={() => setConfirmingDelete(false)}+ disabled={busy}+ >+ {t("portal.policies.detail.delete.cancel")}+ </Button>+ <Button+ variant="primary"+ accent="danger"+ size="sm"+ disabled={busy}+ onClick={() => {+ setConfirmingDelete(false);+ onDelete();+ }}+ >+ {t("portal.policies.detail.delete.confirm")}+ </Button>+ </div>+ }+ >+ {t(+ isPaused+ ? "portal.policies.detail.delete.bodyPaused"+ : "portal.policies.detail.delete.bodyActive",+ { name: state.name?.trim() || t(category.label) },+ )}+ </Modal></>);}