@@ -31,9 +31,10 @@ import {
31
31
SpeedSectionEntity ,
32
32
TrackSectionEntity ,
33
33
} from 'types' ;
34
-
34
+ import DebouncedNumberInputSNCF from 'common/BootstrapSNCF/FormSNCF/DebouncedNumberInputSNCF' ;
35
+ import { WidgetProps } from '@rjsf/core' ;
35
36
import { TrackEditionState } from './types' ;
36
- import { injectGeometry } from './utils' ;
37
+ import { injectGeometry , removeInvalidRanges } from './utils' ;
37
38
38
39
export const TRACK_LAYER_ID = 'trackEditionTool/new-track-path' ;
39
40
export const POINTS_LAYER_ID = 'trackEditionTool/new-track-points' ;
@@ -351,6 +352,21 @@ export const TrackEditionLayers: FC = () => {
351
352
) ;
352
353
} ;
353
354
355
+ export const CustomLengthInput : React . FC < WidgetProps > = ( props ) => {
356
+ const { onChange, value } = props ;
357
+
358
+ return (
359
+ < DebouncedNumberInputSNCF
360
+ debouncedDelay = { 2000 }
361
+ input = { value }
362
+ setInput = { onChange }
363
+ label = ""
364
+ showFlex = { false }
365
+ sm = { false }
366
+ />
367
+ ) ;
368
+ } ;
369
+
354
370
export const TrackEditionLeftPanel : FC = ( ) => {
355
371
const dispatch = useDispatch ( ) ;
356
372
const { t } = useTranslation ( ) ;
@@ -359,7 +375,7 @@ export const TrackEditionLeftPanel: FC = () => {
359
375
EditorContext
360
376
) as ExtendedEditorContextType < TrackEditionState > ;
361
377
const submitBtnRef = useRef < HTMLButtonElement > ( null ) ;
362
- const { track } = state ;
378
+ const { track, initialTrack } = state ;
363
379
const isNew = track . properties . id === NEW_ENTITY_ID ;
364
380
365
381
// Hack to be able to launch the submit event from the rjsf form by using
@@ -376,6 +392,11 @@ export const TrackEditionLeftPanel: FC = () => {
376
392
< >
377
393
< EditorForm
378
394
data = { track }
395
+ overrideUiSchema = { {
396
+ length : {
397
+ 'ui:widget' : CustomLengthInput ,
398
+ } ,
399
+ } }
379
400
onSubmit = { async ( savedEntity ) => {
380
401
// eslint-disable-next-line @typescript-eslint/no-explicit-any
381
402
const res : any = await dispatch (
@@ -408,7 +429,26 @@ export const TrackEditionLeftPanel: FC = () => {
408
429
} ) ;
409
430
} }
410
431
onChange = { ( newTrack ) => {
411
- setState ( { ...state , track : newTrack as TrackSectionEntity } ) ;
432
+ let checkedTrack = { ...newTrack } ;
433
+ if ( initialTrack . properties . length !== newTrack . properties . length ) {
434
+ const { loading_gauge_limits, slopes, curves, length : newLength } = newTrack . properties ;
435
+ const validLoadingGaugeLimits = removeInvalidRanges ( loading_gauge_limits , newLength ) ;
436
+ const validCurves = removeInvalidRanges ( curves , newLength ) ;
437
+ const validSlopes = removeInvalidRanges ( slopes , newLength ) ;
438
+ checkedTrack = {
439
+ ...checkedTrack ,
440
+ properties : {
441
+ ...checkedTrack . properties ,
442
+ loading_gauge_limits : validLoadingGaugeLimits ,
443
+ slopes : validSlopes ,
444
+ curves : validCurves ,
445
+ } ,
446
+ } ;
447
+ }
448
+ setState ( {
449
+ ...state ,
450
+ track : { ...( checkedTrack as TrackSectionEntity ) } ,
451
+ } ) ;
412
452
} }
413
453
>
414
454
< div >
0 commit comments