1
1
/* eslint-disable import/no-unresolved */
2
- import React , { useRef } from 'react' ;
2
+ import React , { useRef , useState } from 'react' ;
3
3
4
+ import { EyeClosed , Telescope } from '@osrd-project/ui-icons' ;
4
5
import { Manchette } from '@osrd-project/ui-manchette' ;
5
6
import type { ProjectPathTrainResult , Waypoint } from '@osrd-project/ui-manchette/dist/types' ;
6
7
import { PathLayer , SpaceTimeChart } from '@osrd-project/ui-spacetimechart' ;
@@ -10,6 +11,8 @@ import '@osrd-project/ui-core/dist/theme.css';
10
11
import '@osrd-project/ui-manchette/dist/theme.css' ;
11
12
import '@osrd-project/ui-manchette-with-spacetimechart/dist/theme.css' ;
12
13
14
+ import Menu , { type MenuItem } from './Menu' ;
15
+ import useElementInView from './useElementInView' ;
13
16
import { SAMPLE_WAYPOINTS , SAMPLE_PATHS_DATA } from '../assets/sampleData' ;
14
17
import useManchettesWithSpaceTimeChart from '../hooks/useManchetteWithSpaceTimeChart' ;
15
18
@@ -18,6 +21,7 @@ type ManchetteWithSpaceTimeWrapperProps = {
18
21
projectPathTrainResult : ProjectPathTrainResult [ ] ;
19
22
selectedTrain : number ;
20
23
} ;
24
+
21
25
const DEFAULT_HEIGHT = 561 ;
22
26
23
27
const ManchetteWithSpaceTimeWrapper = ( {
@@ -26,6 +30,45 @@ const ManchetteWithSpaceTimeWrapper = ({
26
30
selectedTrain,
27
31
} : ManchetteWithSpaceTimeWrapperProps ) => {
28
32
const manchetteWithSpaceTimeChartRef = useRef < HTMLDivElement > ( null ) ;
33
+
34
+ const [ activeWaypointIndex , setActiveWaypointPointIndex ] = useState < number > ( ) ;
35
+ const [ observerData , setObserverData ] = useState < {
36
+ waypointRef : React . RefObject < HTMLDivElement > ;
37
+ waypointsContainerRef : React . RefObject < HTMLDivElement > ;
38
+ } > ( ) ;
39
+
40
+ const isElementInView = useElementInView (
41
+ observerData ?. waypointRef ,
42
+ observerData ?. waypointsContainerRef
43
+ ) ;
44
+
45
+ const menuItems : MenuItem [ ] = [
46
+ {
47
+ title : 'Action 1' ,
48
+ icon : < EyeClosed /> ,
49
+ onClick : ( e : React . MouseEvent ) => {
50
+ e . stopPropagation ( ) ;
51
+ setActiveWaypointPointIndex ( undefined ) ;
52
+ } ,
53
+ } ,
54
+ {
55
+ title : 'Action 2' ,
56
+ icon : < Telescope /> ,
57
+ onClick : ( e : React . MouseEvent ) => {
58
+ e . stopPropagation ( ) ;
59
+ setActiveWaypointPointIndex ( undefined ) ;
60
+ } ,
61
+ } ,
62
+ ] ;
63
+
64
+ const handleWaypointClick = (
65
+ waypointIndex : number ,
66
+ waypointRef : React . RefObject < HTMLDivElement > ,
67
+ waypointsContainerRef : React . RefObject < HTMLDivElement >
68
+ ) => {
69
+ setActiveWaypointPointIndex ( waypointIndex ) ;
70
+ setObserverData ( { waypointRef, waypointsContainerRef } ) ;
71
+ } ;
29
72
const { manchetteProps, spaceTimeChartProps, handleScroll } = useManchettesWithSpaceTimeChart (
30
73
waypoints ,
31
74
projectPathTrainResult ,
@@ -45,7 +88,18 @@ const ManchetteWithSpaceTimeWrapper = ({
45
88
style = { { height : `${ DEFAULT_HEIGHT } px` } }
46
89
onScroll = { handleScroll }
47
90
>
48
- < Manchette { ...manchetteProps } />
91
+ < Manchette
92
+ { ...manchetteProps }
93
+ waypoints = { manchetteProps . waypoints . map ( ( op ) => ( {
94
+ ...op ,
95
+ onClick : handleWaypointClick ,
96
+ } ) ) }
97
+ waypointMenuData = { {
98
+ activeWaypointIndex,
99
+ menu : < Menu items = { menuItems } /> ,
100
+ isWaypointInView : isElementInView ,
101
+ } }
102
+ />
49
103
< div
50
104
className = "space-time-chart-container w-full sticky"
51
105
style = { { bottom : 0 , left : 0 , top : 2 , height : `${ DEFAULT_HEIGHT - 6 } px` } }
0 commit comments