Skip to content

Commit cf04158

Browse files
committed
front: editor-slopes-fix-form-validation
Remove local errors check in slopes form and let global form validate the form
1 parent c2b9acd commit cf04158

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

front/src/applications/editor/components/LinearMetadata/FormComponent.tsx

+34-36
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
9595
: {}) as unknown as { [key: string]: JSONSchema7 };
9696
const field = head(
9797
Object.keys(itemProperties)
98-
.filter((e) => !['begin', 'end'].includes(e))
98+
.filter((e) => !['begin', 'end', 'gradient'].includes(e))
9999
.map((e) => ({
100100
name: e,
101101
type: itemProperties[e] ? itemProperties[e].type || '' : '',
@@ -363,43 +363,41 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
363363
}}
364364
formData={selectedData}
365365
onChange={(e) => {
366-
if (e.errors.length === 0) {
367-
const newItem = e.formData;
368-
const oldItem = data[selected];
369-
let newData = [...data];
370-
// we keep the old value for begin and end
371-
// they will be change in the resize function if needed
372-
newData[selected] = {
373-
...oldItem,
374-
...omit(newItem, ['begin', 'end']),
375-
};
366+
const newItem = e.formData;
367+
const oldItem = data[selected];
368+
let newData = [...data];
369+
// we keep the old value for begin and end
370+
// they will be change in the resize function if needed
371+
newData[selected] = {
372+
...oldItem,
373+
...omit(newItem, ['begin', 'end']),
374+
};
376375

377-
// Check if there is a resize
378-
try {
379-
if (newItem.begin !== oldItem.begin) {
380-
const resizeBegin = resizeSegment(
381-
[...newData],
382-
selected,
383-
newItem.begin - oldItem.begin,
384-
'begin'
385-
);
386-
newData = resizeBegin.result;
387-
}
388-
if (oldItem.end !== newItem.end) {
389-
const resizeEnd = resizeSegment(
390-
[...newData],
391-
selected,
392-
newItem.end - oldItem.end,
393-
'end'
394-
);
395-
newData = resizeEnd.result;
396-
}
397-
customOnChange(newData);
398-
} catch (error) {
399-
// TODO: Should we display the resize error ?
400-
} finally {
401-
setSelectedData(newItem);
376+
// Check if there is a resize
377+
try {
378+
if (newItem.begin !== oldItem.begin) {
379+
const resizeBegin = resizeSegment(
380+
[...newData],
381+
selected,
382+
newItem.begin - oldItem.begin,
383+
'begin'
384+
);
385+
newData = resizeBegin.result;
386+
}
387+
if (oldItem.end !== newItem.end) {
388+
const resizeEnd = resizeSegment(
389+
[...newData],
390+
selected,
391+
newItem.end - oldItem.end,
392+
'end'
393+
);
394+
newData = resizeEnd.result;
402395
}
396+
customOnChange(newData);
397+
} catch (error) {
398+
// TODO: Should we display the resize error ?
399+
} finally {
400+
setSelectedData(newItem);
403401
}
404402
}}
405403
>

0 commit comments

Comments
 (0)