Skip to content

Commit 8b5e834

Browse files
committed
add storybook
1 parent 405e91d commit 8b5e834

File tree

3 files changed

+67
-37
lines changed

3 files changed

+67
-37
lines changed

site/src/components/NavbarView/NavbarView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const NavbarView: React.FC<React.PropsWithChildren<NavbarViewProps>> = ({
109109
</div>
110110
<Stack direction="row" className={styles.profileButton}>
111111
<div className={styles.quota} >
112-
<WorkspaceQuota loading={false} count={1} limit={0}/>
112+
<WorkspaceQuota count={1} limit={2}/>
113113
</div>
114114

115115
<div className={styles.profileButton}>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Story } from "@storybook/react"
2+
import { WorkspaceQuota, WorkspaceQuotaProps } from "./WorkspaceQuota"
3+
4+
export default {
5+
title: "components/WorkspaceQuota",
6+
component: WorkspaceQuota,
7+
}
8+
9+
const Template: Story<WorkspaceQuotaProps> = (args) => <WorkspaceQuota {...args} />
10+
11+
export const Example = Template.bind({})
12+
Example.args = {
13+
count: 1,
14+
limit: 3,
15+
}
16+
17+
export const LimitOf1 = Template.bind({})
18+
LimitOf1.args = {
19+
count: 1,
20+
limit: 1,
21+
}
22+
23+
export const Loading = Template.bind({})
24+
Loading.args = {
25+
count: undefined,
26+
limit: undefined,
27+
}
28+
29+

site/src/components/WorkspaceQuota/WorkspaceQuota.tsx

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,64 @@ import Skeleton from '@material-ui/lab/Skeleton';
66
import { Stack } from 'components/Stack/Stack';
77
import Box from "@material-ui/core/Box";
88

9+
export const Language = {
10+
of: "of",
11+
workspaceUsed: "workspace used",
12+
workspacesUsed: "workspaces used",
13+
}
14+
915
export interface WorkspaceQuotaProps {
10-
loading: boolean
1116
count?: number
1217
limit?: number
1318
}
1419

15-
export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ loading, count, limit }) => {
20+
export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ count, limit }) => {
1621
const styles = useStyles()
1722

18-
const safeCount = count ? count : 0;
19-
const safeLimit = limit ? limit : 100;
20-
let value = Math.round((safeCount / safeLimit) * 100)
23+
// loading state
24+
if (count === undefined || limit === undefined) {
25+
return (
26+
<Box>
27+
<Stack spacing={1} className={styles.stack}>
28+
<LinearProgress
29+
color="primary"
30+
/>
31+
<div className={styles.label}>
32+
<Skeleton className={styles.skeleton}/>
33+
</div>
34+
</Stack>
35+
</Box>
36+
)
37+
}
38+
39+
let value = Math.round((count / limit) * 100)
2140
// we don't want to round down to zero if the count is > 0
22-
if (safeCount > 0 && value === 0) {
41+
if (count > 0 && value === 0) {
2342
value = 1
2443
}
25-
const limitLanguage = limit ? limit : (<span className={styles.infinity}></span>)
2644

2745
return (
2846
<Box>
29-
<Stack spacing={1} className={styles.schedule}>
30-
{loading ? (
31-
<>
32-
<LinearProgress
33-
value={value}
34-
color="primary"
35-
/>
36-
<div className={styles.scheduleLabel}>
37-
<Skeleton className={styles.skeleton}/>
38-
</div>
39-
</>
40-
) : (
41-
<>
42-
<LinearProgress
43-
value={value}
44-
variant="determinate"
45-
color="primary"
46-
/>
47-
<div className={styles.scheduleLabel}>
48-
{safeCount} of {limitLanguage} workspaces used
49-
</div>
50-
</>
51-
)}
47+
<Stack spacing={1} className={styles.stack}>
48+
<LinearProgress
49+
value={value}
50+
variant="determinate"
51+
color="primary"
52+
/>
53+
<div className={styles.label}>
54+
{count} {Language.of} {limit} {limit === 1 ? Language.workspaceUsed : Language.workspacesUsed }
55+
</div>
5256
</Stack>
5357
</Box>
5458
)
5559
}
5660

5761
const useStyles = makeStyles((theme) => ({
58-
schedule: {
59-
fontFamily: MONOSPACE_FONT_FAMILY,
62+
stack: {
6063
display: 'inline-flex',
6164
},
62-
scheduleLabel: {
65+
label: {
66+
fontFamily: MONOSPACE_FONT_FAMILY,
6367
fontSize: 12,
6468
textTransform: "uppercase",
6569
display: "block",
@@ -69,7 +73,4 @@ const useStyles = makeStyles((theme) => ({
6973
skeleton: {
7074
minWidth: "150px",
7175
},
72-
infinity: {
73-
fontSize: 18,
74-
},
7576
}))

0 commit comments

Comments
 (0)