Skip to content

Commit 53c282d

Browse files
committed
Move queries to queries folder
1 parent 4cfba45 commit 53c282d

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

site/src/api/api.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,25 +1471,31 @@ export const getWorkspaceParameters = async (workspace: TypesGen.Workspace) => {
14711471
};
14721472
};
14731473

1474-
type InsightsFilter = {
1474+
export type InsightsParams = {
14751475
start_time: string;
14761476
end_time: string;
14771477
template_ids: string;
14781478
};
14791479

14801480
export const getInsightsUserLatency = async (
1481-
filters: InsightsFilter,
1481+
filters: InsightsParams,
14821482
): Promise<TypesGen.UserLatencyInsightsResponse> => {
14831483
const params = new URLSearchParams(filters);
14841484
const response = await axios.get(`/api/v2/insights/user-latency?${params}`);
14851485
return response.data;
14861486
};
14871487

1488+
export type InsightsTemplateParams = InsightsParams & {
1489+
interval: "day" | "week";
1490+
};
1491+
14881492
export const getInsightsTemplate = async (
1489-
filters: InsightsFilter & { interval: "day" | "week" },
1493+
params: InsightsTemplateParams,
14901494
): Promise<TypesGen.TemplateInsightsResponse> => {
1491-
const params = new URLSearchParams(filters);
1492-
const response = await axios.get(`/api/v2/insights/templates?${params}`);
1495+
const searchParams = new URLSearchParams(params);
1496+
const response = await axios.get(
1497+
`/api/v2/insights/templates?${searchParams}`,
1498+
);
14931499
return response.data;
14941500
};
14951501

site/src/api/queries/insights.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as API from "api/api";
2+
3+
export const insightsTemplate = (params: API.InsightsTemplateParams) => {
4+
return {
5+
queryKey: ["insights", "templates", params.template_ids, params],
6+
queryFn: () => API.getInsightsTemplate(params),
7+
};
8+
};
9+
10+
export const insightsUserLatency = (params: API.InsightsParams) => {
11+
return {
12+
queryKey: ["insights", "userLatency", params.template_ids, params],
13+
queryFn: () => API.getInsightsUserLatency(params),
14+
};
15+
};

site/src/pages/TemplatePage/TemplateInsightsPage/TemplateInsightsPage.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Box from "@mui/material/Box";
33
import { styled, useTheme } from "@mui/material/styles";
44
import { BoxProps } from "@mui/system";
55
import { useQuery } from "@tanstack/react-query";
6-
import { getInsightsTemplate, getInsightsUserLatency } from "api/api";
76
import {
87
ActiveUsersTitle,
98
ActiveUserChart,
@@ -48,6 +47,7 @@ import Tooltip from "@mui/material/Tooltip";
4847
import LinkOutlined from "@mui/icons-material/LinkOutlined";
4948
import { InsightsInterval, IntervalMenu } from "./IntervalMenu";
5049
import { WeeklyPreset, WeeklyPresetsMenu } from "./WeeklyPresetsMenu";
50+
import { insightsTemplate, insightsUserLatency } from "api/queries/insights";
5151

5252
export default function TemplateInsightsPage() {
5353
const { template } = useTemplateLayoutContext();
@@ -77,14 +77,8 @@ export default function TemplateInsightsPage() {
7777
...getDateRangeFilter(dateRange),
7878
};
7979
const insightsFilter = { ...commonFilters, interval };
80-
const { data: templateInsights } = useQuery({
81-
queryKey: ["templates", template.id, "usage", insightsFilter],
82-
queryFn: () => getInsightsTemplate(insightsFilter),
83-
});
84-
const { data: userLatency } = useQuery({
85-
queryKey: ["templates", template.id, "user-latency", commonFilters],
86-
queryFn: () => getInsightsUserLatency(commonFilters),
87-
});
80+
const { data: templateInsights } = useQuery(insightsTemplate(insightsFilter));
81+
const { data: userLatency } = useQuery(insightsUserLatency(commonFilters));
8882

8983
return (
9084
<>

0 commit comments

Comments
 (0)