Skip to content

Commit 9a8bb59

Browse files
committed
Add info tooltip
1 parent 6c742aa commit 9a8bb59

File tree

1 file changed

+94
-3
lines changed

1 file changed

+94
-3
lines changed

site/src/modules/workspaces/WorkspaceTiming/StagesChart.tsx

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
XAxisSections,
66
XAxisMinWidth,
77
} from "./Chart/XAxis";
8-
import type { FC } from "react";
8+
import type { FC, PropsWithChildren } from "react";
99
import {
1010
YAxis,
1111
YAxisCaption,
@@ -24,31 +24,58 @@ import {
2424
} from "./Chart/utils";
2525
import { Chart, ChartContent } from "./Chart/Chart";
2626
import { BarBlocks } from "./Chart/BarBlocks";
27+
import InfoOutlined from "@mui/icons-material/InfoOutlined";
28+
import { useTheme, type Interpolation, type Theme } from "@emotion/react";
29+
import Tooltip, { type TooltipProps } from "@mui/material/Tooltip";
30+
import { css } from "@emotion/css";
2731

2832
// TODO: Add "workspace boot" when scripting timings are done.
2933
const stageCategories = ["provisioning"] as const;
3034

3135
type StageCategory = (typeof stageCategories)[number];
3236

33-
type Stage = { name: string; category: StageCategory };
37+
type Stage = {
38+
name: string;
39+
category: StageCategory;
40+
tooltip: { title: string; description: string };
41+
};
3442

3543
// TODO: Export provisioning stages from the BE to the generated types.
3644
export const stages: Stage[] = [
3745
{
3846
name: "init",
3947
category: "provisioning",
48+
tooltip: {
49+
title: "Terraform initialization",
50+
description: "Download providers & modules.",
51+
},
4052
},
4153
{
4254
name: "plan",
4355
category: "provisioning",
56+
tooltip: {
57+
title: "Terraform plan",
58+
description:
59+
"Compare state of desired vs actual resources and compute changes to be made.",
60+
},
4461
},
4562
{
4663
name: "graph",
4764
category: "provisioning",
65+
tooltip: {
66+
title: "Terraform graph",
67+
description:
68+
"List all resources in plan, used to update coderd database.",
69+
},
4870
},
4971
{
5072
name: "apply",
5173
category: "provisioning",
74+
tooltip: {
75+
title: "Terraform apply",
76+
description:
77+
"Execute terraform plan to create/modify/delete resources into desired states.",
78+
},
5279
},
5380
];
5481

@@ -94,7 +121,12 @@ export const StagesChart: FC<StagesChartProps> = ({
94121
<YAxisLabels>
95122
{stagesInCategory.map((stage) => (
96123
<YAxisLabel key={stage.name} id={stage.name}>
97-
{stage.name}
124+
<span css={styles.stageLabel}>
125+
{stage.name}
126+
<StageInfoTooltip {...stage.tooltip}>
127+
<InfoOutlined css={styles.info} />
128+
</StageInfoTooltip>
129+
</span>
98130
</YAxisLabel>
99131
))}
100132
</YAxisLabels>
@@ -145,3 +177,62 @@ export const StagesChart: FC<StagesChartProps> = ({
145177
</Chart>
146178
);
147179
};
180+
181+
type StageInfoTooltipProps = TooltipProps & {
182+
title: string;
183+
description: string;
184+
};
185+
186+
const StageInfoTooltip: FC<StageInfoTooltipProps> = ({
187+
title,
188+
description,
189+
children,
190+
}) => {
191+
const theme = useTheme();
192+
193+
return (
194+
<Tooltip
195+
classes={{
196+
tooltip: css({
197+
backgroundColor: theme.palette.background.default,
198+
border: `1px solid ${theme.palette.divider}`,
199+
width: 220,
200+
}),
201+
}}
202+
title={
203+
<div css={styles.tooltipTitle}>
204+
<span css={styles.infoStageName}>{title}</span>
205+
<span>{description}</span>
206+
</div>
207+
}
208+
>
209+
{children}
210+
</Tooltip>
211+
);
212+
};
213+
214+
const styles = {
215+
stageLabel: {
216+
display: "flex",
217+
alignItems: "center",
218+
gap: 2,
219+
justifyContent: "flex-end",
220+
},
221+
info: (theme) => ({
222+
width: 12,
223+
height: 12,
224+
color: theme.palette.text.secondary,
225+
cursor: "pointer",
226+
}),
227+
tooltipTitle: (theme) => ({
228+
display: "flex",
229+
flexDirection: "column",
230+
fontWeight: 500,
231+
fontSize: 12,
232+
color: theme.palette.text.secondary,
233+
gap: 4,
234+
}),
235+
infoStageName: (theme) => ({
236+
color: theme.palette.text.primary,
237+
}),
238+
} satisfies Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)