-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUsersDataTableColumns.tsx
More file actions
141 lines (132 loc) · 3.95 KB
/
UsersDataTableColumns.tsx
File metadata and controls
141 lines (132 loc) · 3.95 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use client';
import Link from 'next/link';
import { OrganizationUsersData } from '@/app/(routegroups)/(orgroutes)/organizations/[organizationSlug]/users/(users-page)/page';
import { handleSort, renderSortIcons } from '@/components/utils';
import { Badge, Button, DataTableColumnDef, cn } from '@uselagoon/ui-library';
import { RemoveUser } from './_components/RemoveUser';
type User = OrganizationUsersData['users'][0];
const UsersDataTableColumns = (
orgId: number,
organizationSlug: string,
refetch?: () => void
): DataTableColumnDef<User>[] => [
{
accessorKey: 'firstName',
header: ({ column }) => {
const sortDirection = column.getIsSorted();
return (
<Button variant="ghost" onClick={() => handleSort(sortDirection, column)}>
First Name
<div className="flex flex-col">{renderSortIcons(sortDirection)}</div>
</Button>
);
},
},
{
accessorKey: 'lastName',
header: ({ column }) => {
const sortDirection = column.getIsSorted();
return (
<Button variant="ghost" onClick={() => handleSort(sortDirection, column)}>
Last Name
<div className="flex flex-col">{renderSortIcons(sortDirection)}</div>
</Button>
);
},
cell: ({ row }) => {
const { firstName, lastName, email } = row.original;
const isDefaultUser = !firstName && !lastName && email.startsWith('default-user');
return isDefaultUser ? <Badge>DEFAULT USER</Badge> : lastName;
},
},
{
accessorKey: 'email',
header: ({ column }) => {
const sortDirection = column.getIsSorted();
return (
<Button variant="ghost" onClick={() => handleSort(sortDirection, column)}>
Email
<div className="flex flex-col">{renderSortIcons(sortDirection)}</div>
</Button>
);
},
cell: ({ row }) => {
const { email } = row.original;
return (
<Link
className="hover:text-blue-800 transition-colors"
href={`/organizations/${organizationSlug}/users/${email}`}
>
{email}
</Link>
);
},
},
{
accessorKey: 'groupRoles',
header: 'Roles',
cell: ({ row }) => {
const groupRoles = row.original.groupRoles;
return (
<div className="flex flex-col gap-2">
{[...new Set(groupRoles.map(group => group.role))].map(uniqueRole => (
<Badge key={uniqueRole}>{uniqueRole}</Badge>
))}
</div>
);
},
},
{
id: 'Groups',
accessorFn: row => row.groupRoles?.length,
sortingFn: (rowA, rowB, columnId) => {
const a = rowA.getValue(columnId) as number;
const b = rowB.getValue(columnId) as number;
return a - b;
},
header: ({ column }) => {
const sortDirection = column.getIsSorted();
return (
<Button variant="ghost" onClick={() => handleSort(sortDirection, column)}>
Groups
<div className="flex flex-col">{renderSortIcons(sortDirection)}</div>
</Button>
);
},
cell: ({ row }) => {
const groupRoles = row.original.groupRoles;
return (
<div className="ml-4">
<Badge key={row.original.id}>{groupRoles?.length}</Badge>
</div>
);
},
},
{
accessorKey: 'attrs',
header: 'Attributes',
cell: ({ row }) => {
const has2faEnabled = row.original?.has2faEnabled;
const isFederatedUser = row.original?.isFederatedUser
return (
<div className="flex flex-col gap-2">
{has2faEnabled && (<Badge variant="success">2FA</Badge>)}
{isFederatedUser && (<Badge variant="info">SSO</Badge>)}
</div>
);
},
},
{
id: 'actions',
header: 'Actions',
cell: ({ row }) => {
const user = row.original;
return (
<div className="flex items-center gap-2">
<RemoveUser user={user} orgId={orgId!} refetch={refetch!} />
</div>
);
},
},
];
export default UsersDataTableColumns;