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
Modify DAUChart to be agnostic to interval
  • Loading branch information
BrunoQuaresma committed Oct 2, 2023
commit 78e6db05c1bb4c93e6235c96948726c9d82cabc2
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Box from "@mui/material/Box";
import { Theme } from "@mui/material/styles";
import useTheme from "@mui/styles/useTheme";
import * as TypesGen from "api/typesGenerated";
import {
CategoryScale,
Chart as ChartJS,
Expand Down Expand Up @@ -38,18 +37,18 @@ ChartJS.register(
Legend,
);

export interface DAUChartProps {
daus: TypesGen.DAUsResponse;
export interface ActiveUserChartProps {
data: { date: string; amount: number }[];
}

export const DAUChart: FC<DAUChartProps> = ({ daus }) => {
export const ActiveUserChart: FC<ActiveUserChartProps> = ({ data }) => {
const theme: Theme = useTheme();

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

const data = daus.entries.map((val) => {
const chartData = data.map((val) => {
return val.amount;
});

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

x: {
ticks: {
stepSize: daus.entries.length > 10 ? 2 : undefined,
stepSize: data.length > 10 ? 2 : undefined,
},
type: "time",
time: {
Expand All @@ -101,7 +100,7 @@ export const DAUChart: FC<DAUChartProps> = ({ daus }) => {
datasets: [
{
label: "Daily Active Users",
data: data,
data: chartData,
pointBackgroundColor: theme.palette.info.light,
pointBorderColor: theme.palette.info.light,
borderColor: theme.palette.info.light,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Box from "@mui/material/Box";
import { ClibaseOption, DAUsResponse } from "api/typesGenerated";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { DAUChart, ActiveUsersTitle } from "components/DAUChart/DAUChart";
import {
ActiveUserChart,
ActiveUsersTitle,
} from "components/ActiveUserChart/ActiveUserChart";
import { Header } from "components/DeploySettingsLayout/Header";
import OptionsTable from "components/DeploySettingsLayout/OptionsTable";
import { Stack } from "components/Stack/Stack";
Expand Down Expand Up @@ -33,7 +36,7 @@ export const GeneralSettingsPageView = ({
{deploymentDAUs && (
<Box height={200} sx={{ mb: 3 }}>
<ChartSection title={<ActiveUsersTitle />}>
<DAUChart daus={deploymentDAUs} />
<ActiveUserChart data={deploymentDAUs.entries} />
</ChartSection>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ 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, DAUChart } from "components/DAUChart/DAUChart";
import {
ActiveUsersTitle,
ActiveUserChart,
} from "components/ActiveUserChart/ActiveUserChart";
import { useTemplateLayoutContext } from "pages/TemplatePage/TemplateLayout";
import {
HelpTooltip,
Expand All @@ -19,7 +22,6 @@ import { Helmet } from "react-helmet-async";
import { getTemplatePageTitle } from "../utils";
import { Loader } from "components/Loader/Loader";
import {
DAUsResponse,
TemplateInsightsResponse,
TemplateParameterUsage,
TemplateParameterValue,
Expand Down Expand Up @@ -178,7 +180,16 @@ const ActiveUsersPanel = ({
<PanelContent>
{!data && <Loader sx={{ height: "100%" }} />}
{data && data.length === 0 && <NoDataAvailable />}
{data && data.length > 0 && <DAUChart daus={mapToDAUsResponse(data)} />}
{data && data.length > 0 && (
<ActiveUserChart
data={data.map((d) => {
return {
amount: d.active_users,
date: d.start_time,
};
})}
/>
)}
</PanelContent>
</Panel>
);
Expand Down Expand Up @@ -636,20 +647,6 @@ const getWeeklyRange = (numberOfWeeks: WeeklyPreset) => {
return { startDate, endDate };
};

function mapToDAUsResponse(
data: TemplateInsightsResponse["interval_reports"],
): DAUsResponse {
return {
tz_hour_offset: 0,
entries: data.map((d) => {
return {
amount: d.active_users,
date: d.start_time,
};
}),
};
}

function formatTime(seconds: number): string {
if (seconds < 60) {
return seconds + " seconds";
Expand Down