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: use Duration in StdcmPathStep tolerances #10914

Merged
merged 2 commits into from
Feb 25, 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
Expand Up @@ -9,6 +9,7 @@ import { getSearchDatetimeWindow } from 'reducers/osrdconf/stdcmConf/selectors';
import type { StdcmPathStep } from 'reducers/osrdconf/types';
import { useAppDispatch } from 'store';
import { formatDateString } from 'utils/date';
import { Duration } from 'utils/duration';
import { createStringSelectOptions } from 'utils/uiCoreHelpers';

import type { ArrivalTimeTypes, ScheduleConstraint } from '../../types';
Expand Down Expand Up @@ -41,8 +42,8 @@ const StdcmOpSchedule = ({ disabled, pathStep, opId, isOrigin = false }: StdcmOp

const tolerances = useMemo(
() => ({
minusTolerance: pathStep.tolerances.before,
plusTolerance: pathStep.tolerances.after,
minusTolerance: pathStep.tolerances.before.total('second'),
plusTolerance: pathStep.tolerances.after.total('second'),
}),
[pathStep.tolerances]
);
Expand Down Expand Up @@ -148,7 +149,12 @@ const StdcmOpSchedule = ({ disabled, pathStep, opId, isOrigin = false }: StdcmOp
dispatch(
updateStdcmPathStep({
id: pathStep.id,
updates: { tolerances: { before: minusTolerance, after: plusTolerance } },
updates: {
tolerances: {
before: new Duration({ seconds: minusTolerance }),
after: new Duration({ seconds: plusTolerance }),
},
},
})
);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { dateToHHMMSS, formatDateToString, formatDay } from 'utils/date';
import { Duration } from 'utils/duration';
import { msToKmh } from 'utils/physics';
import { capitalizeFirstLetter } from 'utils/strings';
import { secToMin } from 'utils/timeManipulation';

import styles from './SimulationReportStyleSheet';
import type { SimulationReportSheetProps } from '../../types';
Expand Down Expand Up @@ -203,12 +202,12 @@ const SimulationReportSheet = ({
<View style={styles.convoyAndRoute.tolerancesWidth}>
<Text style={styles.convoyAndRoute.tolerancesText}>
{step.tolerances?.before
? `+${secToMin(step.tolerances?.before)}`
? `+${step.tolerances.before.total('minute')}`
: ''}
</Text>
<Text style={styles.convoyAndRoute.tolerancesText}>
{step.tolerances?.after
? `-${secToMin(step.tolerances?.after)}`
? `-${step.tolerances.after.total('minute')}`
: ''}
</Text>
</View>
Expand Down Expand Up @@ -237,10 +236,10 @@ const SimulationReportSheet = ({
step.arrivalType === 'preciseTime' && (
<View style={styles.convoyAndRoute.tolerancesWidth}>
<Text style={styles.convoyAndRoute.tolerancesText}>
{`+${secToMin(step.tolerances.before)}`}
{`+${step.tolerances.before.total('minute')}`}
</Text>
<Text style={styles.convoyAndRoute.tolerancesText}>
{`-${secToMin(step.tolerances.after)}`}
{`-${step.tolerances.after.total('minute')}`}
</Text>
</View>
)}
Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/stdcm/utils/formatStdcmConf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ export const checkStdcmConf = (
if (arrivalType === 'preciseTime' && arrival) {
timingData = {
arrival_time: arrival.toISOString(),
arrival_time_tolerance_before: sec2ms(tolerances?.before ?? 0),
arrival_time_tolerance_after: sec2ms(tolerances?.after ?? 0),
arrival_time_tolerance_before: tolerances.before.ms,
arrival_time_tolerance_after: tolerances.after.ms,
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion front/src/reducers/osrdconf/stdcmConf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { defaultCommonConf, buildCommonConfReducers } from 'reducers/osrdconf/os
import type { OsrdStdcmConfState, StdcmPathStep } from 'reducers/osrdconf/types';
import { addElementAtIndex, replaceElementAtIndex } from 'utils/array';
import { isArrivalDateInSearchTimeWindow } from 'utils/date';
import { Duration } from 'utils/duration';
import type { ArrayElement, PickAndNonNullableFields } from 'utils/types';

const DEFAULT_TOLERANCE = 1800; // 30min
const DEFAULT_TOLERANCE = new Duration({ minutes: 30 });

export const stdcmConfInitialState: OsrdStdcmConfState = {
...defaultCommonConf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from 'reducers/osrdconf/stdcmConf';
import type { OsrdStdcmConfState, StandardAllowance, StdcmPathStep } from 'reducers/osrdconf/types';
import { createStoreWithoutMiddleware } from 'store';
import { Duration } from 'utils/duration';

import commonConfBuilder from '../osrdConfCommon/__tests__/commonConfBuilder';
import testCommonConfReducers from '../osrdConfCommon/__tests__/utils';
Expand Down Expand Up @@ -180,8 +181,8 @@ describe('stdcmConfReducers', () => {
arrivalType: ArrivalTimeTypes.ASAP,
arrival: new Date('2024-08-12T15:45:00.000+02:00'),
tolerances: {
before: 60,
after: 60,
before: new Duration({ seconds: 60 }),
after: new Duration({ seconds: 60 }),
},
};

Expand Down Expand Up @@ -210,8 +211,8 @@ describe('stdcmConfReducers', () => {
arrivalType: ArrivalTimeTypes.ASAP,
arrival: new Date('2024-08-12T15:45:00.000+02:00'),
tolerances: {
before: 60,
after: 60,
before: new Duration({ seconds: 60 }),
after: new Duration({ seconds: 60 }),
},
};

Expand Down
2 changes: 1 addition & 1 deletion front/src/reducers/osrdconf/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export type StdcmPathStep = {
arrivalType: ArrivalTimeTypes;
// TODO: make arrival non nullable (/!\ store migration)
arrival?: Date;
tolerances: { before: number; after: number };
tolerances: { before: Duration; after: Duration };
}
);

Expand Down
Loading