Skip to content

Commit

Permalink
feat(admin-ui): revert restructuring of fido and schema plugin #1246
Browse files Browse the repository at this point in the history
  • Loading branch information
jv18creator committed Jul 31, 2023
1 parent 13a5fd8 commit aecd484
Show file tree
Hide file tree
Showing 40 changed files with 330 additions and 480 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const persistConfig = {
stateReconciler: hardSet,
}
// Preserve initial state for not-yet-loaded reducers
const combine: any = (reducersObjects) => {
const combine = (reducersObjects) => {
const reducerNames = Object.keys(reducersObjects)
Object.keys(appReducers).forEach((item) => {
if (reducerNames.indexOf(item) === -1) {
Expand All @@ -34,13 +34,6 @@ const store = configureStore({
reducer: persistedReducer
})


declare const module: {
hot: {
accept(path: string, callback: () => void): void;
};
};

let rootReducers

sagaMiddleware.run(RootSaga)
Expand All @@ -61,6 +54,6 @@ export function configStore() {
}
return { store, persistor }
}
export type RootState = ReturnType<typeof rootReducers>;

export default store

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
padding: '12px',
textTransform: 'uppercase',
fontSize: '16px',
} as React.CSSProperties,
},
homeStatTooltip: {
backgroundColor: '#00C9FF',
borderRadius: '30px',
Expand Down
7 changes: 0 additions & 7 deletions admin-ui/app/types/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion admin-ui/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow', '@babel/preset-typescript'],
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-flow'],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-syntax-dynamic-import',
Expand Down
8 changes: 1 addition & 7 deletions admin-ui/build/webpack.config.client.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
target: 'web',
mode: 'development',
entry: {
app: [path.join(config.srcDir, 'index.tsx')],
app: [path.join(config.srcDir, 'index.js')],
},

output: {
Expand All @@ -36,7 +36,6 @@ module.exports = {
resolve: {
fallback: { querystring: false, crypto: false, util: false, console: false },
modules: ['node_modules', config.srcDir],
extensions: ['.ts', '.js', '.jsx', '.tsx'],
alias: {
path: require.resolve('path-browserify'),
Components: path.resolve(__dirname, '../app/components'),
Expand Down Expand Up @@ -86,11 +85,6 @@ module.exports = {
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: 'ts-loader',
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader', 'postcss-loader'],
Expand Down
8 changes: 1 addition & 7 deletions admin-ui/build/webpack.config.client.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
devtool: false,
mode: 'production',
entry: {
app: [path.join(config.srcDir, 'index.tsx')],
app: [path.join(config.srcDir, 'index.js')],
},
optimization: {
moduleIds: 'named',
Expand Down Expand Up @@ -79,7 +79,6 @@ module.exports = {
resolve: {
fallback: { "querystring": false, crypto: false, util: false, console: false },
modules: ['node_modules', config.srcDir],
extensions: ['.ts', '.js', '.jsx', '.tsx'],
alias: {
path: require.resolve('path-browserify'),
Components: path.resolve(__dirname, '../app/components'),
Expand Down Expand Up @@ -135,11 +134,6 @@ module.exports = {
use: 'babel-loader',
sideEffects: false,
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: 'ts-loader',
},
{
test: /\.test\.js$/,
include: [config.srcDir, config.pluginsDir],
Expand Down
3 changes: 0 additions & 3 deletions admin-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"@babel/preset-env": "^7.21.5",
"@babel/preset-flow": "^7.21.4",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.22.5",
"@testing-library/dom": "^9.3.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
Expand Down Expand Up @@ -92,8 +91,6 @@
"rimraf": "^4.4.1",
"sass-loader": "^13.2.2",
"style-loader": "^3.3.2",
"ts-loader": "^9.4.3",
"typescript": "^5.1.3",
"webpack": "^5.77.0",
"webpack-bundle-analyzer": "^4.8.0",
"webpack-cli": "^5.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
import Fido from '../presentation/pages/Fido'
import Fido from 'Plugins/fido/components/Fido'
import AppTestWrapper from 'Routes/Apps/Gluu/Tests/Components/AppTestWrapper.test'
import { Provider } from 'react-redux'
import { combineReducers, configureStore } from '@reduxjs/toolkit'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,66 @@
import React, { useState } from 'react'
import { Row, Col, Form, FormGroup } from '../../../../app/components'
import GluuInputRow from '../../../../app/routes/Apps/Gluu/GluuInputRow'
import GluuSelectRow from '../../../../app/routes/Apps/Gluu/GluuSelectRow'
import { Row, Col, Form, FormGroup } from 'Components'
import GluuInputRow from 'Routes/Apps/Gluu/GluuInputRow'
import GluuSelectRow from 'Routes/Apps/Gluu/GluuSelectRow'
import { useFormik } from 'formik'
import GluuCommitDialog from 'Routes/Apps/Gluu/GluuCommitDialog'
import GluuCommitFooter from 'Routes/Apps/Gluu/GluuCommitFooter'
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
import GluuProperties from 'Routes/Apps/Gluu/GluuProperties'
import {
dynamicConfigInitValues,
dynamicConfigValidationSchema,
} from '../../domain/use-cases/dynamicConfigUseCases'
import * as Yup from 'yup'

const dynamicConfigInitValues = (staticConfiguration) => {
return {
issuer: staticConfiguration?.issuer || '',
baseEndpoint: staticConfiguration?.baseEndpoint || '',
cleanServiceInterval: staticConfiguration?.cleanServiceInterval || '',
cleanServiceBatchChunkSize:
staticConfiguration?.cleanServiceBatchChunkSize || '',
useLocalCache: staticConfiguration?.useLocalCache || '',
disableJdkLogger: staticConfiguration?.disableJdkLogger || '',
loggingLevel: staticConfiguration?.loggingLevel || '',
loggingLayout: staticConfiguration?.loggingLayout || '',
externalLoggerConfiguration:
staticConfiguration?.externalLoggerConfiguration || '',
metricReporterEnabled: staticConfiguration?.metricReporterEnabled,
metricReporterInterval: staticConfiguration?.metricReporterInterval || '',
metricReporterKeepDataDays:
staticConfiguration?.metricReporterKeepDataDays || '',
personCustomObjectClassList:
staticConfiguration?.personCustomObjectClassList || [],
superGluuEnabled: staticConfiguration?.superGluuEnabled,
}
}

const dynamicConfigValidationSchema = Yup.object({
issuer: Yup.string().required('Issuer is required.'),
baseEndpoint: Yup.string().required('Base Endpoint is required.'),
cleanServiceInterval: Yup.string().required(
'Clean Service Interval is required.'
),
cleanServiceBatchChunkSize: Yup.string().required(
'Clean Service Batch Chunk Size is required.'
),
useLocalCache: Yup.boolean().required('Use Local Cache is required.'),
disableJdkLogger: Yup.boolean().required('Disable Jdk Logger is required.'),
loggingLevel: Yup.string().required('Logging Level is required.'),
loggingLayout: Yup.string().required('Logging Layout is required.'),
metricReporterEnabled: Yup.boolean().required(
'Metric Reporter Enabled is required.'
),
metricReporterInterval: Yup.number().required(
'Metric Reporter Interval is required.'
),
metricReporterKeepDataDays: Yup.number().required(
'Metric Reporter Keep Data Days is required.'
),
superGluuEnabled: Yup.boolean().required('Enable Super Gluu is required.'),
})


function DynamicConfiguration({ fidoConfiguration, handleSubmit }) {
const staticConfiguration = fidoConfiguration.fido
const [modal, setModal] = useState<boolean>(false)
const [modal, setModal] = useState(false)
const toggle = () => {
setModal(!modal)
}
Expand All @@ -34,7 +80,7 @@ function DynamicConfiguration({ fidoConfiguration, handleSubmit }) {

return (
<Form
onSubmit={(e: React.FormEvent<HTMLInputElement>) => {
onSubmit={(e) => {
e.preventDefault()
formik.handleSubmit()
}}
Expand Down
129 changes: 129 additions & 0 deletions admin-ui/plugins/fido/components/Fido.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import React, { useEffect } from 'react'
import StaticConfiguration from './StaticConfiguration'
import DynamicConfiguration from './DynamicConfiguration'
import GluuTabs from 'Routes/Apps/Gluu/GluuTabs'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import { useTranslation } from 'react-i18next'
import { Card, CardBody } from 'Components'
import SetTitle from 'Utils/SetTitle'
import { useDispatch, useSelector } from 'react-redux'
import {
getFidoConfiguration,
putFidoConfiguration,
} from '../redux/features/fidoSlice'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'

const tabNames = ['Dynamic Configuration', 'Static Configuration']

const fidoApiPayload = ({ fidoConfiguration, data }) => {
const payload = fidoConfiguration.fido
payload.authenticatorCertsFolder = data.authenticatorCertsFolder
payload.mdsCertsFolder = data.mdsCertsFolder
payload.mdsTocsFolder = data.mdsTocsFolder
payload.checkU2fAttestations = data.checkU2fAttestations
payload.unfinishedRequestExpiration = data.unfinishedRequestExpiration
payload.authenticationHistoryExpiration = data.authenticationHistoryExpiration
payload.serverMetadataFolder = data.serverMetadataFolder
payload.userAutoEnrollment = data.userAutoEnrollment
payload.requestedCredentialTypes = data.requestedCredentialTypes.map((item) =>
item?.value ? item?.value : item
)
payload.requestedParties = data.requestedParties.map((item) => {
return {
name: item.key,
domains: [item.key],
}
})

const newPayload = {
...fidoConfiguration.fido,
fido2Configuration: payload,
}

const opts = {}
const fiodData = JSON.stringify(newPayload)
opts['appConfiguration1'] = JSON.parse(fiodData)

return opts
}

const fidoApiPayloadDynamicConfig = ({ fidoConfiguration, data }) => {
const payload = fidoConfiguration.fido
payload.issuer = data.issuer
payload.baseEndpoint = data.baseEndpoint
payload.cleanServiceInterval = data.cleanServiceInterval
payload.cleanServiceBatchChunkSize = data.cleanServiceBatchChunkSize
payload.useLocalCache = data.useLocalCache
payload.disableJdkLogger = data.disableJdkLogger
payload.loggingLevel = data.loggingLevel
payload.loggingLayout = data.loggingLayout
payload.externalLoggerConfiguration = data.externalLoggerConfiguration
payload.metricReporterEnabled = data.metricReporterEnabled
payload.metricReporterInterval = data.metricReporterInterval
payload.metricReporterKeepDataDays = data.metricReporterKeepDataDays
payload.personCustomObjectClassList = data.personCustomObjectClassList
payload.superGluuEnabled = data.superGluuEnabled
payload.personCustomObjectClassList = data.personCustomObjectClassList.map(
(item) => (item?.value ? item?.value : item)
)

const opts = {}
const fiodData = JSON.stringify(payload)
opts['appConfiguration1'] = JSON.parse(fiodData)

return opts
}

export default function Fido() {
const { t } = useTranslation()
SetTitle(t('titles.fido_management'))
const dispatch = useDispatch()
const fidoConfiguration = useSelector((state) => state.fidoReducer)

useEffect(() => {
dispatch(getFidoConfiguration())
}, [])

const tabToShow = (tabName) => {
switch (tabName) {
case 'Static Configuration':
return (
<StaticConfiguration
handleSubmit={handleStaticConfigurationSubmit}
fidoConfiguration={fidoConfiguration}
/>
)
case 'Dynamic Configuration':
return (
<DynamicConfiguration
handleSubmit={handleDyamicConfigurationSubmit}
fidoConfiguration={fidoConfiguration}
/>
)
}
}

const handleDyamicConfigurationSubmit = (data) => {
const apiPayload = fidoApiPayloadDynamicConfig({ data, fidoConfiguration })
dispatch(putFidoConfiguration(apiPayload))
}

const handleStaticConfigurationSubmit = (data) => {
const apiPayload = fidoApiPayload({ data, fidoConfiguration })
dispatch(putFidoConfiguration(apiPayload))
}

return (
<React.Fragment>
<GluuLoader blocking={fidoConfiguration?.loading}>
<Card className='mb-3' style={applicationStyle.mainCard}>
<CardBody>
{!fidoConfiguration?.loading && (
<GluuTabs tabNames={tabNames} tabToShow={tabToShow} />
)}
</CardBody>
</Card>
</GluuLoader>
</React.Fragment>
)
}
Loading

0 comments on commit aecd484

Please sign in to comment.