Skip to content

Commit 2976e4c

Browse files
committed
fixup! front: infra editor make slopes and curves optional values
1 parent be313a6 commit 2976e4c

File tree

6 files changed

+25
-36
lines changed

6 files changed

+25
-36
lines changed

front/src/applications/editor/components/EditorForm.tsx

-10
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,6 @@ function EditorForm<T extends Omit<EditorEntity, 'objType'> & { objType: string
8484
}
8585
}, [error]);
8686

87-
useEffect(() => {
88-
if (!data.properties.curves || !data.properties.slopes) {
89-
setFormData({
90-
...data.properties,
91-
slopes: data.properties.slopes ?? [],
92-
curves: data.properties.curves ?? [],
93-
});
94-
}
95-
}, [data.properties.length]);
96-
9787
return (
9888
<div>
9989
{submited && error !== null && (

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

+14-19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
7878
getFieldJsonSchema(
7979
schema,
8080
registry.rootSchema,
81+
requiredFilter,
8182
distance
8283
? {
8384
begin: {
@@ -89,8 +90,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
8990
maximum: distance,
9091
},
9192
}
92-
: {},
93-
requiredFilter
93+
: {}
9494
),
9595
[schema, registry.rootSchema, distance]
9696
);
@@ -345,24 +345,19 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
345345
noHtml5Validate
346346
tagName="div"
347347
schema={
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-
},
348+
(getFieldJsonSchema(schema, registry.rootSchema, requiredFilter, {
349+
begin: {
350+
minimum: 0,
351+
maximum: fnMax([selectedData.begin, selectedData.end - SEGMENT_MIN_SIZE]),
363352
},
364-
requiredFilter
365-
).items as JSONSchema7) || {}
353+
end: {
354+
minimum: fnMin([selectedData.end, data[selected].begin + SEGMENT_MIN_SIZE]),
355+
maximum:
356+
selected !== data.length - 1
357+
? fnMax([selectedData.end, data[selected + 1].end - SEGMENT_MIN_SIZE])
358+
: selectedData.end,
359+
},
360+
}).items as JSONSchema7) || {}
366361
}
367362
uiSchema={{
368363
begin: {

front/src/applications/editor/tools/trackEdition/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function getNewLine(points: [number, number][]): TrackSectionEntity {
1313
properties: {
1414
id: NEW_ENTITY_ID,
1515
length: 0,
16+
slopes: [],
17+
curves: [],
1618
},
1719
};
1820
}

front/src/common/IntervalsDataViz/IntervalItem.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
7575
highlighted.includes(segment.index) && 'highlighted',
7676
{
7777
'with-data': hasData,
78-
'no-data': hasNoData
78+
'no-data': hasNoData,
7979
},
8080
!field && isNilObject(segment, ['begin', 'end', 'index']) && 'no-data'
8181
)}

front/src/common/IntervalsDataViz/data.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -688,10 +688,9 @@ 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 },
692-
requiredFilter?: (required: string[]) => string[]
691+
requiredFilter?: (required: string[]) => string[],
692+
enhancement: { [key: string]: JSONSchema7Definition } = {}
693693
): JSONSchema7 {
694-
const enhancementValues = enhancement ?? {};
695694
let result = { ...fieldSchema };
696695
if (fieldSchema.items) {
697696
const itemsSchema = utils.retrieveSchema(fieldSchema.items as JSONSchema7, rootSchema);
@@ -707,11 +706,11 @@ export function getFieldJsonSchema(
707706
properties: {
708707
begin: {
709708
...(itemsSchema.properties?.begin as JSONSchema7),
710-
...(enhancementValues.begin as JSONSchema7),
709+
...(enhancement.begin as JSONSchema7),
711710
},
712711
end: {
713712
...(itemsSchema.properties?.end as JSONSchema7),
714-
...(enhancementValues.end as JSONSchema7),
713+
...(enhancement.end as JSONSchema7),
715714
},
716715
...Object.keys(itemsSchema.properties || {})
717716
.filter((k) => !['begin', 'end'].includes(k))
@@ -722,7 +721,7 @@ export function getFieldJsonSchema(
722721
.reduce((acc, curr) => {
723722
acc[curr.name] = {
724723
...(curr.schema as JSONSchema7),
725-
...(enhancementValues[curr.name] as JSONSchema7),
724+
...(enhancement[curr.name] as JSONSchema7),
726725
};
727726
return acc;
728727
}, {} as { [key: string]: JSONSchema7Definition }),

front/src/types/editor.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JSONSchema7 } from 'json-schema';
22
import { Feature, GeoJsonProperties, Geometry, Point, LineString, MultiLineString } from 'geojson';
33
import { Direction, DirectionalTrackRange, ObjectType } from 'common/api/osrdEditoastApi';
4+
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
45
import { NullGeometry } from './geospatial';
56

67
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -22,6 +23,8 @@ export interface TrackSectionEntity
2223
LineString,
2324
{
2425
length: number;
26+
slopes: LinearMetadataItem<{ gradient: number }>[];
27+
curves: LinearMetadataItem<{ radius: number }>[];
2528
extensions?: {
2629
sncf?: {
2730
line_code?: number;

0 commit comments

Comments
 (0)