From 425edeea04d286f0bb9d4877fe214a719e5ffda4 Mon Sep 17 00:00:00 2001 From: Matt Aitken Date: Wed, 25 Jun 2025 16:39:07 +0100 Subject: [PATCH] Consistent way to get the run filters --- .../app/presenters/RunFilters.server.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 apps/webapp/app/presenters/RunFilters.server.ts diff --git a/apps/webapp/app/presenters/RunFilters.server.ts b/apps/webapp/app/presenters/RunFilters.server.ts new file mode 100644 index 000000000..46edfa78e --- /dev/null +++ b/apps/webapp/app/presenters/RunFilters.server.ts @@ -0,0 +1,61 @@ +import { TaskRunListSearchFilters } from "~/components/runs/v3/RunFilters"; +import { getRootOnlyFilterPreference } from "~/services/preferences/uiPreferences.server"; + +export async function getRunFiltersFromRequest(request: Request) { + const url = new URL(request.url); + let rootOnlyValue = false; + if (url.searchParams.has("rootOnly")) { + rootOnlyValue = url.searchParams.get("rootOnly") === "true"; + } else { + rootOnlyValue = await getRootOnlyFilterPreference(request); + } + + const s = { + cursor: url.searchParams.get("cursor") ?? undefined, + direction: url.searchParams.get("direction") ?? undefined, + statuses: url.searchParams.getAll("statuses"), + tasks: url.searchParams.getAll("tasks"), + period: url.searchParams.get("period") ?? undefined, + bulkId: url.searchParams.get("bulkId") ?? undefined, + tags: url.searchParams.getAll("tags").map((t) => decodeURIComponent(t)), + from: url.searchParams.get("from") ?? undefined, + to: url.searchParams.get("to") ?? undefined, + rootOnly: rootOnlyValue, + runId: url.searchParams.get("runId") ?? undefined, + batchId: url.searchParams.get("batchId") ?? undefined, + scheduleId: url.searchParams.get("scheduleId") ?? undefined, + }; + + const { + tasks, + versions, + statuses, + tags, + period, + bulkId, + from, + to, + cursor, + direction, + runId, + batchId, + scheduleId, + } = TaskRunListSearchFilters.parse(s); + + return { + tasks, + versions, + statuses, + tags, + period, + bulkId, + from, + to, + batchId, + runIds: runId ? [runId] : undefined, + scheduleId, + rootOnly: rootOnlyValue, + direction: direction, + cursor: cursor, + }; +}