-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathGroupMembersSideModal.tsx
More file actions
108 lines (102 loc) · 3.56 KB
/
GroupMembersSideModal.tsx
File metadata and controls
108 lines (102 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { useQuery } from '@tanstack/react-query'
import { api, q, type Group, type Policy, type User } from '@oxide/api'
import { PersonGroup16Icon, PersonGroup24Icon } from '@oxide/design-system/icons/react'
import { Badge } from '@oxide/design-system/ui'
import { ReadOnlySideModalForm } from '~/components/form/ReadOnlySideModalForm'
import { RowActions } from '~/table/columns/action-col'
import { EmptyMessage } from '~/ui/lib/EmptyMessage'
import { PropertiesTable } from '~/ui/lib/PropertiesTable'
import { ResourceLabel } from '~/ui/lib/SideModal'
import { Table } from '~/ui/lib/Table'
import { roleColor } from '~/util/access'
import { ALL_ISH } from '~/util/consts'
type Props = {
group: Group
onDismiss: () => void
policy: Policy
}
export function GroupMembersSideModal({ group, onDismiss, policy }: Props) {
const { data } = useQuery(q(api.userList, { query: { group: group.id, limit: ALL_ISH } }))
const members = data?.items ?? []
const assignment = policy.roleAssignments.find((ra) => ra.identityId === group.id)
return (
<ReadOnlySideModalForm
title="Group"
subtitle={
<ResourceLabel>
<PersonGroup16Icon /> {group.displayName}
</ResourceLabel>
}
onDismiss={onDismiss}
animate
>
<PropertiesTable>
<PropertiesTable.IdRow id={group.id} />
<PropertiesTable.DateRow label="Created" date={group.timeCreated} />
</PropertiesTable>
<div className="mt-6">
<table className="ox-table text-sans-md w-full border-separate">
<Table.Header>
<Table.HeaderRow>
<Table.HeadCell>Role</Table.HeadCell>
<Table.HeadCell>Source</Table.HeadCell>
</Table.HeaderRow>
</Table.Header>
<Table.Body>
{!assignment ? (
<Table.Row>
<Table.Cell colSpan={2} className="text-secondary">
No roles assigned
</Table.Cell>
</Table.Row>
) : (
<Table.Row>
<Table.Cell>
<Badge color={roleColor[assignment.roleName]}>
silo.{assignment.roleName}
</Badge>
</Table.Cell>
<Table.Cell>Assigned</Table.Cell>
</Table.Row>
)}
</Table.Body>
</table>
</div>
<div className="mt-6">
{members.length === 0 ? (
<EmptyMessage
icon={<PersonGroup24Icon />}
title="No members"
body="This group has no members"
/>
) : (
<table className="ox-table text-sans-md w-full border-separate">
<Table.Header>
<Table.HeaderRow>
<Table.HeadCell>Members</Table.HeadCell>
<Table.HeadCell />
</Table.HeaderRow>
</Table.Header>
<Table.Body>
{members.map((member: User) => (
<Table.Row key={member.id}>
<Table.Cell>{member.displayName}</Table.Cell>
<Table.Cell className="action-col w-10 *:p-0">
<RowActions id={member.id} />
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</table>
)}
</div>
</ReadOnlySideModalForm>
)
}