-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move health menu under Home menu #116
- Loading branch information
Showing
19 changed files
with
823 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { GET_HEALTH, GET_HEALTH_RESPONSE } from './types' | ||
|
||
export const getHealthStatus = (action) => ({ | ||
type: GET_HEALTH, | ||
payload: { action }, | ||
}) | ||
|
||
export const getHealthStatusResponse = (data) => ({ | ||
type: GET_HEALTH_RESPONSE, | ||
payload: { data }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { | ||
GET_LICENSE_DETAILS, | ||
GET_LICENSE_DETAILS_RESPONSE, | ||
UPDATE_LICENSE_DETAILS, | ||
UPDATE_LICENSE_DETAILS_RESPONSE, | ||
} from './types' | ||
|
||
export const getLicenseDetails = (action) => ({ | ||
type: GET_LICENSE_DETAILS, | ||
payload: { action }, | ||
}) | ||
|
||
export const getLicenseDetailsResponse = (data) => ({ | ||
type: GET_LICENSE_DETAILS_RESPONSE, | ||
payload: { data }, | ||
}) | ||
|
||
export const updateLicenseDetails = (action) => ({ | ||
type: UPDATE_LICENSE_DETAILS, | ||
payload: { action }, | ||
}) | ||
|
||
export const updateLicenseDetailsResponse = (data) => ({ | ||
type: UPDATE_LICENSE_DETAILS_RESPONSE, | ||
payload: { data }, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export default class HealthApi { | ||
constructor(api) { | ||
this.api = api | ||
} | ||
|
||
getHealthStatus = () => { | ||
return new Promise((resolve, reject) => { | ||
this.api.getAuthServerHealth((error, data) => { | ||
if (error) { | ||
console.log(e); | ||
reject(error) | ||
} else { | ||
resolve(data) | ||
} | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export default class LicenseDetailsApi { | ||
constructor(api) { | ||
this.api = api | ||
} | ||
|
||
getLicenseDetails = () => { | ||
return new Promise((resolve, reject) => { | ||
this.api.getAdminuiLicense((error, data) => { | ||
this.handleResponse(error, reject, resolve, data) | ||
}) | ||
}) | ||
} | ||
|
||
updateLicenseDetails = (data) => { | ||
const options = {} | ||
options['licenseRequest'] = data | ||
return new Promise((resolve, reject) => { | ||
this.api.editAdminuiLicense(options, (error, options) => { | ||
this.handleResponse(error, reject, resolve, data) | ||
}) | ||
}) | ||
} | ||
|
||
handleResponse(error, reject, resolve, data) { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(data) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { GET_HEALTH, GET_HEALTH_RESPONSE } from '../actions/types' | ||
import reducerRegistry from './ReducerRegistry' | ||
const INIT_STATE = { | ||
serverStatus: null, | ||
dbStatus: null, | ||
loading: false, | ||
} | ||
|
||
const reducerName = 'healthReducer' | ||
|
||
export default function healthReducer(state = INIT_STATE, action) { | ||
switch (action.type) { | ||
case GET_HEALTH: | ||
return { | ||
...state, | ||
loading: true, | ||
} | ||
case GET_HEALTH_RESPONSE: | ||
if (action.payload.data) { | ||
return { | ||
...state, | ||
serverStatus: action.payload.data.status, | ||
dbStatus: action.payload.data.db_status, | ||
loading: false, | ||
} | ||
} else { | ||
return handleDefault() | ||
} | ||
default: | ||
return handleDefault() | ||
} | ||
|
||
function handleDefault() { | ||
return { | ||
...state, | ||
loading: false, | ||
} | ||
} | ||
} | ||
reducerRegistry.register(reducerName, healthReducer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { GET_LICENSE_DETAILS, GET_LICENSE_DETAILS_RESPONSE, UPDATE_LICENSE_DETAILS, UPDATE_LICENSE_DETAILS_RESPONSE } from '../actions/types' | ||
import reducerRegistry from '../../redux/reducers/ReducerRegistry' | ||
const INIT_STATE = { | ||
item: {}, | ||
loading: true, | ||
} | ||
|
||
const reducerName = 'licenseDetailsReducer' | ||
|
||
export default function licenseDetailsReducer(state = INIT_STATE, action) { | ||
switch (action.type) { | ||
case GET_LICENSE_DETAILS: | ||
return { | ||
...state, | ||
loading: true, | ||
} | ||
case GET_LICENSE_DETAILS_RESPONSE: | ||
if (action.payload.data) { | ||
return { | ||
...state, | ||
item: action.payload.data, | ||
loading: false, | ||
} | ||
} else { | ||
return { | ||
...state, | ||
loading: false, | ||
} | ||
} | ||
case UPDATE_LICENSE_DETAILS: | ||
return { | ||
...state, | ||
loading: true, | ||
} | ||
case UPDATE_LICENSE_DETAILS_RESPONSE: | ||
if (action.payload.data) { | ||
return { | ||
...state, | ||
items: action.payload.data, | ||
loading: false, | ||
} | ||
} else { | ||
return { | ||
...state, | ||
loading: false, | ||
} | ||
} | ||
default: | ||
return { | ||
...state, | ||
} | ||
} | ||
} | ||
reducerRegistry.register(reducerName, licenseDetailsReducer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { call, all, put, fork, takeLatest, select } from 'redux-saga/effects' | ||
import { | ||
isFourZeroOneError, | ||
addAdditionalData, | ||
} from '../../utils/TokenController' | ||
import { getHealthStatusResponse } from '../actions/HealthAction' | ||
import { getAPIAccessToken } from '../actions/AuthActions' | ||
import { postUserAction} from '../api/backend-api' | ||
import { GET_HEALTH } from '../actions/types' | ||
import HealthApi from '../api/HealthApi' | ||
import { getClient } from '../api/base' | ||
import { initAudit } from '../sagas/SagaUtils' | ||
const JansConfigApi = require('jans_config_api') | ||
|
||
function* newFunction() { | ||
const token = yield select((state) => state.authReducer.token.access_token) | ||
const issuer = yield select((state) => state.authReducer.issuer) | ||
const api = new JansConfigApi.AuthServerHealthCheckApi( | ||
getClient(JansConfigApi, token, issuer), | ||
) | ||
return new HealthApi(api) | ||
} | ||
|
||
export function* getHealthStatus({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
payload = payload ? payload : { action: {} } | ||
addAdditionalData(audit, 'FETCH', 'Health', payload) | ||
const healthApi = yield* newFunction() | ||
const data = yield call(healthApi.getHealthStatus, payload.action.action_data) | ||
yield put(getHealthStatusResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
|
||
yield put(getHealthStatusResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
|
||
export function* watchGetHealthStatus() { | ||
yield takeLatest(GET_HEALTH, getHealthStatus) | ||
} | ||
|
||
export default function* rootSaga() { | ||
yield all([fork(watchGetHealthStatus)]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { all, call, fork, put, takeEvery, select } from 'redux-saga/effects' | ||
import { GET_LICENSE_DETAILS, UPDATE_LICENSE_DETAILS } from '../actions/types' | ||
import { | ||
getLicenseDetailsResponse, | ||
updateLicenseDetailsResponse, | ||
} from '../actions/LicenseDetailsActions' | ||
import { getClient } from '../../redux/api/base' | ||
import LicenseDetailsApi from '../api/LicenseDetailsApi' | ||
const JansConfigApi = require('jans_config_api') | ||
import { initAudit } from '../../redux/sagas/SagaUtils' | ||
import { | ||
isFourZeroOneError, | ||
addAdditionalData, | ||
} from '../../utils/TokenController' | ||
import { getAPIAccessToken } from '../../redux/actions/AuthActions' | ||
|
||
function* newFunction() { | ||
const token = yield select((state) => state.authReducer.token.access_token) | ||
const issuer = yield select((state) => state.authReducer.issuer) | ||
const api = new JansConfigApi.AdminUILicenseApi( | ||
getClient(JansConfigApi, token, issuer), | ||
) | ||
return new LicenseDetailsApi(api) | ||
} | ||
|
||
|
||
export function* getLicenseDetailsWorker({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
//addAdditionalData(audit, FETCH, GET_LICENSE_DETAILS, payload) | ||
const licenseApi = yield* newFunction() | ||
const data = yield call(licenseApi.getLicenseDetails) | ||
yield put(getLicenseDetailsResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(getLicenseDetailsResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
|
||
export function* updateLicenseDetailsWorker({ payload }) { | ||
const audit = yield* initAudit() | ||
try { | ||
//addAdditionalData(audit, UPDATE, UPDATE_LICENSE_DETAILS, payload) | ||
const roleApi = yield* newFunction() | ||
const data = yield call(roleApi.updateLicenseDetails, payload.action.action_data) | ||
yield put(updateLicenseDetailsResponse(data)) | ||
yield call(postUserAction, audit) | ||
} catch (e) { | ||
yield put(updateLicenseDetailsResponse(null)) | ||
if (isFourZeroOneError(e)) { | ||
const jwt = yield select((state) => state.authReducer.userinfo_jwt) | ||
yield put(getAPIAccessToken(jwt)) | ||
} | ||
} | ||
} | ||
|
||
|
||
export function* getLicenseWatcher() { | ||
|
||
yield takeEvery(GET_LICENSE_DETAILS, getLicenseDetailsWorker) | ||
} | ||
|
||
export function* updateLicenseWatcher() { | ||
yield takeEvery(UPDATE_LICENSE_DETAILS, updateLicenseDetailsWorker) | ||
} | ||
|
||
export default function* rootSaga() { | ||
yield all([fork(getLicenseWatcher), fork(updateLicenseWatcher)]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.