From 4f2b1e38dd1e653f8a6c9fb5ad5c5fc1e10443a4 Mon Sep 17 00:00:00 2001 From: Mathieu Richard Date: Wed, 31 Jul 2024 16:12:55 +0200 Subject: [PATCH] ui-manchette: highlight selected train --- ui-manchette/src/components/Manchette.tsx | 9 +++++++-- ui-manchette/src/hooks/usePaths.ts | 12 ++++++------ ui-manchette/src/stories/Manchette.stories.ts | 7 +++++++ ui-manchette/src/stories/assets/sampleData.ts | 6 ++++++ ui-manchette/src/types.ts | 4 ++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/ui-manchette/src/components/Manchette.tsx b/ui-manchette/src/components/Manchette.tsx index c25c2e130..da6bbdcdb 100644 --- a/ui-manchette/src/components/Manchette.tsx +++ b/ui-manchette/src/components/Manchette.tsx @@ -23,6 +23,7 @@ import { useIsOverflow } from '../hooks/useIsOverFlow'; type ManchetteProps = { operationalPoints: OperationalPointType[]; projectPathTrainResult: ProjectPathTrainResult[]; + selectedProjection?: number; }; import usePaths from '../hooks/usePaths'; import type { @@ -32,7 +33,11 @@ import type { } from '../types'; import { getDiff } from '../utils/vector'; -const Manchette: FC = ({ operationalPoints, projectPathTrainResult }) => { +const Manchette: FC = ({ + operationalPoints, + projectPathTrainResult, + selectedProjection, +}) => { const manchette = useRef(null); const [state, setState] = useState<{ @@ -74,7 +79,7 @@ const Manchette: FC = ({ operationalPoints, projectPathTrainResu scales, } = state; - const paths = usePaths(projectPathTrainResult); + const paths = usePaths(projectPathTrainResult, selectedProjection); const zoomYIn = useCallback(() => { if (yZoom < MAX_ZOOM_Y) setState((prev) => ({ ...prev, yZoom: yZoom + ZOOM_Y_DELTA })); diff --git a/ui-manchette/src/hooks/usePaths.ts b/ui-manchette/src/hooks/usePaths.ts index 1cd830d44..f2a5b2944 100644 --- a/ui-manchette/src/hooks/usePaths.ts +++ b/ui-manchette/src/hooks/usePaths.ts @@ -8,18 +8,18 @@ const transformCurve = (curve: SpaceTimeCurves, departureTime: string) => position, })); -const usePaths = (projectPathTrainResult: ProjectPathTrainResult[]) => +const usePaths = (projectPathTrainResult: ProjectPathTrainResult[], selectedProjection?: number) => useMemo( () => - projectPathTrainResult.map((path, index) => ({ - id: path.departure_time, - label: `Train ${index + 1}`, - color: '#000000', + projectPathTrainResult.map((path) => ({ + id: `${path.id}`, + label: path.name, + color: selectedProjection && selectedProjection === path.id ? '#201EDE' : '#000000', points: path.space_time_curves.flatMap((curve) => transformCurve(curve, path.departure_time) ), })), - [projectPathTrainResult] + [projectPathTrainResult, selectedProjection] ); export default usePaths; diff --git a/ui-manchette/src/stories/Manchette.stories.ts b/ui-manchette/src/stories/Manchette.stories.ts index 2b27e75c5..efd1aec5d 100644 --- a/ui-manchette/src/stories/Manchette.stories.ts +++ b/ui-manchette/src/stories/Manchette.stories.ts @@ -23,6 +23,12 @@ const meta: Meta = { type: 'object', }, }, + selectedProjection: { + options: [undefined, ...SAMPLE_PATHS_DATA.map((path) => path.id)], + control: { + type: 'select', + }, + }, }, }; @@ -33,5 +39,6 @@ export const Default: Story = { args: { operationalPoints: OperationalPointListData, projectPathTrainResult: PathData, + selectedProjection: 3, }, }; diff --git a/ui-manchette/src/stories/assets/sampleData.ts b/ui-manchette/src/stories/assets/sampleData.ts index e118ad781..9d84bbfe3 100644 --- a/ui-manchette/src/stories/assets/sampleData.ts +++ b/ui-manchette/src/stories/assets/sampleData.ts @@ -186,6 +186,8 @@ export const SAMPLE_PATH_PROPERTIES_DATA: PathProperties = { export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [ { + id: 1, + name: 'Train 1', departure_time: '2024-06-26T13:57:56Z', rolling_stock_length: 26070, space_time_curves: [ @@ -623,6 +625,8 @@ export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [ ], }, { + id: 2, + name: 'Train 2', departure_time: '2024-06-26T13:42:56Z', rolling_stock_length: 26070, space_time_curves: [ @@ -1060,6 +1064,8 @@ export const SAMPLE_PATHS_DATA: ProjectPathTrainResult[] = [ ], }, { + id: 3, + name: 'Train 3', departure_time: '2024-06-26T14:12:56Z', rolling_stock_length: 26070, space_time_curves: [ diff --git a/ui-manchette/src/types.ts b/ui-manchette/src/types.ts index 4931c666c..ac8b726fe 100644 --- a/ui-manchette/src/types.ts +++ b/ui-manchette/src/types.ts @@ -89,6 +89,10 @@ export type StyledOperationalPointType = OperationalPointType & { }; export type ProjectPathTrainResult = { + /*Name of train */ + name: string; + /*Id of train */ + id: number; /** List of signal updates along the path */ signal_updates: { /** The labels of the new aspect */