Skip to content

feat(site): add workspace timings #15068

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 54 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
5268b1e
Add base components for the chart
BrunoQuaresma Sep 19, 2024
4d509f9
Improve spacing calc
BrunoQuaresma Sep 19, 2024
d48624b
Make bars clickable
BrunoQuaresma Sep 19, 2024
62152ce
Refactor code to allow multiple views
BrunoQuaresma Sep 20, 2024
fd84ed9
Add basic view and breadcrumbs
BrunoQuaresma Sep 23, 2024
f7f09ff
Add resource filtering
BrunoQuaresma Sep 23, 2024
2ffc75a
Find the right tick spacings
BrunoQuaresma Sep 23, 2024
a8372e1
Add colors to the bars
BrunoQuaresma Sep 23, 2024
f7c7488
Do not display Coder resource
BrunoQuaresma Sep 23, 2024
0868185
Add legends
BrunoQuaresma Sep 23, 2024
54d13c8
Handle empty search
BrunoQuaresma Sep 23, 2024
714e37b
Improve coder resource filter and adjust bar hover
BrunoQuaresma Sep 24, 2024
a2dd126
Only scroll the chart
BrunoQuaresma Sep 24, 2024
0b4747e
Add tooltip
BrunoQuaresma Sep 24, 2024
49d3a72
Refactor code and improve legends
BrunoQuaresma Sep 25, 2024
647635d
Adjust columns to fit the space
BrunoQuaresma Sep 25, 2024
6c742aa
Customize scroll
BrunoQuaresma Sep 25, 2024
9a8bb59
Add info tooltip
BrunoQuaresma Sep 25, 2024
4139151
Fix fmt
BrunoQuaresma Sep 25, 2024
bcff9c6
Fix nblock gen
BrunoQuaresma Sep 25, 2024
97b25d9
Fix key
BrunoQuaresma Sep 25, 2024
6d5c344
Debug on chromatic
BrunoQuaresma Sep 25, 2024
c4bd74e
Another debug image
BrunoQuaresma Sep 25, 2024
939ec9a
Try with useEffect
BrunoQuaresma Sep 25, 2024
49c69e0
Fix labels alignment
BrunoQuaresma Sep 26, 2024
61008a3
Increase border radius tooltip
BrunoQuaresma Sep 26, 2024
f969ef2
Add scroll mask
BrunoQuaresma Sep 26, 2024
f55033a
Merge branch 'main' of https://github.com/coder/coder into bq/workspa…
BrunoQuaresma Oct 14, 2024
00616d3
Include agent scripts
BrunoQuaresma Oct 14, 2024
8cc7eef
Add failed icon
BrunoQuaresma Oct 14, 2024
6b95860
Use use effect
BrunoQuaresma Oct 14, 2024
5d08ff0
Apply @chifro feedback
BrunoQuaresma Oct 17, 2024
ea3676a
Add legends to script chart
BrunoQuaresma Oct 17, 2024
1c74c96
Fix fmt
BrunoQuaresma Oct 17, 2024
57df89b
Apply Christin suggestions
BrunoQuaresma Oct 18, 2024
48a61d8
Move style constants to css variables
BrunoQuaresma Oct 18, 2024
0726f39
Fix and rename bar blocks
BrunoQuaresma Oct 18, 2024
a4752c3
Remove unecessary cursor
BrunoQuaresma Oct 18, 2024
b481edd
Add tooltip for scripts
BrunoQuaresma Oct 18, 2024
90b54b4
Fix fmt
BrunoQuaresma Oct 18, 2024
266d82d
Add provisioning time collapse
BrunoQuaresma Oct 18, 2024
a4a1ba8
Merge branch 'main' of https://github.com/coder/coder into bq/workspa…
BrunoQuaresma Oct 18, 2024
4eb24f7
Add timings to the workspace UI
BrunoQuaresma Oct 18, 2024
79f370c
Fix fmt
BrunoQuaresma Oct 18, 2024
a1ee002
Merge branch 'main' of https://github.com/coder/coder into bq/workspa…
BrunoQuaresma Oct 21, 2024
75ea1e5
Fix code verbiage
BrunoQuaresma Oct 21, 2024
edb885c
Fetch timings from build and not workspace
BrunoQuaresma Oct 21, 2024
f8bb22c
Don't could coder resources for blocks
BrunoQuaresma Oct 21, 2024
1ff245c
Fix timings getting fetched before build getting done
BrunoQuaresma Oct 21, 2024
541ccba
Fix comment spacing
BrunoQuaresma Oct 21, 2024
b3f0351
Revert scales on def
BrunoQuaresma Oct 21, 2024
65ca087
Fix columnd calcl
BrunoQuaresma Oct 21, 2024
f288169
Fix fmt
BrunoQuaresma Oct 22, 2024
08874a3
Add extra tests
BrunoQuaresma Oct 23, 2024
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
7 changes: 7 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,13 @@ class ApiMethods {
) => {
await this.axios.post<void>("/api/v2/users/otp/change-password", req);
};

