From 97f20965343e26e49869ddde8acbaaf51c445a83 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Tue, 17 Nov 2026 09:57:33 -0600 Subject: [PATCH] Add export case menu (#24997) * add kebab menu to export cases * disable download while case exports are still encoding * stop case menu clicks from opening the case * check case download readiness against jobs on every camera --- web/e2e/specs/export.spec.ts | 286 +++++++++++++++++++++++ web/public/locales/en/views/exports.json | 7 +- web/src/components/card/ExportCard.tsx | 74 +++++- web/src/pages/Exports.tsx | 99 +++++--- web/src/utils/exportUtil.ts | 12 + 5 files changed, 450 insertions(+), 28 deletions(-) create mode 100644 web/src/utils/exportUtil.ts diff --git a/web/e2e/specs/export.spec.ts b/web/e2e/specs/export.spec.ts index 73eb2118df..2c99795dd2 100644 --- a/web/e2e/specs/export.spec.ts +++ b/web/e2e/specs/export.spec.ts @@ -159,6 +159,292 @@ test.describe("Export Page - Overview @high", () => { }); }); +test.describe("Export Page - Case Card Menu @high", () => { + async function openCaseMenu(frigateApp: FrigateApp) { + await frigateApp.goto("/export"); + await frigateApp.page + .getByRole("button", { name: "Case options" }) + .first() + .click(); + const menu = frigateApp.page.getByRole("menu"); + await expect(menu).toBeVisible(); + return menu; + } + + test("menu offers share, download, edit, and delete", async ({ + frigateApp, + }) => { + const menu = await openCaseMenu(frigateApp); + + await expect( + menu.getByRole("menuitem", { name: "Share case" }), + ).toBeVisible(); + await expect( + menu.getByRole("menuitem", { name: "Download case" }), + ).toHaveAttribute("href", /api\/cases\/case-001\/download$/); + await expect( + menu.getByRole("menuitem", { name: "Edit case" }), + ).toBeVisible(); + await expect( + menu.getByRole("menuitem", { name: "Delete case" }), + ).toBeVisible(); + }); + + test("edit opens a prefilled dialog without opening the case", async ({ + frigateApp, + }) => { + const menu = await openCaseMenu(frigateApp); + await menu.getByRole("menuitem", { name: "Edit case" }).click(); + + const dialog = frigateApp.page + .getByRole("dialog") + .filter({ hasText: "Edit Case" }); + await expect(dialog).toBeVisible(); + await expect(dialog.locator("input")).toHaveValue( + "Package Theft Investigation", + ); + await expect( + frigateApp.page.getByRole("heading", { + name: "Package Theft Investigation", + }), + ).toBeHidden(); + }); + + test("delete opens the confirmation dialog", async ({ frigateApp }) => { + const menu = await openCaseMenu(frigateApp); + await menu.getByRole("menuitem", { name: "Delete case" }).click(); + + const dialog = frigateApp.page + .getByRole("alertdialog") + .filter({ hasText: "Delete Case" }); + await expect(dialog).toBeVisible(); + await expect(dialog.getByText(/Package Theft Investigation/)).toBeVisible(); + }); + + test("share sends a link that opens the case", async ({ frigateApp }) => { + await frigateApp.page.addInitScript(() => { + Object.defineProperty(navigator, "share", { + configurable: true, + value: (data: ShareData) => { + (window as unknown as { sharedUrl?: string }).sharedUrl = data.url; + return Promise.resolve(); + }, + }); + }); + + const menu = await openCaseMenu(frigateApp); + await menu.getByRole("menuitem", { name: "Share case" }).click(); + + const sharedUrl = await frigateApp.page.evaluate( + () => (window as unknown as { sharedUrl?: string }).sharedUrl, + ); + expect(sharedUrl).toMatch(/\/export\?caseId=case-001$/); + + await frigateApp.goto("/export?caseId=case-001"); + await expect( + frigateApp.page.getByRole("heading", { + name: "Package Theft Investigation", + }), + ).toBeVisible(); + }); + + test("deleting via the card menu leaves body interactive", async ({ + frigateApp, + }) => { + const initialCases = [ + { + id: "case-001", + name: "Package Theft Investigation", + description: "", + created_at: 1775407931.3863528, + updated_at: 1775483531.3863528, + }, + ]; + let deleted = false; + + await frigateApp.page.route(/\/api\/cases(?:$|\?|\/)/, async (route) => { + const method = route.request().method(); + + if (method === "DELETE") { + deleted = true; + return route.fulfill({ json: { success: true } }); + } + + if (method === "GET") { + return route.fulfill({ json: deleted ? [] : initialCases }); + } + + return route.fallback(); + }); + + const menu = await openCaseMenu(frigateApp); + await menu.getByRole("menuitem", { name: "Delete case" }).click(); + + const dialog = frigateApp.page.getByRole("alertdialog"); + await dialog.getByRole("button", { name: /^delete$/i }).click(); + + await expect(dialog).toBeHidden(); + await expect( + frigateApp.page.getByText("Package Theft Investigation", { exact: true }), + ).toBeHidden(); + await waitForBodyInteractive(frigateApp.page, 5_000); + await expectBodyInteractive(frigateApp.page); + }); + + test("download is disabled while a case export is still encoding", async ({ + frigateApp, + }) => { + await frigateApp.page.route("**/api/export**", (route) => + route.fulfill({ + json: [ + { + id: "export-done", + camera: "front_door", + name: "Finished", + date: 1775490731, + video_path: "/exports/export-done.mp4", + thumb_path: "/exports/export-done-thumb.jpg", + in_progress: false, + export_case_id: "case-001", + }, + { + id: "export-encoding", + camera: "backyard", + name: "Still Encoding", + date: 1775490732, + video_path: "/exports/export-encoding.mp4", + thumb_path: "", + in_progress: true, + export_case_id: "case-001", + }, + ], + }), + ); + + const menu = await openCaseMenu(frigateApp); + const download = menu.getByRole("menuitem", { name: "Download case" }); + await expect(download).toHaveAttribute("data-disabled", ""); + await expect(download).not.toHaveAttribute("href"); + + const box = await download.boundingBox(); + expect(box).not.toBeNull(); + await frigateApp.page.mouse.click( + box!.x + box!.width / 2, + box!.y + box!.height / 2, + ); + await expect( + frigateApp.page.getByRole("heading", { + name: "Package Theft Investigation", + }), + ).toBeHidden(); + + await frigateApp.page.keyboard.press("Escape"); + await frigateApp.goto("/export?caseId=case-001"); + await expect( + frigateApp.page.getByRole("button", { name: "Download" }), + ).toBeDisabled(); + }); + + test("download is disabled while a case export job is queued", async ({ + frigateApp, + }) => { + await frigateApp.page.route("**/api/jobs/export", (route) => + route.fulfill({ + json: [ + { + id: "job-queued", + job_type: "export", + status: "queued", + camera: "front_door", + name: "Queued Sample", + export_case_id: "case-001", + request_start_time: 1775407931, + request_end_time: 1775408531, + start_time: null, + end_time: null, + error_message: null, + results: null, + current_step: null, + progress_percent: 0, + }, + ], + }), + ); + + const menu = await openCaseMenu(frigateApp); + await expect( + menu.getByRole("menuitem", { name: "Download case" }), + ).toHaveAttribute("data-disabled", ""); + }); + + test("download stays disabled for a running job on a filtered-out camera", async ({ + frigateApp, + }) => { + await frigateApp.page.route("**/api/export**", (route) => + route.fulfill({ + json: [ + { + id: "export-front", + camera: "front_door", + name: "Front Finished", + date: 1775490731, + video_path: "/exports/export-front.mp4", + thumb_path: "", + in_progress: false, + export_case_id: "case-001", + }, + ], + }), + ); + await frigateApp.page.route("**/api/jobs/export", (route) => + route.fulfill({ + json: [ + { + id: "job-backyard", + job_type: "export", + status: "running", + camera: "backyard", + name: "Backyard Running", + export_case_id: "case-001", + request_start_time: 1775407931, + request_end_time: 1775408531, + start_time: 1775407932, + end_time: null, + error_message: null, + results: null, + current_step: "encoding", + progress_percent: 10, + }, + ], + }), + ); + + await frigateApp.goto("/export?cameras=front_door"); + await frigateApp.page + .getByRole("button", { name: "Case options" }) + .first() + .click(); + await expect( + frigateApp.page.getByRole("menuitem", { name: "Download case" }), + ).toHaveAttribute("data-disabled", ""); + }); + + test("viewers only see share and download", async ({ frigateApp }) => { + await frigateApp.installDefaults({ profile: viewerProfile() }); + const menu = await openCaseMenu(frigateApp); + + await expect( + menu.getByRole("menuitem", { name: "Share case" }), + ).toBeVisible(); + await expect(menu.getByRole("menuitem", { name: "Edit case" })).toHaveCount( + 0, + ); + await expect( + menu.getByRole("menuitem", { name: "Delete case" }), + ).toHaveCount(0); + }); +}); + test.describe("Export Page - Case Detail @high", () => { test("opening a case shows its detail view and associated export", async ({ frigateApp, diff --git a/web/public/locales/en/views/exports.json b/web/public/locales/en/views/exports.json index bb83ef79a4..dde5dcac76 100644 --- a/web/public/locales/en/views/exports.json +++ b/web/public/locales/en/views/exports.json @@ -21,7 +21,12 @@ "editName": "Edit name", "deleteExport": "Delete export", "assignToCase": "Add to case", - "removeFromCase": "Remove from case" + "removeFromCase": "Remove from case", + "caseOptions": "Case options", + "shareCase": "Share case", + "downloadCase": "Download case", + "editCase": "Edit case", + "deleteCase": "Delete case" }, "toolbar": { "newCase": "New Case", diff --git a/web/src/components/card/ExportCard.tsx b/web/src/components/card/ExportCard.tsx index cecca0dbfd..d791e89f72 100644 --- a/web/src/components/card/ExportCard.tsx +++ b/web/src/components/card/ExportCard.tsx @@ -18,6 +18,7 @@ import { DeleteClipType, Export, ExportCase, ExportJob } from "@/types/export"; import { baseUrl } from "@/api/baseUrl"; import { cn } from "@/lib/utils"; import { shareOrCopy } from "@/utils/browserUtil"; +import { isCaseDownloadReady } from "@/utils/exportUtil"; import { useTranslation } from "react-i18next"; import { ImageShadowOverlay } from "../overlay/ImageShadowOverlay"; import BlurredIconButton from "../button/BlurredIconButton"; @@ -40,15 +41,23 @@ type CaseCardProps = { className: string; exportCase: ExportCase; exports: Export[]; + hasPendingJobs: boolean; onSelect: () => void; + onEdit: (exportCase: ExportCase) => void; + onDelete: (exportCase: ExportCase) => void; }; export function CaseCard({ className, exportCase, exports, + hasPendingJobs, onSelect, + onEdit, + onDelete, }: CaseCardProps) { const { t } = useTranslation(["views/exports"]); + const isAdmin = useIsAdmin(); + const downloadReady = isCaseDownloadReady(exports, hasPendingJobs); const firstExport = useMemo( () => exports.find((exp) => exp.thumb_path && exp.thumb_path.length > 0), [exports], @@ -87,7 +96,70 @@ export function CaseCard({