Skip to content

Commit cd15d51

Browse files
committed
Parse the scope from the URL
1 parent fd6ab3f commit cd15d51

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.metrics.$dashboardKey/route.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { QueuesFilter } from "~/components/metrics/QueuesFilter";
3030
import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route";
3131
import { useSearchParams } from "~/hooks/useSearchParam";
3232
import { type WidgetData } from "~/components/metrics/QueryWidget";
33-
import type { QueryScope } from "~/services/queryService.server";
33+
import { QueryScopeSchema } from "~/v3/querySchemas";
3434

3535
const ParamSchema = EnvironmentParamSchema.extend({
3636
dashboardKey: z.string(),
@@ -145,7 +145,8 @@ export function MetricDashboard({
145145
const period = value("period");
146146
const from = value("from");
147147
const to = value("to");
148-
const scope = (value("scope") as QueryScope) ?? "environment";
148+
const parsedScope = QueryScopeSchema.safeParse(value("scope") ?? "environment");
149+
const scope = parsedScope.success ? parsedScope.data : "environment";
149150
const tasks = values("tasks").filter((v) => v !== "");
150151
const queues = values("queues").filter((v) => v !== "");
151152

apps/webapp/app/services/queryService.server.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ import {
2020
import { getLimit } from "./platform.v3.server";
2121
import { timeFilters, timeFilterFromTo } from "~/components/runs/v3/SharedFilters";
2222
import parse from "parse-duration";
23-
import { querySchemas } from "~/v3/querySchemas";
23+
import { querySchemas, QueryScopeSchema, type QueryScope } from "~/v3/querySchemas";
2424

25-
export type { TableSchema, TSQLQueryResult };
26-
27-
export type QueryScope = "organization" | "project" | "environment";
25+
export { QueryScopeSchema };
26+
export type { TableSchema, TSQLQueryResult, QueryScope };
2827

2928
const scopeToEnum = {
3029
organization: "ORGANIZATION",

apps/webapp/app/v3/querySchemas.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { column, type TableSchema } from "@internal/tsql";
2+
import { z } from "zod";
23
import { autoFormatSQL } from "~/components/code/TSQLEditor";
34
import { runFriendlyStatus, runStatusTitleFromStatus } from "~/components/runs/v3/TaskRunStatus";
45
import { logger } from "~/services/logger.server";
56

7+
export const QueryScopeSchema = z.enum(["organization", "project", "environment"]);
8+
export type QueryScope = z.infer<typeof QueryScopeSchema>;
9+
610
/**
711
* Environment type values
812
*/

0 commit comments

Comments
 (0)