From 3217cb85f690fa7a3cc42ceb6ebd11267b7b938c Mon Sep 17 00:00:00 2001 From: Bruno Quaresma Date: Fri, 17 Jan 2025 12:37:54 -0300 Subject: [PATCH] feat: improve usage visibility (#16134) - Refactor the DAUs chart for clarity by improving the description and updating its title to better reflect the data. - Add a license consumption chart to the licenses page. --- site/src/api/api.ts | 13 + site/src/api/queries/insights.ts | 14 + site/src/components/Chart/Chart.stories.tsx | 2 +- site/src/components/Chart/Chart.tsx | 4 +- site/src/components/Link/Link.tsx | 4 +- site/src/index.css | 14 +- .../GeneralSettingsPage.tsx | 8 +- .../GeneralSettingsPageView.stories.tsx | 95 +------ .../GeneralSettingsPageView.tsx | 69 +---- .../UserEngagementChart.stories.tsx | 35 +++ .../UserEngagementChart.tsx | 187 +++++++++++++ .../LicenseSeatConsumptionChart.stories.tsx | 37 +++ .../LicenseSeatConsumptionChart.tsx | 251 ++++++++++++++++++ .../LicensesSettingsPage.tsx | 4 + .../LicensesSettingsPageView.tsx | 101 ++++--- site/tailwind.config.js | 9 +- 16 files changed, 630 insertions(+), 217 deletions(-) create mode 100644 site/src/pages/DeploymentSettingsPage/GeneralSettingsPage/UserEngagementChart.stories.tsx create mode 100644 site/src/pages/DeploymentSettingsPage/GeneralSettingsPage/UserEngagementChart.tsx create mode 100644 site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/LicenseSeatConsumptionChart.stories.tsx create mode 100644 site/src/pages/DeploymentSettingsPage/LicensesSettingsPage/LicenseSeatConsumptionChart.tsx diff --git a/site/src/api/api.ts b/site/src/api/api.ts index f3a91f176a..ac4ef4a1ca 100644 --- a/site/src/api/api.ts +++ b/site/src/api/api.ts @@ -2089,6 +2089,19 @@ class ApiMethods { return response.data; }; + getInsightsUserStatusCounts = async ( + offset = Math.trunc(new Date().getTimezoneOffset() / 60), + ): Promise => { + const searchParams = new URLSearchParams({ + tz_offset: offset.toString(), + }); + const response = await this.axios.get( + `/api/v2/insights/user-status-counts?${searchParams}`, + ); + + return response.data; + }; + getInsightsTemplate = async ( params: InsightsTemplateParams, ): Promise => { diff --git a/site/src/api/queries/insights.ts b/site/src/api/queries/insights.ts index a7044a2f24..afdf9f7efe 100644 --- a/site/src/api/queries/insights.ts +++ b/site/src/api/queries/insights.ts @@ -1,4 +1,6 @@ import { API, type InsightsParams, type InsightsTemplateParams } from "api/api"; +import type { GetUserStatusCountsResponse } from "api/typesGenerated"; +import { type UseQueryOptions, UseQueryResult } from "react-query"; export const insightsTemplate = (params: InsightsTemplateParams) => { return { @@ -20,3 +22,15 @@ export const insightsUserActivity = (params: InsightsParams) => { queryFn: () => API.getInsightsUserActivity(params), }; }; + +export const insightsUserStatusCounts = () => { + return { + queryKey: ["insights", "userStatusCounts"], + queryFn: () => API.getInsightsUserStatusCounts(), + select: (data) => data.status_counts, + } satisfies UseQueryOptions< + GetUserStatusCountsResponse, + unknown, + GetUserStatusCountsResponse["status_counts"] + >; +}; diff --git a/site/src/components/Chart/Chart.stories.tsx b/site/src/components/Chart/Chart.stories.tsx index df863d4abe..74fded80d2 100644 --- a/site/src/components/Chart/Chart.stories.tsx +++ b/site/src/components/Chart/Chart.stories.tsx @@ -19,7 +19,7 @@ const chartData = [ const chartConfig = { users: { label: "Users", - color: "hsl(var(--chart-1))", + color: "hsl(var(--highlight-purple))", }, } satisfies ChartConfig; diff --git a/site/src/components/Chart/Chart.tsx b/site/src/components/Chart/Chart.tsx index ba5ff7e7ed..d8435c3333 100644 --- a/site/src/components/Chart/Chart.tsx +++ b/site/src/components/Chart/Chart.tsx @@ -66,6 +66,8 @@ export const ChartContainer = React.forwardRef< "[&_.recharts-sector[stroke='#fff']]:stroke-transparent", "[&_.recharts-sector]:outline-none", "[&_.recharts-surface]:outline-none", + "[&_.recharts-text]:fill-content-secondary [&_.recharts-text]:font-medium", + "[&_.recharts-cartesian-axis-line]:stroke-[hsl(var(--border-default))]", className, )} {...props} @@ -195,7 +197,7 @@ export const ChartTooltipContent = React.forwardRef<
diff --git a/site/src/components/Link/Link.tsx b/site/src/components/Link/Link.tsx index e70475899f..616a24e9fa 100644 --- a/site/src/components/Link/Link.tsx +++ b/site/src/components/Link/Link.tsx @@ -1,4 +1,4 @@ -import { Slot } from "@radix-ui/react-slot"; +import { Slot, Slottable } from "@radix-ui/react-slot"; import { type VariantProps, cva } from "class-variance-authority"; import { SquareArrowOutUpRightIcon } from "lucide-react"; import { forwardRef } from "react"; @@ -38,7 +38,7 @@ export const Link = forwardRef( ref={ref} {...props} > - {children} + {children}