Skip to content

Commit 0ed9587

Browse files
committed
turn accessTypeLabel and getBadgeColor functions into records
1 parent 420174b commit 0ed9587

File tree

4 files changed

+15
-37
lines changed

4 files changed

+15
-37
lines changed

app/pages/SiloAccessPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { Button } from '~/ui/lib/Button'
3535
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
3636
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
3737
import { TableActions, TableEmptyBox } from '~/ui/lib/Table'
38-
import { accessTypeLabel, getBadgeColor } from '~/util/access'
38+
import { identityTypeLabel, roleColor } from '~/util/access'
3939
import { groupBy, isTruthy } from '~/util/array'
4040

4141
const EmptyState = ({ onClick }: { onClick: () => void }) => (
@@ -114,13 +114,13 @@ export function SiloAccessPage() {
114114
colHelper.accessor('name', { header: 'Name' }),
115115
colHelper.accessor('identityType', {
116116
header: 'Type',
117-
cell: (props) => accessTypeLabel(props.getValue()),
117+
cell: (props) => identityTypeLabel[props.getValue()],
118118
}),
119119
colHelper.accessor('siloRole', {
120120
header: 'Role',
121121
cell: (props) => {
122122
const role = props.getValue()
123-
return role ? <Badge color={getBadgeColor(role)}>silo.{role}</Badge> : null
123+
return role ? <Badge color={roleColor[role]}>silo.{role}</Badge> : null
124124
},
125125
}),
126126
// TODO: tooltips on disabled elements explaining why

app/pages/project/access/ProjectAccessPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { EmptyMessage } from '~/ui/lib/EmptyMessage'
4040
import { PageHeader, PageTitle } from '~/ui/lib/PageHeader'
4141
import { TableActions, TableEmptyBox } from '~/ui/lib/Table'
4242
import { TipIcon } from '~/ui/lib/TipIcon'
43-
import { accessTypeLabel, getBadgeColor } from '~/util/access'
43+
import { identityTypeLabel, roleColor } from '~/util/access'
4444
import { groupBy, isTruthy, sortBy } from '~/util/array'
4545

4646
const EmptyState = ({ onClick }: { onClick: () => void }) => (
@@ -128,7 +128,7 @@ export function ProjectAccessPage() {
128128
colHelper.accessor('name', { header: 'Name' }),
129129
colHelper.accessor('identityType', {
130130
header: 'Type',
131-
cell: (props) => accessTypeLabel(props.getValue()),
131+
cell: (props) => identityTypeLabel[props.getValue()],
132132
}),
133133
colHelper.accessor('roleBadges', {
134134
header: () => (
@@ -143,7 +143,7 @@ export function ProjectAccessPage() {
143143
cell: (props) => (
144144
<ListPlusCell tooltipTitle="Other roles">
145145
{props.getValue().map(({ roleName, roleSource }) => (
146-
<Badge key={roleSource} color={getBadgeColor(roleName)}>
146+
<Badge key={roleSource} color={roleColor[roleName]}>
147147
{roleSource}.{roleName}
148148
</Badge>
149149
))}

app/util/access.spec.tsx

Lines changed: 0 additions & 21 deletions
This file was deleted.

app/util/access.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
* Copyright Oxide Computer Company
77
*/
88

9-
import type { IdentityType } from '~/api'
9+
import type { IdentityType, RoleKey } from '~/api'
1010
import type { BadgeColor } from '~/ui/lib/Badge'
1111

12-
export const accessTypeLabel = (identityType: IdentityType) =>
13-
identityType === 'silo_group' ? 'Group' : 'User'
12+
export const identityTypeLabel: Record<IdentityType, string> = {
13+
silo_group: 'Group',
14+
silo_user: 'User',
15+
}
1416

15-
export const getBadgeColor = (role: 'admin' | 'collaborator' | 'viewer'): BadgeColor => {
16-
const badgeColor = {
17-
admin: 'default',
18-
collaborator: 'purple',
19-
viewer: 'blue',
20-
}
21-
return badgeColor[role] as BadgeColor
17+
export const roleColor: Record<RoleKey, BadgeColor> = {
18+
admin: 'default',
19+
collaborator: 'purple',
20+
viewer: 'blue',
2221
}

0 commit comments

Comments
 (0)