Skip to content

Commit

Permalink
feat: allow save range with no signals
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Jan 18, 2024
1 parent 8fcfb77 commit 6f7bfad
Showing 1 changed file with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@ import * as Yup from 'yup';
import { hasCouplingConstant } from '../../../../panels/extra/utilities/MultiplicityUtilities';

const editRangeFormValidation = Yup.object().shape({
signals: Yup.array()
.of(
Yup.object().shape({
js: Yup.array()
.of(
Yup.object().shape({
multiplicity: Yup.string().required(),
coupling: Yup.mixed().test(
'checkValue',
'',
function testCoupling(value) {
signals: Yup.array().of(
Yup.object().shape({
js: Yup.array()
.of(
Yup.object().shape({
multiplicity: Yup.string().required(),
coupling: Yup.mixed().test(
'checkValue',
'',
function testCoupling(value) {
// eslint-disable-next-line no-invalid-this
const { path, createError } = this;
const hasCoupling = hasCouplingConstant(
// eslint-disable-next-line no-invalid-this
const { path, createError } = this;
const hasCoupling = hasCouplingConstant(
// eslint-disable-next-line no-invalid-this
this.parent.multiplicity,
);
if ((!hasCoupling && !value) || (hasCoupling && value)) {
return true;
}
this.parent.multiplicity,
);
if ((!hasCoupling && !value) || (hasCoupling && value)) {
return true;
}

return createError({
path,
message: `${path} is required`,
});
},
),
}),
)
.min(1, 'There must be at least one coupling in a signal'),
}),
)
.min(1, 'There must be at least one signal in a range!'),
return createError({
path,
message: `${path} is required`,
});
},
),
}),
)
.min(1, 'There must be at least one coupling in a signal'),
}),
),
});

export default editRangeFormValidation;

0 comments on commit 6f7bfad

Please sign in to comment.