Skip to content

Commit 78e6db0

Browse files
committed
Modify DAUChart to be agnostic to interval
1 parent 86fab98 commit 78e6db0

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

site/src/components/DAUChart/DAUChart.tsx renamed to site/src/components/ActiveUserChart/ActiveUserChart.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Box from "@mui/material/Box";
22
import { Theme } from "@mui/material/styles";
33
import useTheme from "@mui/styles/useTheme";
4-
import * as TypesGen from "api/typesGenerated";
54
import {
65
CategoryScale,
76
Chart as ChartJS,
@@ -38,18 +37,18 @@ ChartJS.register(
3837
Legend,
3938
);
4039

41-
export interface DAUChartProps {
42-
daus: TypesGen.DAUsResponse;
40+
export interface ActiveUserChartProps {
41+
data: { date: string; amount: number }[];
4342
}
4443

45-
export const DAUChart: FC<DAUChartProps> = ({ daus }) => {
44+
export const ActiveUserChart: FC<ActiveUserChartProps> = ({ data }) => {
4645
const theme: Theme = useTheme();
4746

48-
const labels = daus.entries.map((val) => {
47+
const labels = data.map((val) => {
4948
return dayjs(val.date).format("YYYY-MM-DD");
5049
});
5150

52-
const data = daus.entries.map((val) => {
51+
const chartData = data.map((val) => {
5352
return val.amount;
5453
});
5554

@@ -82,7 +81,7 @@ export const DAUChart: FC<DAUChartProps> = ({ daus }) => {
8281

8382
x: {
8483
ticks: {
85-
stepSize: daus.entries.length > 10 ? 2 : undefined,
84+
stepSize: data.length > 10 ? 2 : undefined,
8685
},
8786
type: "time",
8887
time: {
@@ -101,7 +100,7 @@ export const DAUChart: FC<DAUChartProps> = ({ daus }) => {
101100
datasets: [
102101
{
103102
label: "Daily Active Users",
104-
data: data,
103+
data: chartData,
105104
pointBackgroundColor: theme.palette.info.light,
106105
pointBorderColor: theme.palette.info.light,
107106
borderColor: theme.palette.info.light,

site/src/pages/DeploySettingsPage/GeneralSettingsPage/GeneralSettingsPageView.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import Box from "@mui/material/Box";
22
import { ClibaseOption, DAUsResponse } from "api/typesGenerated";
33
import { ErrorAlert } from "components/Alert/ErrorAlert";
4-
import { DAUChart, ActiveUsersTitle } from "components/DAUChart/DAUChart";
4+
import {
5+
ActiveUserChart,
6+
ActiveUsersTitle,
7+
} from "components/ActiveUserChart/ActiveUserChart";
58
import { Header } from "components/DeploySettingsLayout/Header";
69
import OptionsTable from "components/DeploySettingsLayout/OptionsTable";
710
import { Stack } from "components/Stack/Stack";
@@ -33,7 +36,7 @@ export const GeneralSettingsPageView = ({
3336
{deploymentDAUs && (
3437
<Box height={200} sx={{ mb: 3 }}>
3538
<ChartSection title={<ActiveUsersTitle />}>
36-
<DAUChart daus={deploymentDAUs} />
39+
<ActiveUserChart data={deploymentDAUs.entries} />
3740
</ChartSection>
3841
</Box>
3942
)}

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

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { styled, useTheme } from "@mui/material/styles";
44
import { BoxProps } from "@mui/system";
55
import { useQuery } from "@tanstack/react-query";
66
import { getInsightsTemplate, getInsightsUserLatency } from "api/api";
7-
import { ActiveUsersTitle, DAUChart } from "components/DAUChart/DAUChart";
7+
import {
8+
ActiveUsersTitle,
9+
ActiveUserChart,
10+
} from "components/ActiveUserChart/ActiveUserChart";
811
import { useTemplateLayoutContext } from "pages/TemplatePage/TemplateLayout";
912
import {
1013
HelpTooltip,
@@ -19,7 +22,6 @@ import { Helmet } from "react-helmet-async";
1922
import { getTemplatePageTitle } from "../utils";
2023
import { Loader } from "components/Loader/Loader";
2124
import {
22-
DAUsResponse,
2325
TemplateInsightsResponse,
2426
TemplateParameterUsage,
2527
TemplateParameterValue,
@@ -178,7 +180,16 @@ const ActiveUsersPanel = ({
178180
<PanelContent>
179181
{!data && <Loader sx={{ height: "100%" }} />}
180182
{data && data.length === 0 && <NoDataAvailable />}
181-
{data && data.length > 0 && <DAUChart daus={mapToDAUsResponse(data)} />}
183+
{data && data.length > 0 && (
184+
<ActiveUserChart
185+
data={data.map((d) => {
186+
return {
187+
amount: d.active_users,
188+
date: d.start_time,
189+
};
190+
})}
191+
/>
192+
)}
182193
</PanelContent>
183194
</Panel>
184195
);
@@ -636,20 +647,6 @@ const getWeeklyRange = (numberOfWeeks: WeeklyPreset) => {
636647
return { startDate, endDate };
637648
};
638649

639-
function mapToDAUsResponse(
640-
data: TemplateInsightsResponse["interval_reports"],
641-
): DAUsResponse {
642-
return {
643-
tz_hour_offset: 0,
644-
entries: data.map((d) => {
645-
return {
646-
amount: d.active_users,
647-
date: d.start_time,
648-
};
649-
}),
650-
};
651-
}
652-
653650
function formatTime(seconds: number): string {
654651
if (seconds < 60) {
655652
return seconds + " seconds";

0 commit comments

Comments
 (0)