workspaceBuildTimings = async (workspaceBuildId: string) => {
const res = await this.axios.get<TypesGen.WorkspaceBuildTimings>(
`/api/v2/workspacebuilds/${workspaceBuildId}/timings`,
);
return res.data;
};
}

// This is a hard coded CSRF token/cookie pair for local development. In prod,
Expand Down
7 changes: 7 additions & 0 deletions site/src/api/queries/workspaceBuilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ export const infiniteWorkspaceBuilds = (
},
};
};

export const workspaceBuildTimings = (workspaceBuildId: string) => {
return {
queryKey: ["workspaceBuilds", workspaceBuildId, "timings"],
queryFn: () => API.workspaceBuildTimings(workspaceBuildId),
};
};
105 changes: 105 additions & 0 deletions site/src/modules/workspaces/WorkspaceTiming/Chart/Bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import type { Interpolation, Theme } from "@emotion/react";
import { type ButtonHTMLAttributes, type HTMLProps, forwardRef } from "react";

export type BarColors = {
stroke: string;
fill: string;
};

type BaseBarProps<T> = Omit<T, "size" | "color"> & {
/**
* Scale used to determine the width based on the given value.
*/
scale: number;
value: number;
/**
* The X position of the bar component.
*/
offset: number;
/**
* Color scheme for the bar. If not passed the default gray color will be
* used.
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

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

I kept thinking the gray box was a checkbox 😆

I wonder if we could change the shape or default color a bit, but then again I might be the only one dumb enough not to realize it was the legend color.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lol, @chrifro wdyt?

Copy link

Choose a reason for hiding this comment

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

You are referring to the "state refresh" color right? Screenshot 2024-10-23 at 09 15 19

We could totally change that color. Either to orange if we also want to draw more attention to the "state refresh"
orange-bg: #431407
orange-stroke: #FDBA74 (we use the same color already on different views)

or if we want to keep it more subtle to grey
grey-bg: #18181B
grey-stroke: #71717A

something to keep in mind: the colors will likely slightly change as part of #14780. Then the difference between the newly introduced grey colors and the bg will be more obvious (see screenshot).
Screenshot 2024-10-23 at 09 41 58

Copy link
Member

@code-asher code-asher Oct 29, 2024

Choose a reason for hiding this comment

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

Sorry for the late reply, yes that is what I meant! When there are two or more, it is pretty obvious they are a legend, but with just one I thought it was supposed to be a checkbox, in particular the dark or grey ones. This might just be me being dumb though.

*/
colors?: BarColors;
};

type BarProps = BaseBarProps<HTMLProps<HTMLDivElement>>;

export const Bar = forwardRef<HTMLDivElement, BarProps>(
({ colors, scale, value, offset, ...htmlProps }, ref) => {
return (
<div
css={barCSS({ colors, scale, value, offset })}
{...htmlProps}
ref={ref}
/>
);
},
);

type ClickableBarProps = BaseBarProps<ButtonHTMLAttributes<HTMLButtonElement>>;

export const ClickableBar = forwardRef<HTMLButtonElement, ClickableBarProps>(
({ colors, scale, value, offset, ...htmlProps }, ref) => {
return (
<button
type="button"
css={[...barCSS({ colors, scale, value, offset }), styles.clickable]}
{...htmlProps}
ref={ref}
/>
);
},
);

