encode notice ids in notice action urls

Notice ids went into the URL raw, so a detector on a repeated device like openvino:GPU#2 had everything after the # dropped as a fragment. The acknowledge, mute, and unhide requests 404'd and the buttons did nothing. The hooks now encode the id.
This commit is contained in:
Josh Hawkins
2026-11-26 06:56:17 -06:00
parent 8eaae4b514
commit 8c773c2e2e
3 changed files with 33 additions and 23 deletions
+26 -18
View File
@@ -57,6 +57,14 @@ const EVENT_NOTICE = {
muted_at: null, muted_at: null,
}; };
// a repeated device gets a '#2' suffix, which a raw URL would cut off as a fragment
const SUFFIXED_NOTICE = {
...EVENT_NOTICE,
id: "detector_stuck:openvino:GPU#2",
scope: "openvino:GPU#2",
params: { detector: "openvino:GPU#2" },
};
test.describe("System — Health tab @medium", () => { test.describe("System — Health tab @medium", () => {
test("Health is the default tab and lists notices by severity", async ({ test("Health is the default tab and lists notices by severity", async ({
frigateApp, frigateApp,
@@ -95,19 +103,20 @@ test.describe("System — Health tab @medium", () => {
for (const action of ["acknowledge", "mute"] as const) { for (const action of ["acknowledge", "mute"] as const) {
test(`${action} posts and removes the row`, async ({ frigateApp }) => { test(`${action} posts and removes the row`, async ({ frigateApp }) => {
const path = `/api/notices/${encodeURIComponent(SUFFIXED_NOTICE.id)}/${action}`;
await frigateApp.installDefaults({ await frigateApp.installDefaults({
config: RESTREAMED, config: RESTREAMED,
stats: QUIET_STATS, stats: QUIET_STATS,
notices: [EVENT_NOTICE], notices: [SUFFIXED_NOTICE],
}); });
// the list shrinks after the POST so the refetch shows the row gone // the list shrinks after the POST so the refetch shows the row gone
let hidden = false; let hidden = false;
await frigateApp.page.route("**/api/notices", (route) => await frigateApp.page.route("**/api/notices", (route) =>
route.fulfill({ json: hidden ? [] : [EVENT_NOTICE] }), route.fulfill({ json: hidden ? [] : [SUFFIXED_NOTICE] }),
); );
await frigateApp.page.route( await frigateApp.page.route(
`**/api/notices/detector_stuck/${action}`, (url) => url.pathname.endsWith(path),
(route) => { (route) => {
hidden = true; hidden = true;
return route.fulfill({ json: { success: true } }); return route.fulfill({ json: { success: true } });
@@ -117,11 +126,10 @@ test.describe("System — Health tab @medium", () => {
await frigateApp.goto("/system#health"); await frigateApp.goto("/system#health");
const request = frigateApp.page.waitForRequest( const request = frigateApp.page.waitForRequest(
(req) => (req) =>
req.url().includes(`/api/notices/detector_stuck/${action}`) && new URL(req.url()).pathname.endsWith(path) && req.method() === "POST",
req.method() === "POST",
); );
await frigateApp.page await frigateApp.page
.getByTestId("health-problem-notice:detector_stuck") .getByTestId(`health-problem-notice:${SUFFIXED_NOTICE.id}`)
.getByRole("button", { .getByRole("button", {
name: action === "mute" ? "Mute" : "Acknowledge", name: action === "mute" ? "Mute" : "Acknowledge",
exact: true, exact: true,
@@ -264,8 +272,9 @@ test.describe("System — Health tab @medium", () => {
url.searchParams.get("include_hidden") === "true", url.searchParams.get("include_hidden") === "true",
(route) => route.fulfill({ json: [MUTED_NOTICE] }), (route) => route.fulfill({ json: [MUTED_NOTICE] }),
); );
const path = `/api/notices/${encodeURIComponent(MUTED_NOTICE.id)}/hidden`;
await frigateApp.page.route( await frigateApp.page.route(
"**/api/notices/model_download_failed:yolo/model.onnx/hidden", (url) => url.pathname.endsWith(path),
(route) => route.fulfill({ json: { success: true } }), (route) => route.fulfill({ json: { success: true } }),
); );
await frigateApp.goto("/system#health"); await frigateApp.goto("/system#health");
@@ -276,11 +285,7 @@ test.describe("System — Health tab @medium", () => {
const request = frigateApp.page.waitForRequest( const request = frigateApp.page.waitForRequest(
(req) => (req) =>
req new URL(req.url()).pathname.endsWith(path) && req.method() === "DELETE",
.url()
.endsWith(
"/api/notices/model_download_failed:yolo/model.onnx/hidden",
) && req.method() === "DELETE",
); );
await frigateApp.page await frigateApp.page
.getByTestId( .getByTestId(
@@ -1281,10 +1286,14 @@ test.describe("System — Health notices sources @medium", () => {
// the list gains the mute after the POST so the refetch hides the row // the list gains the mute after the POST so the refetch hides the row
let muted = false; let muted = false;
await frigateApp.page.route(`**/api/notices/${id}/mute`, (route) => { const path = `/api/notices/${encodeURIComponent(id)}/mute`;
muted = true; await frigateApp.page.route(
return route.fulfill({ json: { success: true } }); (url) => url.pathname.endsWith(path),
}); (route) => {
muted = true;
return route.fulfill({ json: { success: true } });
},
);
await frigateApp.page.route("**/api/notices/muted_checks", (route) => await frigateApp.page.route("**/api/notices/muted_checks", (route) =>
route.fulfill({ json: muted ? [{ id, muted_at: NOW }] : [] }), route.fulfill({ json: muted ? [{ id, muted_at: NOW }] : [] }),
); );
@@ -1297,8 +1306,7 @@ test.describe("System — Health notices sources @medium", () => {
); );
const request = frigateApp.page.waitForRequest( const request = frigateApp.page.waitForRequest(
(req) => (req) =>
req.url().includes(`/api/notices/${id}/mute`) && new URL(req.url()).pathname.endsWith(path) && req.method() === "POST",
req.method() === "POST",
); );
await row.getByRole("button", { name: "Mute", exact: true }).click(); await row.getByRole("button", { name: "Mute", exact: true }).click();
await request; await request;
+2 -2
View File
@@ -58,7 +58,7 @@ export function useHealthProblems(
const muteCheck = useCallback( const muteCheck = useCallback(
async (id: string) => { async (id: string) => {
await axios.post(`notices/${id}/mute`); await axios.post(`notices/${encodeURIComponent(id)}/mute`);
mutateMutedChecks(); mutateMutedChecks();
}, },
[mutateMutedChecks], [mutateMutedChecks],
@@ -66,7 +66,7 @@ export function useHealthProblems(
const unmuteCheck = useCallback( const unmuteCheck = useCallback(
async (id: string) => { async (id: string) => {
await axios.delete(`notices/${id}/hidden`); await axios.delete(`notices/${encodeURIComponent(id)}/hidden`);
mutateMutedChecks(); mutateMutedChecks();
}, },
[mutateMutedChecks], [mutateMutedChecks],
+5 -3
View File
@@ -60,15 +60,17 @@ export function useNotices(showHidden: boolean) {
); );
const acknowledge = useCallback( const acknowledge = useCallback(
(id: string) => act(axios.post(`notices/${id}/acknowledge`)), (id: string) =>
act(axios.post(`notices/${encodeURIComponent(id)}/acknowledge`)),
[act], [act],
); );
const mute = useCallback( const mute = useCallback(
(id: string) => act(axios.post(`notices/${id}/mute`)), (id: string) => act(axios.post(`notices/${encodeURIComponent(id)}/mute`)),
[act], [act],
); );
const unhide = useCallback( const unhide = useCallback(
(id: string) => act(axios.delete(`notices/${id}/hidden`)), (id: string) =>
act(axios.delete(`notices/${encodeURIComponent(id)}/hidden`)),
[act], [act],
); );