Skip to content

Commit 091fb50

Browse files
committed
fixup! front: infra editor make slopes and curves optional values
1 parent 67c9d2c commit 091fb50

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

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

+27-15
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import {
2424
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
2525
import { LinearMetadataDataviz } from 'common/IntervalsDataViz/dataviz';
2626
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
27-
import HelpModal from './HelpModal';
2827
import { tooltipPosition, notEmpty } from 'common/IntervalsDataViz/utils';
28+
import HelpModal from './HelpModal';
2929

3030
import { LinearMetadataTooltip } from './tooltip';
3131
import { FormBeginEndWidget } from './FormBeginEndWidget';
@@ -66,6 +66,12 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
6666
return 0;
6767
}, [formContext]);
6868

69+
// Remove the 'valueField' required field because it is required by the backend. However,
70+
// the segment with missing values is filtered in 'customOnChange' before being sent to the backend,
71+
// and then re-added by 'fixLinearMetadataItems'.
72+
const requiredFilter = (requireds: string[]) =>
73+
requireds.filter((r) => ['end', 'begin'].includes(r));
74+
6975
// Compute the JSON schema of the linear metadata item
7076
const jsonSchema = useMemo(
7177
() =>
@@ -83,7 +89,8 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
8389
maximum: distance,
8490
},
8591
}
86-
: {}
92+
: {},
93+
requiredFilter
8794
),
8895
[schema, registry.rootSchema, distance]
8996
);
@@ -338,19 +345,24 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
338345
noHtml5Validate
339346
tagName="div"
340347
schema={
341-
(getFieldJsonSchema(schema, registry.rootSchema, {
342-
begin: {
343-
minimum: 0,
344-
maximum: fnMax([selectedData.begin, selectedData.end - SEGMENT_MIN_SIZE]),
345-
},
346-
end: {
347-
minimum: fnMin([selectedData.end, data[selected].begin + SEGMENT_MIN_SIZE]),
348-
maximum:
349-
selected !== data.length - 1
350-
? fnMax([selectedData.end, data[selected + 1].end - SEGMENT_MIN_SIZE])
351-
: selectedData.end,
348+
(getFieldJsonSchema(
349+
schema,
350+
registry.rootSchema,
351+
{
352+
begin: {
353+
minimum: 0,
354+
maximum: fnMax([selectedData.begin, selectedData.end - SEGMENT_MIN_SIZE]),
355+
},
356+
end: {
357+
minimum: fnMin([selectedData.end, data[selected].begin + SEGMENT_MIN_SIZE]),
358+
maximum:
359+
selected !== data.length - 1
360+
? fnMax([selectedData.end, data[selected + 1].end - SEGMENT_MIN_SIZE])
361+
: selectedData.end,
362+
},
352363
},
353-
}).items as JSONSchema7) || {}
364+
requiredFilter
365+
).items as JSONSchema7) || {}
354366
}
355367
uiSchema={{
356368
begin: {
@@ -394,7 +406,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
394406
);
395407
newData = resizeEnd.result;
396408
}
397-
onChange(newData);
409+
customOnChange(newData);
398410
} catch (error) {
399411
// TODO: Should we display the resize error ?
400412
} finally {

front/src/common/IntervalsDataViz/data.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,10 @@ export function entityDoUpdate<T extends EditorEntity>(entity: T, sourceLine: Li
688688
export function getFieldJsonSchema(
689689
fieldSchema: JSONSchema7,
690690
rootSchema: JSONSchema7,
691-
enhancement: { [key: string]: JSONSchema7Definition } = {}
691+
enhancement: { [key: string]: JSONSchema7Definition },
692+
requiredFilter?: (required: string[]) => string[]
692693
): JSONSchema7 {
694+
const enhancementValues = enhancement ?? {};
693695
let result = { ...fieldSchema };
694696
if (fieldSchema.items) {
695697
const itemsSchema = utils.retrieveSchema(fieldSchema.items as JSONSchema7, rootSchema);
@@ -698,14 +700,18 @@ export function getFieldJsonSchema(
698700
...result,
699701
items: {
700702
...itemsSchema,
703+
required:
704+
requiredFilter && itemsSchema.required && isArray(itemsSchema.required)
705+
? requiredFilter(itemsSchema.required)
706+
: itemsSchema.required,
701707
properties: {
702708
begin: {
703709
...(itemsSchema.properties?.begin as JSONSchema7),
704-
...(enhancement.begin as JSONSchema7),
710+
...(enhancementValues.begin as JSONSchema7),
705711
},
706712
end: {
707713
...(itemsSchema.properties?.end as JSONSchema7),
708-
...(enhancement.end as JSONSchema7),
714+
...(enhancementValues.end as JSONSchema7),
709715
},
710716
...Object.keys(itemsSchema.properties || {})
711717
.filter((k) => !['begin', 'end'].includes(k))
@@ -716,7 +722,7 @@ export function getFieldJsonSchema(
716722
.reduce((acc, curr) => {
717723
acc[curr.name] = {
718724
...(curr.schema as JSONSchema7),
719-
...(enhancement[curr.name] as JSONSchema7),
725+
...(enhancementValues[curr.name] as JSONSchema7),
720726
};
721727
return acc;
722728
}, {} as { [key: string]: JSONSchema7Definition }),

front/src/reducers/osrdconf/infra_schema.json

+2
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
}
255255
},
256256
"required": [
257+
"radius",
257258
"begin",
258259
"end"
259260
],
@@ -1152,6 +1153,7 @@
11521153
}
11531154
},
11541155
"required": [
1156+
"gradient",
11551157
"begin",
11561158
"end"
11571159
],

0 commit comments

Comments
 (0)