Skip to content

Commit 355f023

Browse files
committed
front: infra editor make slopes and curves optional values
make slopes and curves value optional improve chart
1 parent 59b59b5 commit 355f023

File tree

9 files changed

+99
-77
lines changed

9 files changed

+99
-77
lines changed

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ function EditorForm<T extends Omit<EditorEntity, 'objType'> & { objType: string
124124
}}
125125
onChange={(event) => {
126126
setFormData({ ...data.properties, ...event.formData });
127-
if (onChange) {
128-
onChange({ ...data, properties: { ...data.properties, ...event.formData } });
129-
}
127+
onChange?.({ ...data, properties: { ...data.properties, ...event.formData } });
130128
}}
131129
>
132130
{children}

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

+44-38
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import {
2323
} from 'common/IntervalsDataViz/data';
2424
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
2525
import { LinearMetadataDataviz } from 'common/IntervalsDataViz/dataviz';
26-
import { useModal } from '../../../../common/BootstrapSNCF/ModalSNCF';
26+
import { useModal } from 'common/BootstrapSNCF/ModalSNCF';
27+
import { tooltipPosition, notEmpty } from 'common/IntervalsDataViz/utils';
2728
import HelpModal from './HelpModal';
28-
import { tooltipPosition, notEmpty } from '../../../../common/IntervalsDataViz/utils';
2929

