Commit fd7b6a4 1 parent 87e7484 commit fd7b6a4 Copy full SHA for fd7b6a4
File tree 3 files changed +19
-13
lines changed
front/src/applications/operationalStudies/components/MacroEditor
3 files changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,12 @@ import { Duration } from 'utils/duration';
13
13
import { DEFAULT_TRAINRUN_FREQUENCIES , DEFAULT_TRAINRUN_FREQUENCY } from './consts' ;
14
14
import type MacroEditorState from './MacroEditorState' ;
15
15
import type { NodeIndexed } from './MacroEditorState' ;
16
- import { createMacroNode , deleteMacroNodeByNgeId , updateMacroNode } from './utils' ;
16
+ import {
17
+ createMacroNode ,
18
+ deleteMacroNodeByNgeId ,
19
+ trainrunFrequencyFromLabel ,
20
+ updateMacroNode ,
21
+ } from './utils' ;
17
22
import type {
18
23
NetzgrafikDto ,
19
24
NGEEvent ,
@@ -209,7 +214,7 @@ const createTrainSchedulePayload = async ({
209
214
}
210
215
211
216
const trainScheduleLabels =
212
- trainSchedule ?. labels ?. filter ( ( label ) => label . match ( / ^ f r e q u e n c y : : (? ! 3 0 $ | 6 0 $ | 1 2 0 $ ) \d + $ / ) ) || [ ] ;
217
+ trainSchedule ?. labels ?. filter ( ( label ) => trainrunFrequencyFromLabel ( label ) !== null ) || [ ] ;
213
218
214
219
trainrunLabels = uniq ( [ ...trainrunLabels , ...trainScheduleLabels ] ) ;
215
220
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ import {
18
18
DEFAULT_DTO ,
19
19
} from './consts' ;
20
20
import MacroEditorState , { type NodeIndexed } from './MacroEditorState' ;
21
- import { deleteMacroNodeByDbId , getSavedMacroNodes } from './utils' ;
21
+ import { deleteMacroNodeByDbId , getSavedMacroNodes , trainrunFrequencyFromLabel } from './utils' ;
22
22
import {
23
23
type PortDto ,
24
24
type TimeLockDto ,
@@ -130,16 +130,6 @@ const castNodeToNge = (
130
130
) ,
131
131
} ) ;
132
132
133
- /**
134
- * Match a frequency label to a NGE TrainrunFrequency, or `null` if not handled.
135
- */
136
- const trainrunFrequencyFromLabel = ( label : string ) => {
137
- if ( ! label . startsWith ( 'frequency::' ) ) return null ;
138
- const n = parseInt ( label . split ( '::' , 2 ) [ 1 ] , 10 ) ;
139
- const frequency = DEFAULT_TRAINRUN_FREQUENCIES . find ( ( freq ) => freq . frequency === n ) ;
140
- return frequency ?? null ;
141
- } ;
142
-
143
133
/**
144
134
* NGE trainrun frequency is stored as OSRD labels (`"frequency::30"` or `"frequency::120"`).
145
135
* Update the current frequency if the new frequency is smaller.
Original file line number Diff line number Diff line change 8
8
} from 'common/api/osrdEditoastApi' ;
9
9
import type { AppDispatch } from 'store' ;
10
10
11
+ import { DEFAULT_TRAINRUN_FREQUENCIES } from './consts' ;
11
12
import type MacroEditorState from './MacroEditorState' ;
12
13
import type { NodeIndexed } from './MacroEditorState' ;
13
14
@@ -161,3 +162,13 @@ export const getSavedMacroNodes = async (
161
162
}
162
163
return result ;
163
164
} ;
165
+
166
+ /**
167
+ * Match a frequency label to a NGE TrainrunFrequency, or `null` if not handled.
168
+ */
169
+ export const trainrunFrequencyFromLabel = ( label : string ) => {
170
+ if ( ! label . startsWith ( 'frequency::' ) ) return null ;
171
+ const n = parseInt ( label . split ( '::' , 2 ) [ 1 ] , 10 ) ;
172
+ const frequency = DEFAULT_TRAINRUN_FREQUENCIES . find ( ( freq ) => freq . frequency === n ) ;
173
+ return frequency ?? null ;
174
+ } ;
You can’t perform that action at this time.
0 commit comments