Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: remove PathStep casts #10167

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useEffect } from 'react';

import { type Position } from '@turf/helpers';
import { omit } from 'lodash';

import {
osrdEditoastApi,
type PathItemLocation,
type PostInfraByInfraIdPathPropertiesApiArg,
type PostInfraByInfraIdPathfindingBlocksApiArg,
type RollingStockWithLiveries,
Expand Down Expand Up @@ -145,9 +143,8 @@ const useSetupItineraryForTrainUpdate = (trainIdToEdit: number) => {
const params: PostInfraByInfraIdPathfindingBlocksApiArg = {
infraId,
pathfindingInput: {
path_items: trainSchedule.path.map((item) =>
omit(item, ['id', 'deleted'])
) as PathItemLocation[],
// eslint-disable-next-line @typescript-eslint/no-unused-vars
path_items: trainSchedule.path.map(({ id, deleted, ...item }) => item),
rolling_stock_is_thermal: isThermal(rollingStock.effort_curves.modes),
rolling_stock_loading_gauge: rollingStock.loading_gauge,
rolling_stock_supported_electrifications: getSupportedElectrification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ModalSuggestedVias = ({ suggestedVias, launchPathfinding }: ModalSuggested
const dispatch = useAppDispatch();
const vias = useSelector(getVias());
const destination = useSelector(getDestination);
const pathSteps = useSelector(getPathSteps) as PathStep[]; // this modal can't be open if we miss origin or destination;
const pathSteps = useSelector(getPathSteps);
const { t } = useTranslation('operationalStudies/manageTrainSchedule');

const isOriginOrDestination = useCallback(
Expand All @@ -37,7 +37,7 @@ const ModalSuggestedVias = ({ suggestedVias, launchPathfinding }: ModalSuggested
);

const removeViaFromPath = (op: SuggestedOP) => {
const newPathSteps = pathSteps.filter((step) => !matchPathStepAndOp(step, op));
const newPathSteps = pathSteps.filter((step) => !matchPathStepAndOp(step!, op));
launchPathfinding(newPathSteps);
};

Expand Down
16 changes: 4 additions & 12 deletions front/src/modules/trainschedule/helpers/computeBasePathStep.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { omit } from 'lodash';

import type { TrainScheduleResult } from 'common/api/osrdEditoastApi';
import type { PathStep } from 'reducers/osrdconf/types';
import { mmToM } from 'utils/physics';
Expand All @@ -24,7 +22,7 @@ const findCorrespondingMargin = (
const computeBasePathStep = (
trainSchedule: Pick<TrainScheduleResult, 'path' | 'schedule' | 'margins'>,
pathItemIndex: number
) => {
): PathStep => {
const step = trainSchedule.path[pathItemIndex];
const correspondingSchedule = trainSchedule.schedule?.find((schedule) => schedule.at === step.id);

Expand All @@ -35,12 +33,6 @@ const computeBasePathStep = (
reception_signal: receptionSignal,
} = correspondingSchedule || {};

const stepWithoutSecondaryCode = omit(step, ['secondary_code']);

if ('track' in stepWithoutSecondaryCode) {
stepWithoutSecondaryCode.offset = mmToM(stepWithoutSecondaryCode.offset!);
}

let name;
if ('trigram' in step) {
name = step.trigram + (step.secondary_code ? `/${step.secondary_code}` : '');
Expand All @@ -56,15 +48,15 @@ const computeBasePathStep = (
}

return {
...stepWithoutSecondaryCode,
secondary_code: 'secondary_code' in step ? step.secondary_code : undefined,
...step,
...('track' in step ? { offset: mmToM(step.offset) } : null),
name,
arrival, // ISODurationString
stopFor: stopFor ? ISO8601Duration2sec(stopFor).toString() : stopFor,
locked,
receptionSignal,
theoreticalMargin,
} as PathStep;
};
};

export default computeBasePathStep;
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export function builPowerRestrictionReducer<S extends OsrdConfState>(): PowerRes
(restriction) => restriction.from !== from.id && restriction.to !== to.id
);

const newPathSteps = [...state.pathSteps] as PathStep[];
const newPathSteps = [...state.pathSteps].map((step) => step!);
state.pathSteps = cleanPathSteps(newPathSteps, newPowerRestrictionRanges);
state.powerRestriction = newPowerRestrictionRanges;
},
Expand All @@ -146,7 +146,7 @@ export function builPowerRestrictionReducer<S extends OsrdConfState>(): PowerRes

// pathSteps should not be undefined or have null values
if (state.pathSteps && !state.pathSteps.some((pathStep) => !pathStep)) {
let newPathSteps = [...state.pathSteps] as PathStep[];
let newPathSteps = [...state.pathSteps].map((step) => step!);
let newPowerRestrictionRanges = state.powerRestriction.filter(
(restriction) =>
!isEqual(restriction, firstRestriction) || !isEqual(restriction, secondRestriction)
Expand Down Expand Up @@ -196,7 +196,7 @@ export function builPowerRestrictionReducer<S extends OsrdConfState>(): PowerRes

// pathSteps should not be undefined or have null values
if (state.pathSteps && !state.pathSteps.some((pathStep) => !pathStep)) {
let newPathSteps = [...state.pathSteps] as PathStep[];
let newPathSteps = [...state.pathSteps].map((step) => step!);
let newPowerRestrictionRanges = state.powerRestriction.filter(
(restriction) =>
!isEqual(restriction, firstRestriction) || !isEqual(restriction, secondRestriction)
Expand Down
Loading