3030
import { LinearMetadataTooltip } from './tooltip';
3131
import { FormBeginEndWidget } from './FormBeginEndWidget';
@@ -66,12 +66,19 @@ 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
() =>
7278
getFieldJsonSchema(
7379
schema,
7480
registry.rootSchema,
81+
requiredFilter,
7582
distance
7683
? {
7784
begin: {
@@ -108,6 +115,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
108115

109116
const customOnChange = useCallback(
110117
(newData: Array<LinearMetadataItem>) => {
118+
// Remove item without value, it will be recreated by the fixLinearMetadataItems function
111119
onChange(newData.filter((e) => (valueField ? !isNil(e[valueField]) : true)));
112120
},
113121
[onChange, valueField]
@@ -337,7 +345,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
337345
noHtml5Validate
338346
tagName="div"
339347
schema={
340-
(getFieldJsonSchema(schema, registry.rootSchema, {
348+
(getFieldJsonSchema(schema, registry.rootSchema, requiredFilter, {
341349
begin: {
342350
minimum: 0,
343351
maximum: fnMax([selectedData.begin, selectedData.end - SEGMENT_MIN_SIZE]),
@@ -363,43 +371,41 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
363371
}}
364372
formData={selectedData}
365373
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-
};
374+
const newItem = e.formData;
375+
const oldItem = data[selected];
376+
let newData = [...data];
377+
// we keep the old value for begin and end
378+
// they will be change in the resize function if needed
379+
newData[selected] = {
380+
...oldItem,
381+
...omit(newItem, ['begin', 'end']),
382+
};
376383

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);
384+
// Check if there is a resize
385+
try {
386+
if (newItem.begin !== oldItem.begin) {
387+
const resizeBegin = resizeSegment(
388+
[...newData],
389+
selected,
390+
newItem.begin - oldItem.begin,
391+
'begin'
392+
);
393+
newData = resizeBegin.result;
394+
}
395+
if (oldItem.end !== newItem.end) {
396+
const resizeEnd = resizeSegment(
397+
[...newData],
398+
selected,
399+
newItem.end - oldItem.end,
400+
'end'
401+
);
402+
newData = resizeEnd.result;
402403
}
404+
customOnChange(newData);
405+
} catch (error) {
406+
// TODO: Should we display the resize error ?
407+
} finally {
408+
setSelectedData(newItem);
403409
}
404410
}}
405411
>

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { JSONSchema7 } from 'json-schema';
33
import { LinearMetadataItem } from 'common/IntervalsDataViz/types';
4+
import { isNil } from 'lodash';
45

56
interface LinearMetadataTooltipProps<T> {
67
item: LinearMetadataItem<T>;
@@ -38,7 +39,7 @@ export const LinearMetadataTooltip = <T extends Record<string, unknown>>({
3839
<span className="mr-3">
3940
{((schema.properties || {})[k] as JSONSchema7 | undefined)?.title || k}
4041
</span>
41-
{`${item[k] || '-'}`}
42+
{isNil(item[k]) ? '-' : `${item[k]}`}
4243
</div>
4344
))}
4445
</div>

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

+19-10
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,27 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
5656
valueText = `${interval[field]}`;
5757
}
5858
}
59+
60+
const hasNoData =
61+
!!field &&
62+
(segment === undefined || segment[field] === undefined || segment[field] === emptyValue);
63+
const hasData =
64+
!!field &&
65+
segment !== undefined &&
66+
segment[field] !== undefined &&
67+
segment[field] !== emptyValue;
68+
const fieldValue = !!field && segment !== undefined && segment[field];
69+
const isDataZero = fieldValue === 0;
70+
5971
return (
6072
<div
6173
className={cx(
6274
'item',
6375
highlighted.includes(segment.index) && 'highlighted',
64-
field &&
65-
segment !== undefined &&
66-
segment[field] !== undefined &&
67-
segment[field] !== emptyValue &&
68-
'with-data',
69-
field &&
70-
(segment === undefined ||
71-
segment[field] === undefined ||
72-
segment[field] === emptyValue) &&
73-
'no-data',
76+
{
77+
'with-data': hasData,
78+
'no-data': hasNoData,
79+
},
7480
!field && isNilObject(segment, ['begin', 'end', 'index']) && 'no-data'
7581
)}
7682
style={{
@@ -147,6 +153,9 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
147153
<span className="value" style={{ height: '100%' }} />
148154
)}
149155

156+
{hasNoData && <div className="no-data-line" style={computeStyleForDataValue(0, min, max)} />}
157+
{isDataZero && <div className="zero-line" style={computeStyleForDataValue(0, min, max)} />}
158+
150159
{/* Create a div for the resize */}
151160
{data[segment.index] && segment.end === data[segment.index].end && (
152161
<div

front/src/common/IntervalsDataViz/data.ts

+5
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ export function entityDoUpdate<T extends EditorEntity>(entity: T, sourceLine: Li
688688
export function getFieldJsonSchema(
689689
fieldSchema: JSONSchema7,
690690
rootSchema: JSONSchema7,
691+
requiredFilter?: (required: string[]) => string[],
691692
enhancement: { [key: string]: JSONSchema7Definition } = {}
692693
): JSONSchema7 {
693694
let result = { ...fieldSchema };
@@ -698,6 +699,10 @@ export function getFieldJsonSchema(
698699
...result,
699700
items: {
700701
...itemsSchema,
702+
required:
703+
requiredFilter && itemsSchema.required && isArray(itemsSchema.required)
704+
? requiredFilter(itemsSchema.required)
705+
: itemsSchema.required,
701706
properties: {
702707
begin: {
703708
...(itemsSchema.properties?.begin as JSONSchema7),

front/src/common/IntervalsDataViz/dataviz.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { head, isNil, last, maxBy, minBy } from 'lodash';
33
import cx from 'classnames';
44

55
import { AdditionalDataItem } from 'common/IntervalsEditor/types';
6-
import { preventDefault, computeStyleForDataValue, getPositionFromMouseEvent } from './utils';
6+
import { preventDefault, getPositionFromMouseEvent } from './utils';
77
import {
88
cropForDatavizViewbox,
99
cropOperationPointsForDatavizViewbox,
@@ -366,10 +366,6 @@ export const LinearMetadataDataviz = <T extends { [key: string]: any }>({
366366
(viewBox === null || viewBox[1] === last(data)?.end) && 'end-visible'
367367
)}
368368
>
369-
{/* Display the 0 axis if it's necessary */}
370-
{min < 0 && max > 0 && (
371-
<div className="axis-zero" style={computeStyleForDataValue(0, min, max)} />
372-
)}
373369
{/* Display the Y axis if there is one */}
374370
{field && min !== max && !options.fullHeightItem && (
375371
<SimpleScale className="scale-y" begin={min} end={max} />

front/src/common/IntervalsDataViz/style.scss

+22-20
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,24 @@ $resize-width: 3px;
153153
flex-direction: row;
154154
align-items: flex-end;
155155
justify-content: flex-end;
156+
position: relative;
156157

157-
&.no-data {
158-
background-color: mixw($color, 0.9);
159-
background-image: repeating-linear-gradient(
160-
45deg,
161-
$color-nodata,
162-
$color-nodata 1px,
163-
transparent 2px,
164-
transparent 10px
165-
);
166-
167-
&.highlighted {
168-
background-color: $color-highlight;
169-
}
158+
.zero-line {
159+
position: absolute !important;
160+
width: 100%;
161+
right: 0;
162+
left: 0;
163+
z-index: 1;
164+
border-bottom: 1px solid $color;
165+
}
166+
167+
.no-data-line {
168+
position: absolute !important;
169+
width: 100%;
170+
right: 0;
171+
left: 0;
172+
z-index: 1;
173+
border-bottom: 1px dashed var(--coolgray9);
170174
}
171175

172176
&.with-data {
@@ -178,6 +182,10 @@ $resize-width: 3px;
178182
div.value {
179183
background-color: $color-highlight;
180184
}
185+
186+
.zero-line {
187+
border-bottom-color: $color-highlight;
188+
}
181189
}
182190

183191
div.value {
@@ -269,13 +277,6 @@ $resize-width: 3px;
269277
}
270278
}
271279

272-
.axis-zero {
273-
position: absolute !important;
274-
width: 100%;
275-
border-bottom: 1px solid red;
276-
z-index: 1;
277-
}
278-
279280
.scale {
280281
display: flex;
281282
justify-content: space-between;
@@ -312,6 +313,7 @@ $resize-width: 3px;
312313
align-items: center;
313314
width: 100%;
314315
height: 100%;
316+
padding-right: 2px;
315317
div {
316318
position: relative;
317319
top: 0;

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)