Skip to content

Commit

Permalink
front: add track column to timestops table
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Khoudli <[email protected]>
  • Loading branch information
Synar committed Nov 27, 2024
1 parent ab6cdbb commit be2d4f1
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 14 deletions.
1 change: 1 addition & 0 deletions front/public/locales/en/timesStops.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"theoreticalMargin": "theoretical margin",
"theoreticalMarginPlaceholder": "% or min/100km",
"theoreticalMarginSeconds": "theoretical margin (s)",
"trackName": "track",
"waypoint": "Waypoint {{id}}"
}
1 change: 1 addition & 0 deletions front/public/locales/fr/timesStops.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
"theoreticalMargin": "marge théorique",
"theoreticalMarginPlaceholder": "% ou min/100km",
"theoreticalMarginSeconds": "marge théorique (s)",
"trackName": "voie",
"waypoint": "Via {{id}}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from 'common/api/osrdEditoastApi';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import {
formatSuggestedOperationalPoints,
formatSuggestedOperationalPointsWithTrackName,
matchPathStepAndOp,
upsertPathStepsInOPs,
} from 'modules/pathfinding/utils';
Expand Down Expand Up @@ -124,11 +124,14 @@ const useSetupItineraryForTrainUpdate = (
const stepsCoordinates = pathfindingResult.path_item_positions.map((position) =>
getPointCoordinates(geometry, pathfindingResult.length, position)
);
const suggestedOperationalPoints: SuggestedOP[] = formatSuggestedOperationalPoints(
operational_points,
geometry,
pathfindingResult.length
);
const suggestedOperationalPoints: SuggestedOP[] =
await formatSuggestedOperationalPointsWithTrackName(
operational_points,
geometry,
pathfindingResult.length,
infraId,
dispatch
);

const computedpathSteps = computeBasePathSteps(trainSchedule);
const updatedPathSteps: PathStep[] = updatePathStepsFromOperationalPoints(
Expand Down
15 changes: 9 additions & 6 deletions front/src/modules/pathfinding/hooks/usePathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import { initialState } from 'modules/pathfinding/consts';
import type { PathfindingAction, PathfindingState } from 'modules/pathfinding/types';
import {
formatSuggestedOperationalPoints,
formatSuggestedOperationalPointsWithTrackName,
getPathfindingQuery,
matchPathStepAndOp,
upsertPathStepsInOPs,
Expand Down Expand Up @@ -294,11 +294,14 @@ export const usePathfinding = (
await postPathProperties(pathPropertiesParams).unwrap();

if (electrifications && geometry && operational_points) {
const suggestedOperationalPoints: SuggestedOP[] = formatSuggestedOperationalPoints(
operational_points,
geometry,
pathResult.length
);
const suggestedOperationalPoints: SuggestedOP[] =
await formatSuggestedOperationalPointsWithTrackName(
operational_points,
geometry,
pathResult.length,
infraId,
dispatch
);

// We update existing pathsteps with coordinates, positionOnPath and kp corresponding to the new pathfinding result
const updatedPathSteps: (PathStep | null)[] = pathSteps.map((step, i) => {
Expand Down
52 changes: 51 additions & 1 deletion front/src/modules/pathfinding/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { compact } from 'lodash';
import { compact, uniq } from 'lodash';

import type { TrackSectionEntity } from 'applications/editor/tools/trackEdition/types';
import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import type {
GeoJsonLineString,
PathProperties,
PathfindingInput,
PostInfraByInfraIdPathfindingBlocksApiArg,
RollingStockWithLiveries,
TrackSection,
} from 'common/api/osrdEditoastApi';
import { getSupportedElectrification, isThermal } from 'modules/rollingStock/helpers/electric';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { PathStep } from 'reducers/osrdconf/types';
import type { AppDispatch } from 'store';
import { addElementAtIndex } from 'utils/array';
import { getPointCoordinates } from 'utils/geometry';

Expand All @@ -36,6 +40,52 @@ export const formatSuggestedOperationalPoints = (
coordinates: getPointCoordinates(geometry, pathLength, op.position),
}));

export const formatSuggestedOperationalPointsWithTrackName = async (
operationalPoints: NonNullable<Required<PathProperties['operational_points']>>,
geometry: GeoJsonLineString,
pathLength: number,
infraId: number,
dispatch: AppDispatch
): Promise<SuggestedOP[]> => {
// Extract track IDs to fetch track names
const trackIds = uniq(operationalPoints.map((op) => op.part.track));
const trackSections = await dispatch(
osrdEditoastApi.endpoints.postInfraByInfraIdObjectsAndObjectType.initiate({
infraId,
objectType: 'TrackSection',
body: trackIds,
})
).unwrap();

return operationalPoints.map((op) => {
const associatedTrackSection = trackSections.find(
(trackSection) => (trackSection.railjson as TrackSection).id === op.part.track
);

const trackName = associatedTrackSection
? (associatedTrackSection.railjson as TrackSectionEntity['properties']).extensions?.sncf
?.track_name
: null;

return {
opId: op.id,
name: op.extensions?.identifier?.name,
uic: op.extensions?.identifier?.uic,
ch: op.extensions?.sncf?.ch,
kp: op.part.extensions?.sncf?.kp,
chLongLabel: op.extensions?.sncf?.ch_long_label,
chShortLabel: op.extensions?.sncf?.ch_short_label,
ci: op.extensions?.sncf?.ci,
trigram: op.extensions?.sncf?.trigram,
offsetOnTrack: op.part.position,
track: op.part.track,
positionOnPath: op.position,
coordinates: getPointCoordinates(geometry, pathLength, op.position),
trackName: trackName || undefined,
};
});
};

export const matchPathStepAndOp = (
step: PathStep,
op: Pick<SuggestedOP, 'opId' | 'uic' | 'ch' | 'trigram' | 'track' | 'offsetOnTrack'>
Expand Down
13 changes: 12 additions & 1 deletion front/src/modules/timesStops/hooks/useTimeStopsColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const useTimeStopsColumns = <T extends TimeStopsRow>(
title: t('name'),
...(isOutputTable && {
component: ({ rowData }) => (
<span title={rowData.name} className="ml-1 text-nowrap overflow-hidden">
<span title={rowData.name} className="ml-2 text-nowrap overflow-hidden">
{rowData.name}
</span>
),
Expand All @@ -98,6 +98,17 @@ export const useTimeStopsColumns = <T extends TimeStopsRow>(
disabled: true,
...fixedWidth(45),
},
{
...keyColumn('trackName', createTextColumn()),
title: t('trackName'),
component: ({ rowData }) => (
<span title={rowData.trackName} className="ml-2 text-nowrap overflow-hidden">
{rowData.trackName}
</span>
),
disabled: true,
...fixedWidth(70),
},
{
...keyColumn('arrival', timeColumn(isOutputTable)),
title: t('arrivalTime'),
Expand Down
1 change: 1 addition & 0 deletions front/src/modules/timesStops/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type TimeStopsRow = {
opId: string;
name?: string;
ch?: string;
trackName?: string;
isWaypoint: boolean;

arrival?: TimeExtraDays; // value asked by user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type SuggestedOP = {
trigram?: string;
offsetOnTrack: number;
track: string;
trackName?: string;
/** Distance from the beginning of the path in mm */
positionOnPath: number;
coordinates?: Position;
Expand Down
1 change: 1 addition & 0 deletions front/tests/011-op-times-and-stops-tab.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ test.describe('Times and Stops Tab Verification', () => {
const expectedColumnNames = cleanWhitespaceInArray([
translations.name,
translations.ch,
translations.trackName,
translations.arrivalTime,
translations.stopTime,
translations.departureTime,
Expand Down

0 comments on commit be2d4f1

Please sign in to comment.