Add export case menu (#24997)
CI / AMD64 Build (push) Waiting to run
CI / AMD64 Smoke Test (push) Blocked by required conditions
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions

* 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
This commit is contained in:
Josh Hawkins
2026-11-17 08:57:33 -07:00
committed by GitHub
parent 640ae1058a
commit 97f2096534
5 changed files with 450 additions and 28 deletions
+286
View File
@@ -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,
+6 -1
View File
@@ -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",
+73 -1
View File
@@ -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({
<div>{cameraCount}</div>
</div>
</div>
<div className="absolute inset-x-2 bottom-2 z-20 text-white">
<div className="absolute bottom-2 right-3 z-40">
<DropdownMenu>
<DropdownMenuTrigger>
<BlurredIconButton
aria-label={t("tooltip.caseOptions")}
onClick={(e) => e.stopPropagation()}
>
<FiMoreVertical className="size-5" />
</BlurredIconButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" onClick={(e) => e.stopPropagation()}>
<DropdownMenuItem
className="cursor-pointer"
aria-label={t("tooltip.shareCase")}
onClick={() =>
shareOrCopy(
`${baseUrl}export?caseId=${exportCase.id}`,
exportCase.name,
)
}
>
{t("tooltip.shareCase")}
</DropdownMenuItem>
{(exports.length > 0 || hasPendingJobs) && (
<DropdownMenuItem
className="cursor-pointer"
aria-label={t("tooltip.downloadCase")}
disabled={!downloadReady}
asChild
>
<a
download
href={
downloadReady
? `${baseUrl}api/cases/${exportCase.id}/download`
: undefined
}
>
{t("tooltip.downloadCase")}
</a>
</DropdownMenuItem>
)}
{isAdmin && (
<DropdownMenuItem
className="cursor-pointer"
aria-label={t("tooltip.editCase")}
onClick={() => onEdit(exportCase)}
>
{t("tooltip.editCase")}
</DropdownMenuItem>
)}
{isAdmin && (
<DropdownMenuItem
className="cursor-pointer"
aria-label={t("tooltip.deleteCase")}
onClick={() => onDelete(exportCase)}
>
{t("tooltip.deleteCase")}
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>
<div className="absolute bottom-2 left-2 right-12 z-20 text-white">
<div className="flex items-center justify-start gap-2">
<FaFolder />
<div className="truncate smart-capitalize">{exportCase.name}</div>
+73 -26
View File
@@ -5,6 +5,7 @@ import {
CaseCard,
ExportCard,
} from "@/components/card/ExportCard";
import { isCaseDownloadReady } from "@/utils/exportUtil";
import ActivityIndicator from "@/components/indicators/activity-indicator";
import {
AlertDialog,
@@ -172,6 +173,17 @@ function Exports() {
});
}, [activeExportJobs, exportFilter?.cameras]);
// Download readiness ignores the camera filter because the zip includes every camera
const pendingCaseIds = useMemo(
() =>
new Set(
activeExportJobs.flatMap((job) =>
job.export_case_id ? [job.export_case_id] : [],
),
),
[activeExportJobs],
);
const activeJobsByCase = useMemo<{ [caseId: string]: ExportJob[] }>(() => {
const grouped: { [caseId: string]: ExportJob[] } = {};
@@ -452,6 +464,28 @@ function Exports() {
[cases, selectedCaseId],
);
const selectedCaseExports = selectedCaseId
? exportsByCase[selectedCaseId] || []
: [];
const selectedCasePending =
selectedCaseId !== undefined && pendingCaseIds.has(selectedCaseId);
const selectedCaseHasContent =
selectedCaseExports.length > 0 || selectedCasePending;
const selectedCaseDownloadReady = isCaseDownloadReady(
selectedCaseExports,
selectedCasePending,
);
const downloadButtonContent = (
<>
<LuDownload className="text-secondary-foreground" />
{!isMobile && (
<div className="text-primary">
{t("button.download", { ns: "common" })}
</div>
)}
</>
);
const uncategorizedExports = useMemo(
() => exportsByCase["none"] || [],
[exportsByCase],
@@ -463,17 +497,11 @@ function Exports() {
exportCaseId?: string,
) => {
try {
let savedCaseId = exportCaseId;
if (exportCaseId) {
await axios.patch(`cases/${exportCaseId}`, payload);
} else {
const response = await axios.post("cases", payload);
savedCaseId = response.data.id;
}
if (savedCaseId) {
setSelectedCaseId(savedCaseId);
setSelectedCaseId(response.data.id);
}
mutate();
@@ -778,26 +806,31 @@ function Exports() {
onUpdateFilter={setExportFilter}
/>
<div className="flex items-center gap-1 md:gap-2">
{(exportsByCase[selectedCase.id]?.length ?? 0) > 0 && (
<Button
asChild
className="flex items-center gap-2 p-2"
size="sm"
aria-label={t("button.download", { ns: "common" })}
>
<a
download
href={`${baseUrl}api/cases/${selectedCase.id}/download`}
{selectedCaseHasContent &&
(selectedCaseDownloadReady ? (
<Button
asChild
className="flex items-center gap-2 p-2"
size="sm"
aria-label={t("button.download", { ns: "common" })}
>
<LuDownload className="text-secondary-foreground" />
{!isMobile && (
<div className="text-primary">
{t("button.download", { ns: "common" })}
</div>
)}
</a>
</Button>
)}
<a
download
href={`${baseUrl}api/cases/${selectedCase.id}/download`}
>
{downloadButtonContent}
</a>
</Button>
) : (
<Button
className="flex items-center gap-2 p-2"
size="sm"
aria-label={t("button.download", { ns: "common" })}
disabled
>
{downloadButtonContent}
</Button>
))}
{isAdmin && (
<>
<Button
@@ -880,11 +913,16 @@ function Exports() {
exports={exports}
exportsByCase={exportsByCase}
activeJobs={activeJobsByCase["none"] || []}
pendingCaseIds={pendingCaseIds}
selectedExports={selectedExports}
selectionMode={selectionMode}
isLoading={cases === undefined || rawExports === undefined}
onSelectExport={onSelectExport}
setSelectedCaseId={setSelectedCaseId}
onEditCase={(exportCase) =>
setCaseDialog({ mode: "edit", exportCase })
}
onDeleteCase={setCaseToDelete}
setSelected={setSelected}
renameClip={onHandleRename}
setDeleteClip={setDeleteClip}
@@ -902,11 +940,14 @@ type AllExportsViewProps = {
exports: Export[];
exportsByCase: { [caseId: string]: Export[] };
activeJobs: ExportJob[];
pendingCaseIds: Set<string>;
selectedExports: Export[];
selectionMode: boolean;
isLoading: boolean;
onSelectExport: (e: Export) => void;
setSelectedCaseId: (id: string) => void;
onEditCase: (exportCase: ExportCase) => void;
onDeleteCase: (exportCase: ExportCase) => void;
setSelected: (e: Export) => void;
renameClip: (id: string, update: string) => void;
setDeleteClip: (d: DeleteClipType | undefined) => void;
@@ -919,11 +960,14 @@ function AllExportsView({
exports,
exportsByCase,
activeJobs,
pendingCaseIds,
selectedExports,
selectionMode,
isLoading,
onSelectExport,
setSelectedCaseId,
onEditCase,
onDeleteCase,
setSelected,
renameClip,
setDeleteClip,
@@ -991,9 +1035,12 @@ function AllExportsView({
className=""
exportCase={item}
exports={exportsByCase[item.id] || []}
hasPendingJobs={pendingCaseIds.has(item.id)}
onSelect={() => {
setSelectedCaseId(item.id);
}}
onEdit={onEditCase}
onDelete={onDeleteCase}
/>
))}
</div>
+12
View File
@@ -0,0 +1,12 @@
import { Export } from "@/types/export";
export function isCaseDownloadReady(
exports: Export[],
hasPendingJobs: boolean,
): boolean {
return (
exports.length > 0 &&
!hasPendingJobs &&
!exports.some((exp) => exp.in_progress)
);
}