Skip to content

Commit f42ab3b

Browse files
committed
fix:claims dropdown is not populated in Add/Edit scopes page #140
1 parent 444343f commit f42ab3b

File tree

4 files changed

+90
-11
lines changed

4 files changed

+90
-11
lines changed

admin-ui/plugins/auth-server/components/Scopes/ScopeAddPage.js

+35-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react'
22
import { connect } from 'react-redux'
33
import { useHistory } from 'react-router-dom'
44
import { Container, CardBody, Card } from '../../../../app/components'
55
import ScopeForm from './ScopeForm'
66
import { addScope } from '../../redux/actions/ScopeActions'
77
import { buildPayload } from '../../../../app/utils/PermChecker'
8+
import GluuLoader from '../../../../app/routes/Apps/Gluu/GluuLoader'
9+
import {
10+
getAttributes,
11+
getScripts
12+
} from '../../../../app//redux/actions/InitActions'
13+
import GluuAlert from '../../../../app/routes/Apps/Gluu/GluuAlert'
14+
import { useTranslation } from 'react-i18next'
815

9-
function ScopeAddPage({ scripts, dispatch, attributes }) {
16+
function ScopeAddPage({ scripts, dispatch, attributes, loading, saveOperationFlag, errorInSaveOperationFlag }) {
1017
const userAction = {}
1118
const history = useHistory()
19+
const { t } = useTranslation()
20+
useEffect(() => {
21+
if (attributes.length === 0) {
22+
buildPayload(userAction, 'Fetch attributes', {})
23+
dispatch(getAttributes(userAction))
24+
}
25+
if (scripts.length === 0) {
26+
buildPayload(userAction, 'Fetch custom scripts', {})
27+
dispatch(getScripts(userAction))
28+
}
29+
}, [])
30+
31+
useEffect(() => {
32+
if (saveOperationFlag && !errorInSaveOperationFlag)
33+
history.push('/auth-server/scopes')
34+
}, [saveOperationFlag])
35+
1236
function handleSubmit(data) {
1337
if (data) {
1438
const postBody = {}
@@ -18,7 +42,6 @@ function ScopeAddPage({ scripts, dispatch, attributes }) {
1842
postBody['scope'] = data
1943
buildPayload(userAction, message, postBody)
2044
dispatch(addScope(userAction))
21-
history.push('/auth-server/scopes')
2245
}
2346
}
2447

@@ -34,7 +57,12 @@ function ScopeAddPage({ scripts, dispatch, attributes }) {
3457
}
3558

3659
return (
37-
<React.Fragment>
60+
<GluuLoader blocking={loading}>
61+
<GluuAlert
62+
severity={t('titles.error')}
63+
message={t('messages.error_in_saving')}
64+
show={errorInSaveOperationFlag}
65+
/>
3866
<Container>
3967
<Card className="mb-3">
4068
<CardBody>
@@ -47,7 +75,7 @@ function ScopeAddPage({ scripts, dispatch, attributes }) {
4775
</CardBody>
4876
</Card>
4977
</Container>
50-
</React.Fragment>
78+
</GluuLoader>
5179
)
5280
}
5381
const mapStateToProps = (state) => {
@@ -56,6 +84,8 @@ const mapStateToProps = (state) => {
5684
permissions: state.authReducer.permissions,
5785
scripts: state.initReducer.scripts,
5886
attributes: state.initReducer.attributes,
87+
saveOperationFlag: state.scopeReducer.saveOperationFlag,
88+
errorInSaveOperationFlag: state.scopeReducer.errorInSaveOperationFlag,
5989
}
6090
}
6191
export default connect(mapStateToProps)(ScopeAddPage)

admin-ui/plugins/auth-server/components/Scopes/ScopeEditPage.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react'
22
import { connect } from 'react-redux'
33
import { useHistory } from 'react-router-dom'
44
import { CardBody, Card } from '../../../../app/components'
55
import GluuLoader from '../../../../app/routes/Apps/Gluu/GluuLoader'
66
import ScopeForm from './ScopeForm'
77
import { editScope } from '../../redux/actions/ScopeActions'
88
import { buildPayload } from '../../../../app/utils/PermChecker'
9+
import {
10+
getAttributes,
11+
getScripts
12+
} from '../../../../app//redux/actions/InitActions'
13+
import GluuAlert from '../../../../app/routes/Apps/Gluu/GluuAlert'
14+
import { useTranslation } from 'react-i18next'
915

10-
function ScopeEditPage({ scope, loading, dispatch, scripts, attributes }) {
16+
function ScopeEditPage({ scope, loading, dispatch, scripts, attributes, saveOperationFlag, errorInSaveOperationFlag }) {
1117
const userAction = {}
1218
const history = useHistory()
19+
const { t } = useTranslation()
20+
1321
if (!scope.attributes) {
1422
scope.attributes = {
1523
spontaneousClientId: null,
1624
spontaneousClientScopes: [],
1725
showInConfigurationEndpoint: false,
1826
}
1927
}
28+
useEffect(() => {
29+
if (attributes.length === 0) {
30+
buildPayload(userAction, 'Fetch attributes', {})
31+
dispatch(getAttributes(userAction))
32+
}
33+
if (scripts.length === 0) {
34+
buildPayload(userAction, 'Fetch custom scripts', {})
35+
dispatch(getScripts(userAction))
36+
}
37+
}, [])
38+
useEffect(() => {
39+
if (saveOperationFlag && !errorInSaveOperationFlag)
40+
history.push('/auth-server/scopes')
41+
}, [saveOperationFlag])
2042

2143
function handleSubmit(data) {
2244
if (data) {
@@ -27,11 +49,15 @@ function ScopeEditPage({ scope, loading, dispatch, scripts, attributes }) {
2749
postBody['scope'] = data
2850
buildPayload(userAction, message, postBody)
2951
dispatch(editScope(userAction))
30-
history.push('/auth-server/scopes')
3152
}
3253
}
3354
return (
3455
<GluuLoader blocking={loading}>
56+
<GluuAlert
57+
severity={t('titles.error')}
58+
message={t('messages.error_in_saving')}
59+
show={errorInSaveOperationFlag}
60+
/>
3561
<Card className="mb-3">
3662
<CardBody>
3763
<ScopeForm
@@ -52,6 +78,8 @@ const mapStateToProps = (state) => {
5278
permissions: state.authReducer.permissions,
5379
scripts: state.initReducer.scripts,
5480
attributes: state.initReducer.attributes,
81+
saveOperationFlag: state.scopeReducer.saveOperationFlag,
82+
errorInSaveOperationFlag: state.scopeReducer.errorInSaveOperationFlag,
5583
}
5684
}
5785

admin-ui/plugins/auth-server/components/Scopes/ScopeForm.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function ScopeForm({ scope, scripts, attributes, handleSubmit }) {
3232
.filter((item) => item.scriptType == 'DYNAMIC_SCOPE')
3333
.filter((item) => item.enabled)
3434
.map((item) => ({ dn: item.dn, name: item.name }))
35-
claims = attributes.map((item) => ({ dn: item.dn, name: item.name }))
35+
claims = attributes.map((item) => ({ dn: item.dn, name: item.displayName }))
36+
3637
const [init, setInit] = useState(false)
3738
const [modal, setModal] = useState(false)
3839
const [showClaimsPanel, handleClaimsPanel] = useState(

admin-ui/plugins/auth-server/redux/reducers/ScopeReducer.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const INIT_STATE = {
2020
items: [],
2121
item: {},
2222
loading: false,
23+
saveOperationFlag: false,
24+
errorInSaveOperationFlag: false,
2325
}
2426

2527
const reducerName = 'scopeReducer'
@@ -73,9 +75,16 @@ export default function scopeReducer(state = INIT_STATE, action) {
7375
...state,
7476
items: [...state.items],
7577
loading: false,
78+
saveOperationFlag: true,
79+
errorInSaveOperationFlag: false,
7680
}
7781
} else {
78-
return handleDefault()
82+
return {
83+
...state,
84+
loading: false,
85+
saveOperationFlag: true,
86+
errorInSaveOperationFlag: true,
87+
}
7988
}
8089

8190
case EDIT_SCOPE:
@@ -87,9 +96,16 @@ export default function scopeReducer(state = INIT_STATE, action) {
8796
...state,
8897
items: [...state.items],
8998
loading: false,
99+
saveOperationFlag: true,
100+
errorInSaveOperationFlag: false,
90101
}
91102
} else {
92-
return handleDefault()
103+
return {
104+
...state,
105+
loading: false,
106+
saveOperationFlag: true,
107+
errorInSaveOperationFlag: true,
108+
}
93109
}
94110
case DELETE_SCOPE:
95111
return handleLoading()
@@ -123,12 +139,16 @@ export default function scopeReducer(state = INIT_STATE, action) {
123139
return {
124140
...state,
125141
loading: true,
142+
saveOperationFlag: false,
143+
errorInSaveOperationFlag: false,
126144
}
127145
}
128146
function handleDefault() {
129147
return {
130148
...state,
131149
loading: false,
150+
saveOperationFlag: false,
151+
errorInSaveOperationFlag: false,
132152
}
133153
}
134154
}

0 commit comments

Comments
 (0)