- Notifications
You must be signed in to change notification settings - Fork927
feat(site): add display for workspace timings#14773
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Uh oh!
There was an error while loading.Please reload this page.
Closed
Changes fromall commits
Commits
Show all changes
27 commits Select commitHold shift + click to select a range
5268b1e
Add base components for the chart
BrunoQuaresma4d509f9
Improve spacing calc
BrunoQuaresmad48624b
Make bars clickable
BrunoQuaresma62152ce
Refactor code to allow multiple views
BrunoQuaresmafd84ed9
Add basic view and breadcrumbs
BrunoQuaresmaf7f09ff
Add resource filtering
BrunoQuaresma2ffc75a
Find the right tick spacings
BrunoQuaresmaa8372e1
Add colors to the bars
BrunoQuaresmaf7c7488
Do not display Coder resource
BrunoQuaresma0868185
Add legends
BrunoQuaresma54d13c8
Handle empty search
BrunoQuaresma714e37b
Improve coder resource filter and adjust bar hover
BrunoQuaresmaa2dd126
Only scroll the chart
BrunoQuaresma0b4747e
Add tooltip
BrunoQuaresma49d3a72
Refactor code and improve legends
BrunoQuaresma647635d
Adjust columns to fit the space
BrunoQuaresma6c742aa
Customize scroll
BrunoQuaresma9a8bb59
Add info tooltip
BrunoQuaresma4139151
Fix fmt
BrunoQuaresmabcff9c6
Fix nblock gen
BrunoQuaresma97b25d9
Fix key
BrunoQuaresma6d5c344
Debug on chromatic
BrunoQuaresmac4bd74e
Another debug image
BrunoQuaresma939ec9a
Try with useEffect
BrunoQuaresma49c69e0
Fix labels alignment
BrunoQuaresma61008a3
Increase border radius tooltip
BrunoQuaresmaf969ef2
Add scroll mask
BrunoQuaresmaFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletionssite/src/modules/workspaces/WorkspaceTiming/Chart/Bar.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import type { Interpolation, Theme } from "@emotion/react"; | ||
import { type ButtonHTMLAttributes, type HTMLProps, forwardRef } from "react"; | ||
import { CSSVars } from "./constants"; | ||
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. | ||
*/ | ||
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(${CSSVars.xAxisWidth}) * ${value}) / ${scale})`, | ||
backgroundColor: colors?.fill, | ||
borderColor: colors?.stroke, | ||
marginLeft: `calc((var(${CSSVars.xAxisWidth}) * ${offset}) / ${scale})`, | ||
}, | ||
]; | ||
}; | ||
const styles = { | ||
bar: (theme) => ({ | ||
border: "1px solid", | ||
borderColor: theme.palette.divider, | ||
backgroundColor: theme.palette.background.default, | ||
borderRadius: 8, | ||
height: 32, | ||
display: "flex", | ||
padding: 0, | ||
minWidth: 8, | ||
}), | ||
clickable: { | ||
cursor: "pointer", | ||
"&:focus, &:hover, &:active": { | ||
outline: "none", | ||
borderColor: "#38BDF8", | ||
}, | ||
}, | ||
} satisfies Record<string, Interpolation<Theme>>; |
77 changes: 77 additions & 0 deletionssite/src/modules/workspaces/WorkspaceTiming/Chart/BarBlocks.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import type { Interpolation, Theme } from "@emotion/react"; | ||
import MoreHorizOutlined from "@mui/icons-material/MoreHorizOutlined"; | ||
import { type FC, useEffect, useRef, useState } from "react"; | ||
const sidePadding = 8; | ||
const spaceBetweenBlocks = 4; | ||
const moreIconSize = 18; | ||
const blockSize = 20; | ||
type BarBlocksProps = { | ||
count: number; | ||
}; | ||
export const BarBlocks: FC<BarBlocksProps> = ({ count }) => { | ||
const [parentWidth, setParentWidth] = useState<number>(); | ||
const blocksRef = useRef<HTMLDivElement>(null); | ||
useEffect(() => { | ||
if (!blocksRef.current || parentWidth) { | ||
return; | ||
} | ||
const parentEl = blocksRef.current.parentElement; | ||
if (!parentEl) { | ||
throw new Error("BarBlocks must be a child of a Bar"); | ||
} | ||
setParentWidth(parentEl.clientWidth); | ||
}, [parentWidth]); | ||
const totalSpaceBetweenBlocks = (count - 1) * spaceBetweenBlocks; | ||
const freeSize = parentWidth ? parentWidth - sidePadding * 2 : 0; | ||
const necessarySize = blockSize * count + totalSpaceBetweenBlocks; | ||
const hasSpacing = necessarySize <= freeSize; | ||
const nOfPossibleBlocks = Math.floor( | ||
(freeSize - 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 }} /> | ||
))} | ||
{!hasSpacing && ( | ||
<div css={styles.extraBlock}> | ||
<MoreHorizOutlined /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
const styles = { | ||
blocks: { | ||
display: "flex", | ||
width: "100%", | ||
height: "100%", | ||
padding: sidePadding, | ||
gap: spaceBetweenBlocks, | ||
alignItems: "center", | ||
}, | ||
block: { | ||
borderRadius: 4, | ||
height: 16, | ||
backgroundColor: "#082F49", | ||
border: "1px solid #38BDF8", | ||
flexShrink: 0, | ||
}, | ||
extraBlock: { | ||
color: "#38BDF8", | ||
lineHeight: 0, | ||
flexShrink: 0, | ||
"& svg": { | ||
fontSize: moreIconSize, | ||
}, | ||
}, | ||
} satisfies Record<string, Interpolation<Theme>>; |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.