8000 feat: improve metrics and UI for user engagement on the platform by BrunoQuaresma · Pull Request #16134 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: improve metrics and UI for user engagement on the platform #16134

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 18 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Implement User Engagement component
  • Loading branch information
BrunoQuaresma committed Jan 14, 2025
commit 034c35919abb76dff557ad5d20fbae87321bf8d1
4 changes: 3 additions & 1 deletion site/src/components/Chart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -195,7 +197,7 @@ export const ChartTooltipContent = React.forwardRef<
<div
ref={ref}
className={cn(
"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
"grid min-w-[8rem] items-start gap-1 rounded-lg border border-solid border-border bg-surface-primary px-3 py-2 text-xs shadow-xl",
className,
)}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Meta, StoryObj } from "@storybook/react";
import { UserEngagementChart } from "./UserEngagementChart";

const meta: Meta<typeof UserEngagementChart> = {
title: "pages/DeploymentSettingsPage/GeneralSettingsPage/UserEngagementChart",
component: UserEngagementChart,
args: {
data: [
{ date: "1/1/2024", users: 150 },
{ date: "1/2/2024", users: 165 },
{ date: "1/3/2024", users: 180 },
{ date: "1/4/2024", users: 155 },
{ date: "1/5/2024", users: 190 },
{ date: "1/6/2024", users: 200 },
{ date: "1/7/2024", users: 210 },
],
},
};

export default meta;
type Story = StoryObj<typeof UserEngagementChart>;

export const Default: Story = {};
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { Button } from "components/Button/Button";
import {
ChartContainer,
ChartTooltip,
ChartTooltipContent,
type ChartConfig,
} from "components/Chart/Chart";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "components/Collapsible/Collapsible";
import { ChevronDownIcon, ExternalLinkIcon } from "lucide-react";
import type { FC } from "react";
import { Link } from "react-router-dom";
import { CartesianGrid, XAxis, Area, AreaChart, YAxis } from "recharts";

const chartConfig = {
users: {
label: "Users",
color: "hsl(var(--chart-1))",
},
} satisfies ChartConfig;

export type UserEngagementChartProps = {
data: {
date: string;
users: number;
}[];
};

export const UserEngagementChart: FC<UserEngagementChartProps> = ({ data }) => {
return (
<section className="border border-solid rounded">
<div className="p-4">
<Collapsible>
<header className="flex flex-col gap-2 items-start">
<h3 className="text-md m-0 font-medium">User Engagement</h3>

<CollapsibleTrigger asChild>
<Button className="h-auto p-0 border-0 bg-transparent font-medium text-content-secondary hover:bg-transparent hover:text-content-primary">
<ChevronDownIcon />
How we calculate engaged users
</Button>
</CollapsibleTrigger>
</header>

<CollapsibleContent className="pt-2 pl-7 pr-5 space-y-4 [&_p]:m-0 [&_p]:text-sm [&_p]:text-content-secondary font-medium">
<p>
We consider a user “engaged” if they initiate a connection to
their workspace. The connection can be made through apps, web
terminal or SSH.
</p>
<p>
The graph shows the number of unique users who were engaged at
least once during the day.
</p>
<div>
<p>You might also check:</p>
<ul className="list-none p-0 m-0 [&_a]:text-sm [&_a]:font-medium [&_a]:text-content-link [&_a]:no-underline [&_a]:flex [&_a]:items-center [&_a]:gap-0.5 [&_svg]:p-[2px]">
<li>
<Link to="/audit">
Activity Audit
<ExternalLinkIcon className="size-icon-sm" />
</Link>
</li>
<li>
<Link to="/deployment/licenses">
License Consumption
<ExternalLinkIcon className="size-icon-sm" />
</Link>
</li>
</ul>
</div>
</CollapsibleContent>
</Collapsible>
</div>

<div className="p-6 border-0 border-t border-solid">
<ChartContainer config={chartConfig} className="aspect-auto h-64">
<AreaChart
accessibilityLayer
data={data}
margin={{
left: 0,
right: 0,
}}
>
<CartesianGrid vertical={false} />
<XAxis
dataKey="date"
tickLine={false}
tickMargin={12}
tickFormatter={(value: string) =>
new Date(value).toLocaleDateString(undefined, {
month: "short",
day: "numeric",
})
}
/>
<YAxis
dataKey="users"
tickLine={false}
axisLine={false}
tickMargin={12}
tickFormatter={(value: number) => {
return value === 0 ? "" : value.toLocaleString();
}}
/>
<ChartTooltip
cursor={false}
content={
<ChartTooltipContent
className="font-medium text-content-secondary"
labelClassName="text-content-primary"
labelFormatter={(_, p) => {
const item = p[0];
return `${item.value} users`;
}}
formatter={(v, n, item) => {
const date = new Date(item.payload.date);
return date.toLocaleString(undefined, {
month: "long",
day: "2-digit",
});
}}
/>
}
/>
<defs>
<linearGradient id="fillUsers" x1="0" y1="0" x2="0" y2="1">
<stop
offset="5%"
stopColor="var(--color-users)"
stopOpacity={0.8}
/>
<stop
offset="95%"
stopColor="var(--color-users)"
stopOpacity={0.1}
/>
</linearGradient>
</defs>

<Area
dataKey="users"
type="natural"
fill="url(#fillUsers)"
fillOpacity={0.4}
stroke="var(--color-users)"
stackId="a"
/>
</AreaChart>
</ChartContainer>
</div>
</section>
);
};

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions site/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
fontSize: {
"2xs": ["0.625rem", "0.875rem"],
sm: ["0.875rem", "1.5rem"],
md: ["1rem", "1.5rem"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text-base covers the size ["1rem", "1.5rem"] so there shouldn't be a need to explicitly set md, see https://tailwindcss.com/docs/font-size#setting-the-line-height

"3xl": ["2rem", "2.5rem"],
},
borderRadius: {
Expand Down
0