Skip to content

Commit 67c9d2c

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

File tree

5 files changed

+43
-38
lines changed

5 files changed

+43
-38
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function EditorForm<T extends Omit<EditorEntity, 'objType'> & { objType: string
8989
setFormData({
9090
...data.properties,
9191
slopes: data.properties.slopes ?? [],
92-
curves: data.properties.curves ?? []
92+
curves: data.properties.curves ?? [],
9393
});
9494
}
9595
}, [data.properties.length]);

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

+3-2
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';
2727
import HelpModal from './HelpModal';
28-
import { tooltipPosition, notEmpty } from '../../../../common/IntervalsDataViz/utils';
28+
import { tooltipPosition, notEmpty } from 'common/IntervalsDataViz/utils';
2929

3030
import { LinearMetadataTooltip } from './tooltip';
3131
import { FormBeginEndWidget } from './FormBeginEndWidget';
@@ -108,6 +108,7 @@ export const FormComponent: React.FC<FieldProps> = (props) => {
108108

109109
const customOnChange = useCallback(
110110
(newData: Array<LinearMetadataItem>) => {
111+
// Remove item without value, it will be recreated by the fixLinearMetadataItems function
111112
onChange(newData.filter((e) => (valueField ? !isNil(e[valueField]) : true)));
112113
},
113114
[onChange, valueField]

front/src/common/IntervalsDataViz/IntervalItem.tsx

+17-10
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,25 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
5656
valueText = `${interval[field]}`;
5757
}
5858
}
59+
60+
const isNoData =
61+
!!field &&
62+
(segment === undefined || segment[field] === undefined || segment[field] === emptyValue);
63+
const isHasData =
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+
isHasData && 'with-data',
77+
isNoData && 'no-data',
7478
!field && isNilObject(segment, ['begin', 'end', 'index']) && 'no-data'
7579
)}
7680
style={{
@@ -147,6 +151,9 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
147151
<span className="value" style={{ height: '100%' }} />
148152
)}
149153

154+
{isNoData && <div className="no-data-line" style={computeStyleForDataValue(0, min, max)} />}
155+
{isDataZero && <div className="zero-line" style={computeStyleForDataValue(0, min, max)} />}
156+
150157
{/* Create a div for the resize */}
151158
{data[segment.index] && segment.end === data[segment.index].end && (
152159
<div

front/src/common/IntervalsDataViz/dataviz.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { head, 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

+21-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(--orange);
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;

0 commit comments

Comments
 (0)