Skip to content

Commit 0847176

Browse files
committed
refactor(site): refactor DAU chart
1 parent 6e54bd9 commit 0847176

File tree

6 files changed

+12
-73
lines changed

6 files changed

+12
-73
lines changed

site/src/components/ActiveUserChart/ActiveUserChart.stories.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,3 @@ export default meta;
2222
type Story = StoryObj<typeof ActiveUserChart>;
2323

2424
export const Example: Story = {};
25-
26-
export const UserLimit: Story = {
27-
args: {
28-
userLimit: 10,
29-
},
30-
};

site/src/components/ActiveUserChart/ActiveUserChart.tsx

+9-40
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
Tooltip,
1515
defaults,
1616
} from "chart.js";
17-
import annotationPlugin from "chartjs-plugin-annotation";
1817
import {
1918
HelpTooltip,
2019
HelpTooltipContent,
@@ -36,21 +35,16 @@ ChartJS.register(
3635
Title,
3736
Tooltip,
3837
Legend,
39-
annotationPlugin,
4038
);
4139

42-
const USER_LIMIT_DISPLAY_THRESHOLD = 60;
43-
4440
export interface ActiveUserChartProps {
4541
data: readonly { date: string; amount: number }[];
4642
interval: "day" | "week";
47-
userLimit: number | undefined;
4843
}
4944

5045
export const ActiveUserChart: FC<ActiveUserChartProps> = ({
5146
data,
5247
interval,
53-
userLimit,
5448
}) => {
5549
const theme = useTheme();
5650

@@ -64,24 +58,6 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
6458
responsive: true,
6559
animation: false,
6660
plugins: {
67-
annotation: {
68-
annotations: [
69-
{
70-
type: "line",
71-
scaleID: "y",
72-
display: shouldDisplayUserLimit(userLimit, chartData),
73-
value: userLimit,
74-
borderColor: theme.palette.secondary.contrastText,
75-
borderWidth: 5,
76-
label: {
77-
content: "User limit",
78-
color: theme.palette.primary.contrastText,
79-
display: true,
80-
font: { weight: "normal" },
81-
},
82-
},
83-
],
84-
},
8561
legend: {
8662
display: false,
8763
},
@@ -103,7 +79,6 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
10379
precision: 0,
10480
},
10581
},
106-
10782
x: {
10883
grid: { color: theme.palette.divider },
10984
ticks: {
@@ -138,32 +113,26 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
138113
);
139114
};
140115

141-
export const ActiveUsersTitle: FC = () => {
116+
type ActiveUsersTitleProps = {
117+
interval: "day" | "week";
118+
};
119+
120+
export const ActiveUsersTitle: FC<ActiveUsersTitleProps> = ({ interval }) => {
142121
return (
143122
<div css={{ display: "flex", alignItems: "center", gap: 8 }}>
144-
Active Users
123+
{interval === "day" ? "Daily" : "Weekly"} Active Users
145124
<HelpTooltip>
146125
<HelpTooltipTrigger size="small" />
147126
<HelpTooltipContent>
148127
<HelpTooltipTitle>How do we calculate active users?</HelpTooltipTitle>
149128
<HelpTooltipText>
150129
When a connection is initiated to a user&apos;s workspace they are
151-
considered an active user. e.g. apps, web terminal, SSH
130+
considered an active user. e.g. apps, web terminal, SSH. This is for
131+
measuring user activity and has no connection to license
132+
consumption.
152133
</HelpTooltipText>
153134
</HelpTooltipContent>
154135
</HelpTooltip>
155136
</div>
156137
);
157138
};
158-
159-
function shouldDisplayUserLimit(
160-
userLimit: number | undefined,
161-
activeUsers: number[],
162-
): boolean {
163-
if (!userLimit || activeUsers.length === 0) {
164-
return false;
165-
}
166-
return (
167-
Math.max(...activeUsers) >= (userLimit * USER_LIMIT_DISPLAY_THRESHOLD) / 100
168-
);
169-
}

site/src/pages/DeploymentSettingsPage/GeneralSettingsPage/GeneralSettingsPageView.stories.tsx

-7
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ type Story = StoryObj<typeof GeneralSettingsPageView>;
5050

5151
export const Page: Story = {};
5252

53-
export const WithUserLimit: Story = {
54-
args: {
55-
deploymentDAUs: MockDeploymentDAUResponse,
56-
entitlements: MockEntitlementsWithUserLimit,
57-
},
58-
};
59-
6053
export const NoDAUs: Story = {
6154
args: {
6255
deploymentDAUs: undefined,

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,8 @@ export const GeneralSettingsPageView: FC<GeneralSettingsPageViewProps> = ({
4949
)}
5050
{deploymentDAUs && (
5151
<div css={{ marginBottom: 24, height: 200 }}>
52-
<ChartSection title={<ActiveUsersTitle />}>
53-
<ActiveUserChart
54-
data={deploymentDAUs.entries}
55-
interval="day"
56-
userLimit={
57-
entitlements?.features.user_limit.enabled
58-
? entitlements?.features.user_limit.limit
59-
: undefined
60-
}
61-
/>
52+
<ChartSection title={<ActiveUsersTitle interval="day" />}>
53+
<ActiveUserChart data={deploymentDAUs.entries} interval="day" />
6254
</ChartSection>
6355
</div>
6456
)}

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

-8
Original file line numberDiff line numberDiff line change
@@ -868,11 +868,3 @@ export const Loaded: Story = {
868868
},
869869
},
870870
};
871-
872-
export const LoadedWithUserLimit: Story = {
873-
...Loaded,
874-
args: {
875-
...Loaded.args,
876-
entitlements: MockEntitlementsWithUserLimit,
877-
},
878-
};

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ const ActiveUsersPanel: FC<ActiveUsersPanelProps> = ({
249249
<Panel {...panelProps}>
250250
<PanelHeader>
251251
<PanelTitle>
252-
<ActiveUsersTitle />
252+
<ActiveUsersTitle interval={interval} />
253253
</PanelTitle>
254254
</PanelHeader>
255255
<PanelContent>
@@ -258,7 +258,6 @@ const ActiveUsersPanel: FC<ActiveUsersPanelProps> = ({
258258
{data && data.length > 0 && (
259259
<ActiveUserChart
260260
interval={interval}
261-
userLimit={userLimit}
262261
data={data.map((d) => ({
263262
amount: d.active_users,
264263
date: d.start_time,

0 commit comments

Comments
 (0)