@@ -26,9 +26,10 @@ import { save } from 'reducers/editor';
26
26
import { getMap } from 'reducers/map/selectors' ;
27
27
import { getInfraID } from 'reducers/osrdconf/selectors' ;
28
28
import { CatenaryEntity , SpeedSectionEntity , TrackSectionEntity } from 'types' ;
29
-
29
+ import DebouncedNumberInputSNCF from 'common/BootstrapSNCF/FormSNCF/DebouncedNumberInputSNCF' ;
30
+ import { WidgetProps } from '@rjsf/core' ;
30
31
import { TrackEditionState } from './types' ;
31
- import { injectGeometry } from './utils' ;
32
+ import { injectGeometry , removeInvalidRanges } from './utils' ;
32
33
33
34
export const TRACK_LAYER_ID = 'trackEditionTool/new-track-path' ;
34
35
export const POINTS_LAYER_ID = 'trackEditionTool/new-track-points' ;
@@ -346,6 +347,14 @@ export const TrackEditionLayers: FC = () => {
346
347
) ;
347
348
} ;
348
349
350
+ export const CustomLengthInput : React . FC < WidgetProps > = ( props ) => {
351
+ const { onChange, value } = props ;
352
+
353
+ return (
354
+ < DebouncedNumberInputSNCF debouncedDelay = { 1500 } input = { value } setInput = { onChange } label = "" />
355
+ ) ;
356
+ } ;
357
+
349
358
export const TrackEditionLeftPanel : FC = ( ) => {
350
359
const dispatch = useDispatch ( ) ;
351
360
const { t } = useTranslation ( ) ;
@@ -354,7 +363,7 @@ export const TrackEditionLeftPanel: FC = () => {
354
363
EditorContext
355
364
) as ExtendedEditorContextType < TrackEditionState > ;
356
365
const submitBtnRef = useRef < HTMLButtonElement > ( null ) ;
357
- const { track } = state ;
366
+ const { track, initialTrack } = state ;
358
367
const isNew = track . properties . id === NEW_ENTITY_ID ;
359
368
360
369
// Hack to be able to launch the submit event from the rjsf form by using
@@ -371,6 +380,11 @@ export const TrackEditionLeftPanel: FC = () => {
371
380
< >
372
381
< EditorForm
373
382
data = { track }
383
+ overrideUiSchema = { {
384
+ length : {
385
+ 'ui:widget' : CustomLengthInput ,
386
+ } ,
387
+ } }
374
388
onSubmit = { async ( savedEntity ) => {
375
389
// eslint-disable-next-line @typescript-eslint/no-explicit-any
376
390
const res : any = await dispatch (
@@ -403,7 +417,26 @@ export const TrackEditionLeftPanel: FC = () => {
403
417
} ) ;
404
418
} }
405
419
onChange = { ( newTrack ) => {
406
- setState ( { ...state , track : newTrack as TrackSectionEntity } ) ;
420
+ let checkedTrack = { ...newTrack } ;
421
+ if ( initialTrack . properties . length !== newTrack . properties . length ) {
422
+ const { loading_gauge_limits, slopes, curves, length : newLength } = newTrack . properties ;
423
+ const validLoadingGaugeLimits = removeInvalidRanges ( loading_gauge_limits , newLength ) ;
424
+ const validCurves = removeInvalidRanges ( curves , newLength ) ;
425
+ const validSlopes = removeInvalidRanges ( slopes , newLength ) ;
426
+ checkedTrack = {
427
+ ...checkedTrack ,
428
+ properties : {
429
+ ...checkedTrack . properties ,
430
+ loading_gauge_limits : validLoadingGaugeLimits ,
431
+ slopes : validSlopes ,
432
+ curves : validCurves ,
433
+ } ,
434
+ } ;
435
+ }
436
+ setState ( {
437
+ ...state ,
438
+ track : checkedTrack as TrackSectionEntity ,
439
+ } ) ;
407
440
} }
408
441
>
409
442
< div >
0 commit comments