forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
122 lines (115 loc) · 3.81 KB
/
index.tsx
File metadata and controls
122 lines (115 loc) · 3.81 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
import { useEffect, useMemo } from 'react';
import { useIntl } from '@edx/frontend-platform/i18n';
import debounce from 'lodash.debounce';
import {
Container, DataTable,
} from '@openedx/paragon';
import TableFooter from '@src/authz-module/components/TableFooter/TableFooter';
import { AUTHZ_HOME_PATH, TABLE_DEFAULT_PAGE_SIZE } from '@src/authz-module/constants';
import AuthZLayout from '@src/authz-module/components/AuthZLayout';
import { useNavigate, useParams } from 'react-router-dom';
import { useUserAccount } from '@src/data/hooks';
import baseMessages from '@src/authz-module/messages';
import AddRoleButton from '@src/authz-module/components/AddRoleButton';
import {
OrgCell, RoleCell, ScopeCell, PermissionsCell, ViewAllPermissionsCell, ActionsCell,
} from '@src/authz-module/components/TableCells';
import { useQuerySettings } from '@src/authz-module/hooks/useQuerySettings';
import { useUserAssignedRoles } from '@src/authz-module/data/hooks';
import messages from './messages';
const AuditUserPage = () => {
const { formatMessage } = useIntl();
const { username } = useParams();
const navigate = useNavigate();
const { isLoading: isLoadingUser, data: user } = useUserAccount(username ?? '');
const { querySettings, handleTableFetch } = useQuerySettings();
const { isLoading: isLoadingUserAssignments, data: { results: userAssignments, count } = { results: [], count: 0 } } = useUserAssignedRoles(username ?? '', querySettings);
useEffect(() => {
if (!user && !isLoadingUser) {
navigate(AUTHZ_HOME_PATH);
}
}, [user, isLoadingUser, navigate]);
const navLinks = [
{
label: formatMessage(baseMessages['authz.management.home.nav.link']),
to: AUTHZ_HOME_PATH,
},
];
const additionalColumns = [
{
id: 'view_permissions',
Header: '',
Cell: ViewAllPermissionsCell,
},
{
id: 'action',
Header: formatMessage(messages['authz.user.table.action.column.header']),
Cell: ActionsCell,
},
];
const columns = [
{
Header: formatMessage(messages['authz.user.table.role.column.header']),
accessor: 'role',
Cell: RoleCell,
},
{
Header: formatMessage(messages['authz.user.table.organization.column.header']),
accessor: 'org',
Cell: OrgCell,
},
{
Header: formatMessage(messages['authz.user.table.scope.column.header']),
accessor: 'scope',
Cell: ScopeCell,
disableFilters: true,
},
{
Header: formatMessage(messages['authz.user.table.permissions.column.header']),
Cell: PermissionsCell,
disableFilters: true,
disableSortBy: true,
},
];
const pageCount = Math.ceil(count / TABLE_DEFAULT_PAGE_SIZE);
const fetchData = useMemo(() => debounce(handleTableFetch, 500), [handleTableFetch]);
return (
<div className="authz-module">
<AuthZLayout
context={{
id: '',
org: '',
title: '',
}}
navLinks={navLinks}
activeLabel={username || ''}
pageTitle={user?.username || ''}
pageSubtitle={user?.email || ''}
actions={
[
<AddRoleButton presetUsername={user?.username} key="add-role-button" />,
]
}
>
<Container className="bg-light-200 p-5">
<DataTable
isPaginated
manualPagination
data={userAssignments}
fetchData={fetchData}
itemCount={count}
pageCount={pageCount}
initialState={{ pageSize: TABLE_DEFAULT_PAGE_SIZE }}
additionalColumns={additionalColumns}
columns={columns}
isLoading={isLoadingUserAssignments}
>
<DataTable.Table />
<TableFooter />
</DataTable>
</Container>
</AuthZLayout>
</div>
);
};
export default AuditUserPage;