Skip to content

Commit

Permalink
fix(admin-ui): not able to change location type on edit script
Browse files Browse the repository at this point in the history
  • Loading branch information
jv18creator committed Jul 20, 2023
1 parent 086544e commit d09e180
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ function CustomScriptEditPage({
}
}

const moduleProperties = item.moduleProperties ? item.moduleProperties.map((item) => item) : []

return (
<GluuLoader blocking={loading}>
<GluuAlert
Expand All @@ -47,7 +49,7 @@ function CustomScriptEditPage({
<Card className="mb-3" style={applicationStyle.mainCard}>
<CardBody>
<CustomScriptForm
item={{ ...item }}
item={{ ...item, moduleProperties }}
scripts={scripts}
viewOnly={viewOnly}
handleSubmit={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Alert, Button } from "reactstrap";
import ErrorIcon from '@mui/icons-material/Error';

function CustomScriptForm({ item, scripts, handleSubmit, viewOnly }) {
console.log(`;is is`, Object.isExtensible(item.moduleProperties));
const { t } = useTranslation()
const [init, setInit] = useState(false)
const [modal, setModal] = useState(false)
Expand Down Expand Up @@ -90,17 +91,36 @@ function CustomScriptForm({ item, scripts, handleSubmit, viewOnly }) {
aliases: item.aliases,
moduleProperties: item.moduleProperties,
configurationProperties: item.configurationProperties,
script_path: scriptPath
},
validationSchema: Yup.object({
name: Yup.string().matches(/^[a-zA-Z0-9_]+$/,"Name should contain only letters, digits and underscores").min(2, 'Mininum 2 characters').required('Required!'),
name: Yup.string()
.matches(
/^[a-zA-Z0-9_]+$/,
'Name should contain only letters, digits and underscores'
)
.min(2, 'Mininum 2 characters')
.required('Required!'),
description: Yup.string(),
scriptType: Yup.string()
.min(2, 'Mininum 2 characters')
.required('Required!'),
programmingLanguage: Yup.string()
.min(3, 'This value is required')
.required('Required!'),
script: Yup.object().shape().when('location_type', { is: 'db', then: () => Yup.string().required('Required!') })
script: Yup.string().when('location_type', {
is: (value) => {
console.log('the value', value)
return value === 'db'
},
then: () => Yup.string().required('Required!'),
}),
script_path: Yup.string().when('location_type', {
is: (value) => {
return value === 'file'
},
then: () => Yup.string().required('Required!'),
}),
}),

onSubmit: (values) => {
Expand Down Expand Up @@ -414,7 +434,7 @@ function CustomScriptForm({ item, scripts, handleSubmit, viewOnly }) {
{scriptPath && (

<FormGroup row>
<GluuLabel label="fields.script_path" doc_category={SCRIPT} doc_entry="scriptPath" />
<GluuLabel required label="fields.script_path" doc_category={SCRIPT} doc_entry="scriptPath" />
<Col sm={9}>
<InputGroup>
<Input
Expand All @@ -438,9 +458,16 @@ function CustomScriptForm({ item, scripts, handleSubmit, viewOnly }) {
}
onChange={(e) => {
scriptPathChange(e.target.value)
formik.setFieldValue('script_path', e.target.value)
}}
/>
</InputGroup>
{formik.errors.script_path &&
formik.touched.script_path && (
<div style={{ color: 'red' }}>
{formik.errors.script_path}
</div>
)}
</Col>
</FormGroup>
)}
Expand Down

0 comments on commit d09e180

Please sign in to comment.