Skip to content

Commit 1018195

Browse files
committed
fix(site): fix workspace timings to use theme colors
1 parent 4cad6f7 commit 1018195

File tree

5 files changed

+75
-60
lines changed

5 files changed

+75
-60
lines changed

site/src/modules/workspaces/WorkspaceTiming/Chart/Bar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ const styles = {
9191
left: -8,
9292
},
9393
}),
94-
clickable: {
94+
clickable: (theme) => ({
9595
cursor: "pointer",
9696
// We need to make the bar width at least 34px to allow the "..." icons to be displayed.
9797
// The calculation is border * 1 + side paddings * 2 + icon width (which is 18px)
9898
minWidth: 34,
9999

100100
"&:focus, &:hover, &:active": {
101101
outline: "none",
102-
borderColor: "#38BDF8",
102+
borderColor: theme.roles.active.outline,
103103
},
104-
},
104+
}),
105105
} satisfies Record<string, Interpolation<Theme>>;

site/src/modules/workspaces/WorkspaceTiming/Chart/Blocks.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,22 @@ const styles = {
5252
gap: spaceBetweenBlocks,
5353
alignItems: "center",
5454
},
55-
block: {
55+
block: (theme) =>({
5656
borderRadius: 4,
5757
height: 18,
58-
backgroundColor: "#082F49",
59-
border: "1px solid #38BDF8",
58+
backgroundColor: theme.roles.active.background,
59+
border: `1px solid ${theme.roles.active.outline}`,
6060
flexShrink: 0,
6161
flex: 1,
62-
},
63-
more: {
64-
color: "#38BDF8",
62+
}),
63+
more: (theme) => ({
64+
color: theme.roles.active.outline,
6565
lineHeight: 0,
6666
flexShrink: 0,
6767
flex: 1,
6868

6969
"& svg": {
7070
fontSize: moreIconSize,
7171
},
72-
},
72+
}),
7373
} satisfies Record<string, Interpolation<Theme>>;

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

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,7 @@ import {
3232
} from "./Chart/utils";
3333
import type { StageCategory } from "./StagesChart";
3434

35-
const legendsByAction: Record<string, ChartLegend> = {
36-
"state refresh": {
37-
label: "state refresh",
38-
},
39-
create: {
40-
label: "create",
41-
colors: {
42-
fill: "#022C22",
43-
stroke: "#BBF7D0",
44-
},
45-
},
46-
delete: {
47-
label: "delete",
48-
colors: {
49-
fill: "#422006",
50-
stroke: "#FDBA74",
51-
},
52-
},
53-
read: {
54-
label: "read",
55-
colors: {
56-
fill: "#082F49",
57-
stroke: "#38BDF8",
58-
},
59-
},
60-
};
35+
6136

6237
type ResourceTiming = {
6338
name: string;
@@ -86,6 +61,8 @@ export const ResourcesChart: FC<ResourcesChartProps> = ({
8661
const visibleTimings = timings.filter(
8762
(t) => !isCoderResource(t.name) && t.name.includes(filter),
8863
);
64+
const theme = useTheme();
65+
const legendsByAction = getLegendsByAction(theme);
8966
const visibleLegends = [...new Set(visibleTimings.map((t) => t.action))].map(
9067
(a) => legendsByAction[a],
9168
);
@@ -168,3 +145,32 @@ export const isCoderResource = (resource: string) => {
168145
resource.startsWith("coder_")
169146
);
170147
};
148+
149+
function getLegendsByAction(theme: Theme): Record<string, ChartLegend> {
150+
return {
151+
"state refresh": {
152+
label: "state refresh",
153+
},
154+
create: {
155+
label: "create",
156+
colors: {
157+
fill: theme.roles.success.background,
158+
stroke: theme.roles.success.outline,
159+
},
160+
},
161+
delete: {
162+
label: "delete",
163+
colors: {
164+
fill: theme.roles.warning.background,
165+
stroke: theme.roles.warning.outline,
166+
},
167+
},
168+
read: {
169+
label: "read",
170+
colors: {
171+
fill: theme.roles.active.background,
172+
stroke: theme.roles.active.outline,
173+
},
174+
},
175+
}
176+
}

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,7 @@ import {
2727
mergeTimeRanges,
2828
} from "./Chart/utils";
2929
import type { StageCategory } from "./StagesChart";
30-
31-
const legendsByStatus: Record<string, ChartLegend> = {
32-
ok: {
33-
label: "success",
34-
colors: {
35-
fill: "#022C22",
36-
stroke: "#BBF7D0",
37-
},
38-
},
39-
exit_failure: {
40-
label: "failure",
41-
colors: {
42-
fill: "#450A0A",
43-
stroke: "#F87171",
44-
},
45-
},
46-
timeout: {
47-
label: "timed out",
48-
colors: {
49-
fill: "#422006",
50-
stroke: "#FDBA74",
51-
},
52-
},
53-
};
30+
import { type Theme, useTheme } from "@emotion/react";
5431

5532
type ScriptTiming = {
5633
name: string;
@@ -77,6 +54,8 @@ export const ScriptsChart: FC<ScriptsChartProps> = ({
7754
const [ticks, scale] = makeTicks(totalTime);
7855
const [filter, setFilter] = useState("");
7956
const visibleTimings = timings.filter((t) => t.name.includes(filter));
57+
const theme = useTheme()
58+
const legendsByStatus = getLegendsByStatus(theme);
8059
const visibleLegends = [...new Set(visibleTimings.map((t) => t.status))].map(
8160
(s) => legendsByStatus[s],
8261
);
@@ -151,3 +130,29 @@ export const ScriptsChart: FC<ScriptsChartProps> = ({
151130
</Chart>
152131
);
153132
};
133+
134+
function getLegendsByStatus(theme: Theme): Record<string, ChartLegend> {
135+
return {
136+
ok: {
137+
label: "success",
138+
colors: {
139+
fill: theme.roles.success.background,
140+
stroke: theme.roles.success.outline,
141+
},
142+
},
143+
exit_failure: {
144+
label: "failure",
145+
colors: {
146+
fill: theme.roles.error.background,
147+
stroke: theme.roles.error.outline,
148+
},
149+
},
150+
timeout: {
151+
label: "timed out",
152+
colors: {
153+
fill: theme.roles.warning.background,
154+
stroke: theme.roles.warning.outline,
155+
},
156+
},
157+
}
158+
};

site/src/modules/workspaces/WorkspaceTiming/WorkspaceTimings.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Meta, StoryObj } from "@storybook/react";
22
import { expect, userEvent, waitFor, within } from "@storybook/test";
33
import { WorkspaceTimings } from "./WorkspaceTimings";
44
import { WorkspaceTimingsResponse } from "./storybookData";
5+
import { chromatic } from "testHelpers/chromatic";
56

67
const meta: Meta<typeof WorkspaceTimings> = {
78
title: "modules/workspaces/WorkspaceTimings",
@@ -11,6 +12,9 @@ const meta: Meta<typeof WorkspaceTimings> = {
1112
provisionerTimings: WorkspaceTimingsResponse.provisioner_timings,
1213
agentScriptTimings: WorkspaceTimingsResponse.agent_script_timings,
1314
},
15+
parameters: {
16+
chromatic,
17+
}
1418
};
1519

1620
export default meta;

0 commit comments

Comments
 (0)