|
1 | 1 | import React from 'react'
|
2 | 2 | import MaterialTable from 'material-table'
|
| 3 | +import { Paper } from '@material-ui/core' |
3 | 4 | import UiRoleDetailPage from './UiRoleDetailPage'
|
4 | 5 | import { Badge } from 'reactstrap'
|
5 | 6 | import { connect } from 'react-redux'
|
| 7 | +import { Card, CardBody, FormGroup } from '../../../../app/components' |
6 | 8 | import { useTranslation } from 'react-i18next'
|
7 | 9 | import GluuViewWrapper from '../../../../app/routes/Apps/Gluu/GluuViewWrapper'
|
8 |
| -import { hasPermission, SCRIPT_READ } from '../../../../app/utils/PermChecker' |
| 10 | +import GluuRibbon from '../../../../app/routes/Apps/Gluu/GluuRibbon' |
| 11 | +import applicationStyle from '../../../../app/routes/Apps/Gluu/styles/applicationstyle' |
| 12 | +import { |
| 13 | + hasPermission, |
| 14 | + SCRIPT_READ, |
| 15 | + SCRIPT_WRITE, |
| 16 | +} from '../../../../app/utils/PermChecker' |
9 | 17 |
|
10 | 18 | function UiRoleListPage({ apiRoles, permissions, loading }) {
|
11 | 19 | const { t } = useTranslation()
|
| 20 | + const myActions = [] |
12 | 21 | const pageSize = localStorage.getItem('paggingSize') || 10
|
13 | 22 |
|
| 23 | + if (hasPermission(permissions, SCRIPT_READ)) { |
| 24 | + myActions.push((rowData) => ({ |
| 25 | + icon: 'visibility', |
| 26 | + iconProps: { |
| 27 | + color: 'primary', |
| 28 | + id: 'viewRole' + rowData.inum, |
| 29 | + }, |
| 30 | + tooltip: `${t('messages.view_role_details')}`, |
| 31 | + onClick: (e, rowData) => handleGoToRoleEditPage(rowData, true), |
| 32 | + disabled: false, |
| 33 | + })) |
| 34 | + } |
| 35 | + |
| 36 | + if (hasPermission(permissions, SCRIPT_WRITE)) { |
| 37 | + myActions.push((rowData) => ({ |
| 38 | + icon: 'edit', |
| 39 | + iconProps: { |
| 40 | + color: 'primary', |
| 41 | + id: 'editRole' + rowData.inum, |
| 42 | + }, |
| 43 | + tooltip: `${t('messages.edit_role')}`, |
| 44 | + onClick: (e, entry) => handleGoToRoleEditPage(entry, false), |
| 45 | + disabled: false, |
| 46 | + })) |
| 47 | + } |
| 48 | + if (hasPermission(permissions, SCRIPT_WRITE)) { |
| 49 | + myActions.push({ |
| 50 | + icon: 'add', |
| 51 | + tooltip: `${t('messages.add_role')}`, |
| 52 | + iconProps: { color: 'primary' }, |
| 53 | + isFreeAction: true, |
| 54 | + onClick: () => handleGoToRoleAddPage(), |
| 55 | + }) |
| 56 | + } |
| 57 | + |
14 | 58 | return (
|
15 |
| - <React.Fragment> |
16 |
| - <GluuViewWrapper canShow={hasPermission(permissions, SCRIPT_READ)}> |
17 |
| - <MaterialTable |
18 |
| - columns={[ |
19 |
| - { |
20 |
| - title: `${t('fields.name')}`, |
21 |
| - field: 'name', |
22 |
| - width: '20%', |
23 |
| - render: (rowData) => <Badge color="info">{rowData.name}</Badge>, |
24 |
| - }, |
25 |
| - { title: `${t('fields.description')}`, field: 'description' }, |
26 |
| - ]} |
27 |
| - data={apiRoles} |
28 |
| - isLoading={loading || false} |
29 |
| - title={t('titles.roles')} |
30 |
| - actions={[]} |
31 |
| - options={{ |
32 |
| - search: false, |
33 |
| - searchFieldAlignment: 'left', |
34 |
| - selection: false, |
35 |
| - pageSize: pageSize, |
36 |
| - rowStyle: (rowData) => ({ |
37 |
| - backgroundColor: rowData.enabled ? '#33AE9A' : '#FFF', |
38 |
| - }), |
39 |
| - headerStyle: { |
40 |
| - backgroundColor: '#03a96d', |
41 |
| - color: '#FFF', |
42 |
| - padding: '2px', |
43 |
| - textTransform: 'uppercase', |
44 |
| - fontSize: '18px', |
45 |
| - }, |
46 |
| - actionsColumnIndex: -1, |
47 |
| - }} |
48 |
| - detailPanel={(rowData) => { |
49 |
| - return <UiRoleDetailPage row={rowData} /> |
50 |
| - }} |
51 |
| - /> |
52 |
| - </GluuViewWrapper> |
53 |
| - </React.Fragment> |
| 59 | + <Card> |
| 60 | + <GluuRibbon title={t('titles.roles')} fromLeft /> |
| 61 | + <CardBody> |
| 62 | + <FormGroup row /> |
| 63 | + <FormGroup row /> |
| 64 | + <GluuViewWrapper canShow={hasPermission(permissions, SCRIPT_READ)}> |
| 65 | + <MaterialTable |
| 66 | + components={{ |
| 67 | + Container: (props) => <Paper {...props} elevation={0} />, |
| 68 | + }} |
| 69 | + columns={[ |
| 70 | + { |
| 71 | + title: `${t('fields.name')}`, |
| 72 | + field: 'name', |
| 73 | + width: '20%', |
| 74 | + render: (rowData) => <Badge color="info">{rowData.name}</Badge>, |
| 75 | + }, |
| 76 | + { title: `${t('fields.description')}`, field: 'description' }, |
| 77 | + ]} |
| 78 | + data={apiRoles} |
| 79 | + isLoading={loading || false} |
| 80 | + title="" |
| 81 | + actions={myActions} |
| 82 | + options={{ |
| 83 | + search: true, |
| 84 | + searchFieldAlignment: 'left', |
| 85 | + selection: false, |
| 86 | + pageSize: pageSize, |
| 87 | + rowStyle: (rowData) => ({ |
| 88 | + backgroundColor: rowData.enabled ? '#33AE9A' : '#FFF', |
| 89 | + }), |
| 90 | + headerStyle: applicationStyle.tableHeaderStyle, |
| 91 | + actionsColumnIndex: -1, |
| 92 | + }} |
| 93 | + detailPanel={(rowData) => { |
| 94 | + return <UiRoleDetailPage row={rowData} /> |
| 95 | + }} |
| 96 | + /> |
| 97 | + </GluuViewWrapper> |
| 98 | + </CardBody> |
| 99 | + </Card> |
54 | 100 | )
|
55 | 101 | }
|
56 | 102 |
|
|
0 commit comments