Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin-ui): save form value of client in state while navigating between tabs #1341 #1354

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion admin-ui/app/routes/Apps/Gluu/GluuTypeAheadForDn.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ function GluuTypeAheadForDn({
onPaginate = () => {},
maxResults = undefined,
isLoading = false,
placeholder = undefined
placeholder = undefined,
onChange
}) {
const { t } = useTranslation()
const [open, setOpen] = useState(false)
Expand Down Expand Up @@ -83,6 +84,7 @@ function GluuTypeAheadForDn({
: item.dn,
),
)
onChange?.(selected)
}}
disabled={disabled}
id={name}
Expand Down
10 changes: 8 additions & 2 deletions admin-ui/app/styles/components/wizard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
.wizard {
display: flex;
align-items: center;
overflow-x: auto;
}

.wizard-wrapper {
max-width: 70vw;
margin: 0 auto;
}

.wizard-step {
Expand Down Expand Up @@ -60,8 +66,8 @@
}

@media (max-width: breakpoint-max('md', $grid-breakpoints)) {
.wizard {
flex-wrap: wrap;
.wizard-wrapper {
max-width: 100vw;
}

.wizard-step {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { Col, Container, FormGroup, InputGroup, CustomInput } from 'Components'
import GluuBooleanSelectBox from 'Routes/Apps/Gluu/GluuBooleanSelectBox'
import GluuLabel from 'Routes/Apps/Gluu/GluuLabel'
Expand All @@ -20,23 +20,19 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
const request_uri_id = 'request_uri_id'
const requestUris = []

const [expirable, setExpirable] = useState(
client.expirationDate ? client.expirationDate : false,
const [expirable] = useState(
formik.values.expirationDate ? formik.values.expirationDate : false,
)
const [scopesModal, setScopesModal] = useState(false)
const [expirationDate, setExpirationDate] = useState(expirable ? dayjs(expirable) : undefined)
const handler = () => {
setScopesModal(!scopesModal)
}

function handleExpirable() {
setExpirable(!expirable)
}

scripts = scripts
.filter((item) => item.scriptType == 'person_authentication')
.filter((item) => item.enabled)
.map((item) => (item.name))
const filteredScripts = scripts
?.filter((item) => item.scriptType == 'person_authentication')
?.filter((item) => item.enabled)
?.map((item) => (item.name))
function uriValidator(uri) {
return uri
}
Expand All @@ -46,26 +42,15 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
}
return total.filter((item) => partial.includes(item))
}
const [softwareSection, setSoftwareSection] = useState(false)
const [cibaSection, setCibaSection] = useState(false)

function handleCibaSection() {
setCibaSection(!cibaSection)
}
function handleSoftwareSection() {
setSoftwareSection(!softwareSection)
}
function emailValidator(email) {
return /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(
email,
)
}
function getScopeMapping(exitingScopes, scopes) {
if (!exitingScopes) {
exitingScopes = []
useEffect(() => {
// Listen for changes on expirable input switch
if (!formik.values.expirable) {
formik.setFieldValue('expirationDate', null)
setExpirationDate(null)
}
return scopes.filter((item) => exitingScopes.includes(item.dn))
}
}, [formik.values.expirable])

return (
<Container>
<ClientShowSpontaneousScopes handler={handler} isOpen={scopesModal} />
Expand All @@ -78,7 +63,7 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
id="subjectType"
name="subjectType"
disabled={viewOnly}
defaultValue={client.subjectType}
defaultValue={formik.values.subjectType}
onChange={formik.handleChange}
>
<option value="">{t('actions.choose')}...</option>
Expand All @@ -91,18 +76,18 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {

<GluuToogleRow
name="persistClientAuthorizations"
lsize={9}
rsize={3}
lsize={3}
rsize={9}
formik={formik}
label="fields.persist_client_authorizations"
value={client.persistClientAuthorizations}
value={formik.values.persistClientAuthorizations}
doc_category={DOC_CATEGORY}
disabled={viewOnly}
/>
<GluuBooleanSelectBox
name="allowSpontaneousScopes"
label="fields.allow_spontaneous_scopes"
value={client.allowSpontaneousScopes}
value={formik.values.allowSpontaneousScopes}
formik={formik}
lsize={3}
rsize={9}
Expand Down Expand Up @@ -142,7 +127,7 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
label="fields.initiateLoginUri"
name="initiateLoginUri"
formik={formik}
value={client.initiateLoginUri}
value={formik.values.initiateLoginUri}
doc_category={DOC_CATEGORY}
disabled={viewOnly}
/>
Expand All @@ -151,7 +136,7 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
label="fields.requestUris"
formik={formik}
placeholder={t('Enter a valid request uri eg') + ' https://...'}
value={client.requestUris || []}
value={formik.values.requestUris || []}
options={requestUris}
validator={uriValidator}
inputId={request_uri_id}
Expand All @@ -164,8 +149,8 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
name="defaultAcrValues"
label="fields.defaultAcrValues"
formik={formik}
value={getMapping(client.defaultAcrValues, scripts)}
options={scripts}
value={getMapping(formik.values.defaultAcrValues, filteredScripts)}
options={filteredScripts}
doc_category={DOC_CATEGORY}
lsize={3}
rsize={9}
Expand All @@ -175,8 +160,8 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
name="authorizedAcrValues"
label="fields.authorizedAcrValues"
formik={formik}
value={getMapping(client.authorizedAcrValues, scripts)}
options={scripts}
value={getMapping(formik.values.authorizedAcrValues, filteredScripts)}
options={filteredScripts}
doc_category={DOC_CATEGORY}
lsize={3}
rsize={9}
Expand All @@ -188,43 +173,41 @@ function ClientAdvancedPanel({ client, scripts, formik, viewOnly }) {
rsize={9}
formik={formik}
label="fields.defaultPromptLogin"
value={client.jansDefaultPromptLogin}
value={formik.values.jansDefaultPromptLogin}
doc_category={DOC_CATEGORY}
disabled={viewOnly}
/>
<GluuInputRow
label="fields.tls_client_auth_subject_dn"
name="tlsClientAuthSubjectDn"
formik={formik}
value={client.tlsClientAuthSubjectDn}
value={formik.values.tlsClientAuthSubjectDn}
doc_category={DOC_CATEGORY}
disabled={viewOnly}
/>

<FormGroup row>
<Col sm={6}>
{client.expirable && (
<GluuToogleRow
name="expirable"
formik={formik}
label="fields.is_expirable_client"
value={client.expirable?.length ? true : false}
handler={handleExpirable}
value={formik.values.expirable}
doc_category={DOC_CATEGORY}
lsize={6}
rsize={6}
disabled={viewOnly}
/>
)}
</Col>
<Col sm={6}>
{client.expirable?.length ? (
{formik.values.expirable ? (
<FormGroup row>
<Col sm={12}>
<LocalizationProvider dateAdapter={AdapterDayjs}>
<DateTimePicker
id="expirationDate"
name="expirationDate"
disablePast
value={expirationDate}
onChange={(date) => {
formik.setFieldValue('expirationDate', new Date(date))
Expand Down
Loading