-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathLoggingPage.js
More file actions
231 lines (214 loc) · 8.76 KB
/
LoggingPage.js
File metadata and controls
231 lines (214 loc) · 8.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import React, { useEffect, useState, useMemo, useCallback } from 'react'
import { Form, FormGroup, Card, CardBody, Col, CustomInput, Row } from 'Components'
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
import GluuLoader from 'Routes/Apps/Gluu/GluuLoader'
import GluuViewWrapper from 'Routes/Apps/Gluu/GluuViewWrapper'
import GluuCommitDialog from 'Routes/Apps/Gluu/GluuCommitDialog'
import GluuFormFooter from 'Routes/Apps/Gluu/GluuFormFooter'
import { JSON_CONFIG } from 'Utils/ApiResources'
import { loggingValidationSchema } from './validations'
import { LOG_LEVELS, LOG_LAYOUTS, getLoggingInitialValues } from './utils'
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
import { useDispatch, useSelector } from 'react-redux'
import { Formik } from 'formik'
import {
getLoggingConfig,
editLoggingConfig,
} from 'Plugins/auth-server/redux/features/loggingSlice'
import { LOGGING_READ, LOGGING_WRITE } from 'Utils/PermChecker'
import { useCedarling } from '@/cedarling'
import { useTranslation } from 'react-i18next'
import SetTitle from 'Utils/SetTitle'
import GluuToogleRow from 'Routes/Apps/Gluu/GluuToogleRow'
import { getChangedFields, getMergedValues } from '@/helpers'
function LoggingPage() {
const { t } = useTranslation()
const { hasCedarPermission, authorize } = useCedarling()
const logging = useSelector((state) => state.loggingReducer.logging)
const loading = useSelector((state) => state.loggingReducer.loading)
const dispatch = useDispatch()
const [showCommitDialog, setShowCommitDialog] = useState(false)
const [pendingValues, setPendingValues] = useState(null)
const toggleCommitDialog = useCallback(() => setShowCommitDialog((prev) => !prev), [])
useEffect(() => {
const initPermissions = async () => {
const permissions = [LOGGING_READ, LOGGING_WRITE]
for (const permission of permissions) {
await authorize([permission])
}
}
initPermissions()
dispatch(getLoggingConfig())
}, [dispatch, authorize])
const initialValues = useMemo(() => getLoggingInitialValues(logging), [logging])
const levels = useMemo(() => LOG_LEVELS, [])
const logLayouts = useMemo(() => LOG_LAYOUTS, [])
SetTitle('Logging')
const handleSubmit = useCallback(
(values) => {
const mergedValues = getMergedValues(logging, values)
const changedFields = getChangedFields(logging, mergedValues)
setPendingValues({ mergedValues, changedFields })
setShowCommitDialog(true)
},
[logging],
)
const handleAccept = useCallback(
(userMessage) => {
if (pendingValues) {
const { mergedValues, changedFields } = pendingValues
const opts = {}
opts['logging'] = JSON.stringify(mergedValues)
dispatch(
editLoggingConfig({
data: opts,
otherFields: { userMessage, changedFields },
}),
)
setShowCommitDialog(false)
setPendingValues(null)
}
},
[pendingValues, dispatch],
)
return (
<GluuLoader blocking={loading}>
<Card style={applicationStyle.mainCard}>
<CardBody style={{ minHeight: 500 }}>
<GluuViewWrapper canShow={hasCedarPermission(LOGGING_READ)}>
<Formik
initialValues={initialValues}
enableReinitialize
onSubmit={handleSubmit}
validationSchema={loggingValidationSchema}
validateOnMount
>
{(formik) => (
<Form onSubmit={formik.handleSubmit}>
<FormGroup row>
<GluuLabel
label="fields.log_level"
size={4}
doc_category={JSON_CONFIG}
doc_entry="loggingLevel"
required
/>
<Col sm={8}>
<CustomInput
type="select"
id="loggingLevel"
name="loggingLevel"
data-testid="loggingLevel"
value={formik.values.loggingLevel}
onChange={(e) => formik.setFieldValue('loggingLevel', e.target.value)}
onBlur={() => formik.setFieldTouched('loggingLevel', true)}
required
aria-required="true"
>
<option value="">{t('actions.choose')}...</option>
{levels.map((item, key) => (
<option value={item} key={key}>
{item}
</option>
))}
</CustomInput>
{formik.touched.loggingLevel && formik.errors.loggingLevel && (
<div className="text-danger mt-1">{formik.errors.loggingLevel}</div>
)}
</Col>
</FormGroup>
<FormGroup row>
<GluuLabel
label="fields.log_layout"
size={4}
doc_category={JSON_CONFIG}
doc_entry="loggingLayout"
required
/>
<Col sm={8}>
<CustomInput
type="select"
id="loggingLayout"
name="loggingLayout"
data-testid="loggingLayout"
value={formik.values.loggingLayout}
onChange={(e) => formik.setFieldValue('loggingLayout', e.target.value)}
onBlur={() => formik.setFieldTouched('loggingLayout', true)}
required
aria-required="true"
>
<option value="">{t('actions.choose')}...</option>
{logLayouts.map((item, key) => (
<option value={item} key={key}>
{item}
</option>
))}
</CustomInput>
{formik.touched.loggingLayout && formik.errors.loggingLayout && (
<div className="text-danger mt-1">{formik.errors.loggingLayout}</div>
)}
</Col>
</FormGroup>
<GluuToogleRow
label="fields.http_logging_enabled"
name="httpLoggingEnabled"
handler={(e) => formik.setFieldValue('httpLoggingEnabled', e.target.checked)}
lsize={5}
rsize={7}
value={formik.values.httpLoggingEnabled}
doc_category={JSON_CONFIG}
/>
<GluuToogleRow
label="fields.disable_jdk_logger"
name="disableJdkLogger"
handler={(e) => formik.setFieldValue('disableJdkLogger', e.target.checked)}
lsize={5}
rsize={7}
doc_category={JSON_CONFIG}
value={formik.values.disableJdkLogger}
/>
<GluuToogleRow
label="fields.enabled_oAuth_audit_logging"
name="enabledOAuthAuditLogging"
handler={(e) =>
formik.setFieldValue('enabledOAuthAuditLogging', e.target.checked)
}
lsize={5}
rsize={7}
doc_category={JSON_CONFIG}
value={formik.values.enabledOAuthAuditLogging}
/>
{hasCedarPermission(LOGGING_WRITE) && (
<Row>
<Col>
<GluuFormFooter
showBack={true}
showCancel={true}
showApply={true}
onApply={formik.handleSubmit}
onCancel={() => formik.resetForm()}
disableBack={false}
disableCancel={!formik.dirty}
disableApply={!formik.isValid || !formik.dirty}
applyButtonType="button"
isLoading={loading}
/>
</Col>
</Row>
)}
</Form>
)}
</Formik>
<GluuCommitDialog
handler={toggleCommitDialog}
modal={showCommitDialog}
onAccept={handleAccept}
isLicenseLabel={false}
/>
</GluuViewWrapper>
</CardBody>
</Card>
</GluuLoader>
)
}
export default LoggingPage