Добавлена страница управления правами

This commit is contained in:
Александр Сироткин 2021-12-21 15:46:05 +05:00
parent 7ffab81c33
commit 3c4b98366d
2 changed files with 74 additions and 9 deletions

View File

@ -0,0 +1,60 @@
import { useEffect, useState } from 'react'
import { invokeWebApiWrapperAsync } from '../../components/factory'
import LoaderPortal from '../../components/LoaderPortal'
import {
EditableTable,
makeActionHandler,
makeColumn,
makeStringSorter
} from '../../components/Table'
import { AdminPermissionService } from '../../services/api'
const columns = [
makeColumn('Название', 'name', {
editable: true,
sorter: makeStringSorter('name'),
}),
makeColumn('Описание', 'description', {
editable: true,
sorter: makeStringSorter('description'),
}),
]
export const PermissionController = () => {
const [showLoader, setShowLoader] = useState(false)
const [permissions, setPermissions] = useState([])
const updateTable = () => invokeWebApiWrapperAsync(
async () => {
const permission = await AdminPermissionService.getAll()
setPermissions(permission ?? [])
},
setShowLoader,
`Не удалось загрузить список прав`
)
useEffect(updateTable, [])
const handlerProps = {
service: AdminPermissionService,
setLoader: setShowLoader,
errorMsg: `Не удалось выполнить операцию`,
onComplete: updateTable
}
return (
<LoaderPortal show={showLoader}>
<EditableTable
bordered
size={'small'}
columns={columns}
dataSource={permissions}
onRowAdd={makeActionHandler('insert', handlerProps)}
onRowEdit={makeActionHandler('update', handlerProps)}
onRowDelete={makeActionHandler('delete', handlerProps)}
/>
</LoaderPortal>
)
}
export default PermissionController

View File

@ -9,6 +9,7 @@ const DepositController = lazy(() => import('./DepositController'))
const UserController = lazy(() => import('./UserController'))
const WellController = lazy(() => import('./WellController'))
const RoleController = lazy(() => import('./RoleController'))
const PermissionController = lazy(() => import('./PermissionController'))
const VisitLog = lazy(() => import('./VisitLog'))
export const AdminPanel = () => {
@ -34,9 +35,12 @@ export const AdminPanel = () => {
<Link to={`${rootPath}/company`}>Компании</Link>
</PrivateMenuItem>
<PrivateMenuItem key={'role'} permission={'role_editor'}>
<Link to={`${rootPath}/role`}>Права</Link>
<Link to={`${rootPath}/role`}>Роли</Link>
</PrivateMenuItem>
<PrivateMenuItem key={'visit_log'} permission={'visit_log'}>
<PrivateMenuItem key={'permission'} permission={'permission_editor'}>
<Link to={`${rootPath}/permission`}>Права</Link>
</PrivateMenuItem>
<PrivateMenuItem key={'visit_log'}>
<Link to={`${rootPath}/visit_log`}>Журнал посещений</Link>
</PrivateMenuItem>
</Menu>
@ -45,13 +49,14 @@ export const AdminPanel = () => {
<Layout.Content className={'site-layout-background'}>
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<PrivateRoute permission={'deposit_editor'} path={`${rootPath}/deposit` } component={DepositController} />
<PrivateRoute permission={'cluster_editor'} path={`${rootPath}/cluster` } component={ClusterController} />
<PrivateRoute permission={ 'deposit_editor'} path={`${rootPath}/deposit` } component={ DepositController} />
<PrivateRoute permission={ 'cluster_editor'} path={`${rootPath}/cluster` } component={ ClusterController} />
<PrivateRoute permission={ 'well_editor'} path={`${rootPath}/well` } component={ WellController} />
<PrivateRoute permission={ 'user_editor'} path={`${rootPath}/user` } component={ UserController} />
<PrivateRoute permission={'company_editor'} path={`${rootPath}/company` } component={CompanyController} />
<PrivateRoute permission={ 'company_editor'} path={`${rootPath}/company` } component={ CompanyController} />
<PrivateRoute permission={ 'role_editor'} path={`${rootPath}/role` } component={ RoleController} />
<PrivateRoute permission={ 'visit_log'} path={`${rootPath}/visit_log`} component={ VisitLog} />
<PrivateRoute permission={'permission_editor'} path={`${rootPath}/permission`} component={PermissionController} />
<PrivateRoute path={`${rootPath}/visit_log`} component={VisitLog} />
<Route path={'/'}>
<Redirect to={`${rootPath}/deposit`}/>
</Route>