export const barCSS = ({
scale,
value,
colors,
offset,
}: BaseBarProps<unknown>) => {
return [
styles.bar,
{
width: `calc((var(--x-axis-width) * ${value}) / ${scale})`,
backgroundColor: colors?.fill,
borderColor: colors?.stroke,
marginLeft: `calc((var(--x-axis-width) * ${offset}) / ${scale})`,
},
];
};

const styles = {
bar: (theme) => ({
border: "1px solid",
borderColor: theme.palette.divider,
backgroundColor: theme.palette.background.default,
borderRadius: 8,
// The bar should fill the row height.
height: "inherit",
display: "flex",
padding: 7,
minWidth: 24,
// Increase hover area
position: "relative",
"&::after": {
Copy link
Member

Choose a reason for hiding this comment

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

Neat trick!

content: '""',
position: "absolute",
top: -2,
right: -8,
bottom: -2,
left: -8,
},
}),
clickable: {
cursor: "pointer",
// We need to make the bar width at least 34px to allow the "..." icons to be displayed.
// The calculation is border * 1 + side paddings * 2 + icon width (which is 18px)
minWidth: 34,

"&:focus, &:hover, &:active": {
outline: "none",
borderColor: "#38BDF8",
},
},
} satisfies Record<string, Interpolation<Theme>>;
73 changes: 73 additions & 0 deletions site/src/modules/workspaces/WorkspaceTiming/Chart/Blocks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import type { Interpolation, Theme } from "@emotion/react";
import MoreHorizOutlined from "@mui/icons-material/MoreHorizOutlined";
import { type FC, useEffect, useRef, useState } from "react";

const spaceBetweenBlocks = 4;
const moreIconSize = 18;
const blockSize = 20;

type BlocksProps = {
count: number;
};

export const Blocks: FC<BlocksProps> = ({ count }) => {
const [availableWidth, setAvailableWidth] = useState<number>(0);
const blocksRef = useRef<HTMLDivElement>(null);

// Fix: When using useLayoutEffect, Chromatic fails to calculate the right width.
useEffect(() => {
if (availableWidth || !blocksRef.current) {
return;
}
setAvailableWidth(blocksRef.current.clientWidth);
}, [availableWidth]);

const totalSpaceBetweenBlocks = (count - 1) * spaceBetweenBlocks;
const necessarySize = blockSize * count + totalSpaceBetweenBlocks;
const hasSpacing = necessarySize <= availableWidth;
const nOfPossibleBlocks = Math.floor(
(availableWidth - moreIconSize) / (blockSize + spaceBetweenBlocks),
);
const nOfBlocks = hasSpacing ? count : nOfPossibleBlocks;

return (
<div ref={blocksRef} css={styles.blocks}>
{Array.from({ length: nOfBlocks }, (_, i) => i + 1).map((n) => (
<div key={n} css={styles.block} style={{ minWidth: blockSize }} />
))}
Comment on lines +35 to +37
Copy link
Member

Choose a reason for hiding this comment

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

Hopefully this is the right spot, but one thing that threw me off is that my template has five resources, and I saw five blue blocks, but only three of them show up in the chart when I click into the bar. Edit: I think because we filter Coder resources in the sub-chart but not the top-level chart.

It was also a little surprising that the blue blocks were all even width instead of matching up with their timings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

{!hasSpacing && (
<div css={styles.more}>
<MoreHorizOutlined />
</div>
)}
</div>
);
};

const styles = {
blocks: {
display: "flex",
width: "100%",
height: "100%",
gap: spaceBetweenBlocks,
alignItems: "center",
},
block: {
borderRadius: 4,
height: 18,
backgroundColor: "#082F49",
border: "1px solid #38BDF8",
flexShrink: 0,
flex: 1,
},
more: {
color: "#38BDF8",
lineHeight: 0,
flexShrink: 0,
flex: 1,

"& svg": {
fontSize: moreIconSize,
},
},
} satisfies Record<string, Interpolation<Theme>>;
Loading
Loading