1
- import { useRef , useState } from 'react' ;
1
+ import { useMemo , useRef , useState } from 'react' ;
2
2
3
3
import { KebabHorizontal } from '@osrd-project/ui-icons' ;
4
4
import { Manchette } from '@osrd-project/ui-manchette' ;
@@ -7,10 +7,12 @@ import { ConflictLayer, PathLayer, SpaceTimeChart } from '@osrd-project/ui-space
7
7
import type { Conflict } from '@osrd-project/ui-spacetimechart' ;
8
8
9
9
import type { OperationalPoint , TrainSpaceTimeData } from 'applications/operationalStudies/types' ;
10
+ import WaypointMenu from 'common/OSRDMenu' ;
10
11
import type { WaypointsPanelData } from 'modules/simulationResult/types' ;
11
12
12
13
import SettingsPanel from './SettingsPanel' ;
13
14
import ManchetteMenuButton from '../SpaceTimeChart/ManchetteMenuButton' ;
15
+ import useWaypointMenu from '../SpaceTimeChart/useWaypointMenu' ;
14
16
import WaypointsPanel from '../SpaceTimeChart/WaypointsPanel' ;
15
17
16
18
type ManchetteWithSpaceTimeChartProps = {
@@ -32,6 +34,8 @@ const ManchetteWithSpaceTimeChartWrapper = ({
32
34
const [ heightOfManchetteWithSpaceTimeChart ] = useState ( DEFAULT_HEIGHT ) ;
33
35
const manchetteWithSpaceTimeChartRef = useRef < HTMLDivElement > ( null ) ;
34
36
37
+ const [ showSettingsPanel , setShowSettingsPanel ] = useState ( false ) ;
38
+ const [ settings , setSettings ] = useState ( { showConflicts : false } ) ;
35
39
const [ waypointsPanelIsOpen , setWaypointsPanelIsOpen ] = useState ( false ) ;
36
40
37
41
const { manchetteProps, spaceTimeChartProps, handleScroll } = useManchettesWithSpaceTimeChart (
@@ -41,8 +45,25 @@ const ManchetteWithSpaceTimeChartWrapper = ({
41
45
selectedTrainScheduleId
42
46
) ;
43
47
44
- const [ showSettingsPanel , setShowSettingsPanel ] = useState ( false ) ;
45
- const [ settings , setSettings ] = useState ( { showConflicts : false } ) ;
48
+ const waypointMenuData = useWaypointMenu (
49
+ manchetteWithSpaceTimeChartRef ,
50
+ waypointsPanelData ?. filteredWaypoints ,
51
+ waypointsPanelData ?. setFilteredWaypoints
52
+ ) ;
53
+
54
+ const manchettePropsWithWaypointMenu = useMemo (
55
+ ( ) => ( {
56
+ ...manchetteProps ,
57
+ operationalPoints : manchetteProps . operationalPoints . map ( ( op ) => ( {
58
+ ...op ,
59
+ onClick : ( id : string , ref : HTMLDivElement | null ) => {
60
+ waypointMenuData . handleWaypointClick ( id , ref ) ;
61
+ } ,
62
+ } ) ) ,
63
+ activeOperationalPointId : waypointMenuData . activeOperationalPointId ,
64
+ } ) ,
65
+ [ manchetteProps , waypointMenuData ]
66
+ ) ;
46
67
47
68
return (
48
69
< div className = "manchette-space-time-chart-wrapper" >
@@ -64,7 +85,19 @@ const ManchetteWithSpaceTimeChartWrapper = ({
64
85
style = { { height : `${ heightOfManchetteWithSpaceTimeChart } px` } }
65
86
onScroll = { handleScroll }
66
87
>
67
- < Manchette { ...manchetteProps } />
88
+ < Manchette { ...manchettePropsWithWaypointMenu } >
89
+ { waypointMenuData . menuPosition && (
90
+ < WaypointMenu
91
+ menuRef = { waypointMenuData . menuRef }
92
+ items = { waypointMenuData . menuItems }
93
+ style = { {
94
+ width : '305px' ,
95
+ top : waypointMenuData . menuPosition . top ,
96
+ left : waypointMenuData . menuPosition . left ,
97
+ } }
98
+ />
99
+ ) }
100
+ </ Manchette >
68
101
< div
69
102
className = "space-time-chart-container"
70
103
style = { {
0 commit comments