Skip to content

Commit 871340c

Browse files
committed
feat(admin-ui): show ldpat test result based on API response
1 parent 95ef2b0 commit 871340c

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

admin-ui/plugins/services/Components/Configuration/LdapListPage.js

+32-17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
setCurrentItem,
2525
deleteLdap,
2626
testLdap,
27+
resetTestLdap,
2728
} from 'Plugins/services/redux/actions/LdapActions'
2829
import { getPersistenceType } from 'Plugins/services/redux/actions/PersistenceActions'
2930
import { useTranslation } from 'react-i18next'
@@ -50,6 +51,7 @@ function LdapListPage({
5051
const history = useHistory()
5152
const [item, setItem] = useState({})
5253
const [modal, setModal] = useState(false)
54+
const [testRunning, setTestRunning] = useState(false)
5355
const pageSize = localStorage.getItem('paggingSize') || 10
5456
const [alertObj, setAlertObj] = useState({
5557
severity: '',
@@ -137,31 +139,44 @@ function LdapListPage({
137139
function testLdapConnect(row) {
138140
const testPromise = new Promise(function (resolve, reject) {
139141
setAlertObj({ ...alertObj, show: false })
142+
dispatch(resetTestLdap())
140143
resolve()
141144
})
142145

143146
testPromise
144147
.then(() => {
148+
setTestRunning(true)
145149
dispatch(testLdap(row))
146150
})
147-
.then(() => {
148-
if (testStatus) {
149-
setAlertObj({
150-
...alertObj,
151-
severity: 'success',
152-
message: `${t('messages.ldap_connection_success')}`,
153-
show: true,
154-
})
155-
} else {
156-
setAlertObj({
157-
...alertObj,
158-
severity: 'error',
159-
message: `${t('messages.ldap_connection_error')}`,
160-
show: true,
161-
})
162-
}
163-
})
164151
}
152+
153+
useEffect(() => {
154+
dispatch(resetTestLdap())
155+
setAlertObj({ ...alertObj, show: false })
156+
}, [])
157+
158+
useEffect(() => {
159+
if (testStatus === null || !testRunning) {
160+
return
161+
}
162+
163+
if (testStatus) {
164+
setAlertObj({
165+
...alertObj,
166+
severity: 'success',
167+
message: `${t('messages.ldap_connection_success')}`,
168+
show: true,
169+
})
170+
} else {
171+
setAlertObj({
172+
...alertObj,
173+
severity: 'error',
174+
message: `${t('messages.ldap_connection_error')}`,
175+
show: true,
176+
})
177+
}
178+
}, [testStatus])
179+
165180
return (
166181
<Card style={applicationStyle.mainCard}>
167182
<CardBody>

admin-ui/plugins/services/redux/actions/LdapActions.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
SET_LDAP,
1111
TEST_LDAP,
1212
TEST_LDAP_RESPONSE,
13+
RESET_TEST_LDAP_RESPONSE
1314
} from './types'
1415

1516
export const getLdapConfig = () => ({
@@ -58,10 +59,15 @@ export const setCurrentItem = (item) => ({
5859

5960
export const testLdap = (data) => ({
6061
type: TEST_LDAP,
61-
payload: {data},
62+
payload: { data },
6263
})
6364

6465
export const testLdapResponse = (data) => ({
6566
type: TEST_LDAP_RESPONSE,
6667
payload: { data },
67-
})
68+
})
69+
70+
export const resetTestLdap = () => ({
71+
type: RESET_TEST_LDAP_RESPONSE,
72+
payload: {},
73+
})

admin-ui/plugins/services/redux/actions/types.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export const PUT_ACRS_RESPONSE = 'PUT_ACRS_RESPONSE'
8585
export const GET_ACR_AUTH_SCRIPT = 'GET_ACR_AUTH_SCRIPT'
8686
export const GET_ACR_AUTH_SCRIPT_RESPONSE = 'GET_ACR_AUTH_SCRIPT_RESPONSE'
8787

88-
8988
// fido
9089
export const GET_FIDO = 'GET_FIDO'
9190
export const GET_FIDO_RESPONSE = 'GET_FIDO_RESPONSE'
@@ -118,6 +117,7 @@ export const DELETE_LDAP = 'DELETE_LDAP'
118117
export const DELETE_LDAP_RESPONSE = 'DELETE_LDAP_RESPONSE'
119118
export const TEST_LDAP = 'TEST_LDAP'
120119
export const TEST_LDAP_RESPONSE = 'TEST_LDAP_RESPONSE'
120+
export const RESET_TEST_LDAP_RESPONSE = 'RESET_TEST_LDAP_RESPONSE'
121121
// Couchbase
122122
export const GET_COUCHBASE = 'GET_COUCHBASE'
123123
export const GET_COUCHBASE_RESPONSE = 'GET_COUCHBASE_RESPONSE'
@@ -179,4 +179,3 @@ export const GET_JSON_CONFIG = 'GET_JSON_CONFIG'
179179
export const GET_JSONCONFIG_RESPONSE = 'GET_JSONCONFIG_RESPONSE'
180180
export const PATCH_JSON_CONFIG = 'PATCH_JSON_CONFIG'
181181
export const PATCH_JSONCONFIG_RESPONSE = 'PATCH_JSONCONFIG_RESPONSE'
182-

admin-ui/plugins/services/redux/api/LdapApi.js

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default class LdapApi {
4141

4242
// test LDAP Config
4343
testLdapConfig = (input) => {
44-
console.log('Ldap Api testLdapConfig ')
4544
return new Promise((resolve, reject) => {
4645
this.api.postConfigDatabaseLdapTest(input, (error, data, response) => {
4746
this.handleResponse(error, reject, resolve, data)

admin-ui/plugins/services/redux/reducers/LdapReducer.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import {
1111
DELETE_LDAP_RESPONSE,
1212
TEST_LDAP,
1313
TEST_LDAP_RESPONSE,
14+
RESET_TEST_LDAP_RESPONSE,
1415
} from '../actions/types'
1516
const INIT_STATE = {
1617
ldap: [],
1718
item: {},
1819
loading: false,
19-
testStatus: false,
20+
testStatus: null,
2021
}
2122

2223
export default function ldapReducer(state = INIT_STATE, action) {
@@ -120,6 +121,11 @@ export default function ldapReducer(state = INIT_STATE, action) {
120121
loading: false,
121122
}
122123

124+
case RESET_TEST_LDAP_RESPONSE:
125+
return {
126+
...state,
127+
testStatus: INIT_STATE.testStatus,
128+
}
123129
case RESET:
124130
return {
125131
...state,

0 commit comments

Comments
 (0)