Skip to content

feat(site): add support for weekly data on template insights #9997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move queries to queries folder
  • Loading branch information
BrunoQuaresma committed Oct 3, 2023
commit 53c282d032df26d0eeb1765d5bd8a920bfefb0b8
16 changes: 11 additions & 5 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1471,25 +1471,31 @@ export const getWorkspaceParameters = async (workspace: TypesGen.Workspace) => {
};
};

type InsightsFilter = {
export type InsightsParams = {
start_time: string;
end_time: string;
template_ids: string;
};

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

export type InsightsTemplateParams = InsightsParams & {
interval: "day" | "week";
};

export const getInsightsTemplate = async (
filters: InsightsFilter & { interval: "day" | "week" },
params: InsightsTemplateParams,
): Promise<TypesGen.TemplateInsightsResponse> => {
const params = new URLSearchParams(filters);
const response = await axios.get(`/api/v2/insights/templates?${params}`);
const searchParams = new URLSearchParams(params);
const response = await axios.get(
`/api/v2/insights/templates?${searchParams}`,
);
return response.data;
};

Expand Down
15 changes: 15 additions & 0 deletions site/src/api/queries/insights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as API from "api/api";

export const insightsTemplate = (params: API.InsightsTemplateParams) => {
return {
queryKey: ["insights", "templates", params.template_ids, params],
queryFn: () => API.getInsightsTemplate(params),
};
};

export const insightsUserLatency = (params: API.InsightsParams) => {
return {
queryKey: ["insights", "userLatency", params.template_ids, params],
queryFn: () => API.getInsightsUserLatency(params),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Box from "@mui/material/Box";
import { styled, useTheme } from "@mui/material/styles";
import { BoxProps } from "@mui/system";
import { useQuery } from "@tanstack/react-query";
import { getInsightsTemplate, getInsightsUserLatency } from "api/api";
import {
ActiveUsersTitle,
ActiveUserChart,
Expand Down Expand Up @@ -48,6 +47,7 @@ import Tooltip from "@mui/material/Tooltip";
import LinkOutlined from "@mui/icons-material/LinkOutlined";
import { InsightsInterval, IntervalMenu } from "./IntervalMenu";
import { WeeklyPreset, WeeklyPresetsMenu } from "./WeeklyPresetsMenu";
import { insightsTemplate, insightsUserLatency } from "api/queries/insights";

export default function TemplateInsightsPage() {
const { template } = useTemplateLayoutContext();
Expand Down Expand Up @@ -77,14 +77,8 @@ export default function TemplateInsightsPage() {
...getDateRangeFilter(dateRange),
};
const insightsFilter = { ...commonFilters, interval };
const { data: templateInsights } = useQuery({
queryKey: ["templates", template.id, "usage", insightsFilter],
queryFn: () => getInsightsTemplate(insightsFilter),
});
const { data: userLatency } = useQuery({
queryKey: ["templates", template.id, "user-latency", commonFilters],
queryFn: () => getInsightsUserLatency(commonFilters),
});
const { data: templateInsights } = useQuery(insightsTemplate(insightsFilter));
const { data: userLatency } = useQuery(insightsUserLatency(commonFilters));

return (
<>
Expand Down