1
- import React , { useEffect } from 'react'
1
+ import React , { useEffect , useState } from 'react'
2
2
import MaterialTable from 'material-table'
3
3
import { Paper } from '@material-ui/core'
4
4
import UiPermDetailPage from './UiPermDetailPage'
@@ -9,7 +9,12 @@ import { useTranslation } from 'react-i18next'
9
9
import GluuViewWrapper from '../../../../app/routes/Apps/Gluu/GluuViewWrapper'
10
10
import GluuRibbon from '../../../../app/routes/Apps/Gluu/GluuRibbon'
11
11
import applicationStyle from '../../../../app/routes/Apps/Gluu/styles/applicationstyle'
12
- import { getPermissions } from '../../redux/actions/ApiPermissionActions'
12
+ import {
13
+ getPermissions ,
14
+ deletePermission ,
15
+ editPermission ,
16
+ addPermission ,
17
+ } from '../../redux/actions/ApiPermissionActions'
13
18
import {
14
19
hasPermission ,
15
20
buildPayload ,
@@ -19,50 +24,39 @@ import {
19
24
20
25
function UiPermListPage ( { apiPerms, permissions, loading, dispatch } ) {
21
26
const { t } = useTranslation ( )
27
+ const [ modal , setModal ] = useState ( false )
28
+ const toggle = ( ) => setModal ( ! modal )
22
29
const myActions = [ ]
23
30
const options = [ ]
24
31
const userAction = { }
25
32
const pageSize = localStorage . getItem ( 'paggingSize' ) || 10
26
33
useEffect ( ( ) => {
27
- buildPayload ( userAction , 'PERMISSIONS' , options )
28
- dispatch ( getPermissions ( userAction ) )
34
+ doFetchList ( )
29
35
} , [ ] )
30
36
31
- if ( hasPermission ( permissions , PERMISSION_READ ) ) {
32
- myActions . push ( ( aRow ) => ( {
33
- icon : 'visibility' ,
34
- iconProps : {
35
- color : 'primary' ,
36
- id : 'viewRole' + aRow . inum ,
37
- } ,
38
- tooltip : `${ t ( 'messages.view_role_details' ) } ` ,
39
- onClick : ( e , v ) => handleGoToPermissionEditPage ( v , true ) ,
40
- disabled : false ,
41
- } ) )
42
- }
43
-
44
- if ( hasPermission ( permissions , PERMISSION_WRITE ) ) {
45
- myActions . push ( ( rowD ) => ( {
46
- icon : 'edit' ,
47
- iconProps : {
48
- color : 'primary' ,
49
- id : 'editRole' + rowD . inum ,
50
- } ,
51
- tooltip : `${ t ( 'messages.edit_role' ) } ` ,
52
- onClick : ( e , entry ) => handleGoToPermissionEditPage ( entry , false ) ,
53
- disabled : false ,
54
- } ) )
55
- }
56
37
if ( hasPermission ( permissions , PERMISSION_WRITE ) ) {
57
38
myActions . push ( {
58
39
icon : 'add' ,
59
- tooltip : `${ t ( 'messages.add_role ' ) } ` ,
40
+ tooltip : `${ t ( 'messages.add_permission ' ) } ` ,
60
41
iconProps : { color : 'primary' } ,
61
42
isFreeAction : true ,
62
- onClick : ( ) => handleGoToPermissionAddPage ( ) ,
43
+ onClick : ( ) => handleAddNewPermission ( ) ,
63
44
} )
64
45
}
65
46
47
+ function handleAddNewPermission ( ) {
48
+ toggle ( )
49
+ }
50
+ function doFetchList ( ) {
51
+ buildPayload ( userAction , 'PERMISSIONS' , options )
52
+ dispatch ( getPermissions ( userAction ) )
53
+ }
54
+ function onAddConfirmed ( roleData ) {
55
+ buildPayload ( userAction , 'message' , roleData )
56
+ dispatch ( addPermission ( userAction ) )
57
+ toggle ( )
58
+ doFetchList ( )
59
+ }
66
60
return (
67
61
< Card >
68
62
< GluuRibbon title = { t ( 'titles.roles' ) } fromLeft />
@@ -78,12 +72,13 @@ function UiPermListPage({ apiPerms, permissions, loading, dispatch }) {
78
72
{
79
73
title : `${ t ( 'fields.name' ) } ` ,
80
74
field : 'permission' ,
75
+ editable : false ,
81
76
width : '50%' ,
82
77
render : ( rowData ) => (
83
78
< Badge color = "info" > { rowData . permission } </ Badge >
84
79
) ,
85
80
} ,
86
- // { title: `${t('fields.description')}`, field: 'description' },
81
+ { title : `${ t ( 'fields.description' ) } ` , field : 'description' } ,
87
82
] }
88
83
data = { apiPerms }
89
84
isLoading = { loading || false }
@@ -103,6 +98,22 @@ function UiPermListPage({ apiPerms, permissions, loading, dispatch }) {
103
98
detailPanel = { ( rowD ) => {
104
99
return < UiPermDetailPage row = { rowD } />
105
100
} }
101
+ editable = { {
102
+ onRowUpdate : ( newData , oldData ) =>
103
+ new Promise ( ( resolve , reject ) => {
104
+ buildPayload ( userAction , 'Edit permision' , newData )
105
+ dispatch ( editPermission ( userAction ) )
106
+ resolve ( )
107
+ doFetchList ( )
108
+ } ) ,
109
+ onRowDelete : ( oldData ) =>
110
+ new Promise ( ( resolve , reject ) => {
111
+ buildPayload ( userAction , 'Remove permission' , oldData )
112
+ dispatch ( deletePermission ( userAction ) )
113
+ resolve ( )
114
+ doFetchList ( )
115
+ } ) ,
116
+ } }
106
117
/>
107
118
</ GluuViewWrapper >
108
119
</ CardBody >
0 commit comments