Skip to content

Commit 158ac78

Browse files
committed
wip
1 parent 8931a23 commit 158ac78

File tree

6 files changed

+49
-18
lines changed

6 files changed

+49
-18
lines changed

codersdk/workspacequota.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package codersdk
2+
3+
type UserWorkspaceQuota struct {
4+
Count int `json:"count"`
5+
Limit int `json:"limit"`
6+
}

site/src/api/typesGenerated.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,12 @@ export interface UserRoles {
521521
readonly organization_roles: Record<string, string[]>
522522
}
523523

524+
// From codersdk/workspacequota.go
525+
export interface UserWorkspaceQuota {
526+
readonly count: number
527+
readonly limit: number
528+
}
529+
524530
// From codersdk/users.go
525531
export interface UsersRequest extends Pagination {
526532
readonly q?: string

site/src/components/Navbar/Navbar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export const Navbar: React.FC = () => {
1616
)
1717
const canViewAuditLog =
1818
featureVisibility[FeatureNames.AuditLog] && Boolean(permissions?.viewAuditLog)
19+
const canViewWorkspaceQuota = featureVisibility[FeatureNames.WorkspaceQuota]
1920
const onSignOut = () => authSend("SIGN_OUT")
2021

21-
return <NavbarView user={me} onSignOut={onSignOut} canViewAuditLog={canViewAuditLog} />
22+
return <NavbarView user={me} onSignOut={onSignOut} canViewAuditLog={canViewAuditLog} canViewWorkspaceQuota={canViewWorkspaceQuota}/>
2223
}

site/src/components/NavbarView/NavbarView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface NavbarViewProps {
1919
user?: TypesGen.User
2020
onSignOut: () => void
2121
canViewAuditLog: boolean
22+
canViewWorkspaceQuota: boolean
2223
}
2324

2425
export const Language = {
@@ -71,6 +72,7 @@ export const NavbarView: React.FC<React.PropsWithChildren<NavbarViewProps>> = ({
7172
user,
7273
onSignOut,
7374
canViewAuditLog,
75+
canViewWorkspaceQuota,
7476
}) => {
7577
const styles = useStyles()
7678
const [isDrawerOpen, setIsDrawerOpen] = useState(false)
@@ -109,7 +111,7 @@ export const NavbarView: React.FC<React.PropsWithChildren<NavbarViewProps>> = ({
109111
</div>
110112
<Stack direction="row" className={styles.profileButton}>
111113
<div className={styles.quota}>
112-
<WorkspaceQuota count={1} limit={2} />
114+
<WorkspaceQuota />
113115
</div>
114116

115117
<div className={styles.profileButton}>

site/src/components/WorkspaceQuota/WorkspaceQuota.stories.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,29 @@ const Template: Story<WorkspaceQuotaProps> = (args) => <WorkspaceQuota {...args}
1010

1111
export const Example = Template.bind({})
1212
Example.args = {
13-
count: 1,
14-
limit: 3,
13+
quota: {
14+
count: 1,
15+
limit: 3,
16+
}
1517
}
1618

1719
export const LimitOf1 = Template.bind({})
1820
LimitOf1.args = {
19-
count: 1,
20-
limit: 1,
21+
quota: {
22+
count: 1,
23+
limit: 1,
24+
}
2125
}
2226

2327
export const Loading = Template.bind({})
2428
Loading.args = {
25-
count: undefined,
26-
limit: undefined,
29+
quota: undefined
30+
}
31+
32+
export const Disabled = Template.bind({})
33+
Disabled.args = {
34+
quota: {
35+
count: 1,
36+
limit: 0,
37+
}
2738
}

site/src/components/WorkspaceQuota/WorkspaceQuota.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import Skeleton from "@material-ui/lab/Skeleton"
55
import { Stack } from "components/Stack/Stack"
66
import { FC } from "react"
77
import { MONOSPACE_FONT_FAMILY } from "../../theme/constants"
8+
import * as TypesGen from "../../api/typesGenerated"
89

910
export const Language = {
1011
of: "of",
11-
workspaceUsed: "workspace used",
12-
workspacesUsed: "workspaces used",
12+
workspace: "workspace",
13+
workspaces: "workspaces",
1314
}
1415

1516
export interface WorkspaceQuotaProps {
16-
count?: number
17-
limit?: number
17+
quota?: TypesGen.UserWorkspaceQuota
1818
}
1919

20-
export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ count, limit }) => {
20+
export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ quota }) => {
2121
const styles = useStyles()
2222

2323
// loading state
24-
if (count === undefined || limit === undefined) {
24+
if (quota === undefined) {
2525
return (
2626
<Box>
2727
<Stack spacing={1} className={styles.stack}>
@@ -34,9 +34,14 @@ export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ count, limit }) => {
3434
)
3535
}
3636

37-
let value = Math.round((count / limit) * 100)
37+
// don't show if limit is 0, this means the feature is disabled.
38+
if (quota.limit === 0) {
39+
return (<></>)
40+
}
41+
42+
let value = Math.round((quota.count / quota.limit) * 100)
3843
// we don't want to round down to zero if the count is > 0
39-
if (count > 0 && value === 0) {
44+
if (quota.count > 0 && value === 0) {
4045
value = 1
4146
}
4247

@@ -45,8 +50,8 @@ export const WorkspaceQuota: FC<WorkspaceQuotaProps> = ({ count, limit }) => {
4550
<Stack spacing={1} className={styles.stack}>
4651
<LinearProgress value={value} variant="determinate" color="primary" />
4752
<div className={styles.label}>
48-
{count} {Language.of} {limit}{" "}
49-
{limit === 1 ? Language.workspaceUsed : Language.workspacesUsed}
53+
{quota.count} {Language.of} {quota.limit}{" "}
54+
{quota.limit === 1 ? Language.workspace : Language.workspaces}{" used"}
5055
</div>
5156
</Stack>
5257
</Box>

0 commit comments

Comments
 (0)