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: stdcm: persist user-entered date and time in the interface #8942

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

SarahBellaha
Copy link
Contributor

@SarahBellaha SarahBellaha requested a review from a team as a code owner September 20, 2024 07:06
@codecov-commenter
Copy link

codecov-commenter commented Sep 20, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 26.02740% with 54 lines in your changes missing coverage. Please review.

Project coverage is 37.11%. Comparing base (68e0513) to head (6b9f2fc).
Report is 5 commits behind head on dev.

Files with missing lines Patch % Lines
...plications/stdcmV2/components/StdcmDestination.tsx 0.00% 22 Missing and 1 partial ⚠️
...rc/applications/stdcmV2/components/StdcmOrigin.tsx 0.00% 21 Missing and 1 partial ⚠️
...pplications/stdcmV2/components/StdcmOpSchedule.tsx 0.00% 6 Missing ⚠️
...ront/src/reducers/osrdconf/osrdConfCommon/index.ts 50.00% 0 Missing and 2 partials ⚠️
front/src/utils/date.ts 91.66% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #8942      +/-   ##
============================================
- Coverage     37.13%   37.11%   -0.03%     
  Complexity     2211     2211              
============================================
  Files          1260     1260              
  Lines        115076   115189     +113     
  Branches       3230     3234       +4     
============================================
+ Hits          42736    42752      +16     
- Misses        70407    70500      +93     
- Partials       1933     1937       +4     
Flag Coverage Δ
core 74.67% <ø> (ø)
editoast 72.56% <ø> (ø)
front 15.20% <26.02%> (-0.01%) ⬇️
gateway 2.20% <ø> (ø)
osrdyne 2.60% <ø> (ø)
railjson_generator 87.49% <ø> (ø)
tests 86.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 240 to 241
date: Date,
{ hours, minutes }: { hours: number; minutes: number }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really an issue, just a suggestion: we could create an explicit type instead of repeating those parameters

@@ -302,19 +302,21 @@ export function buildCommonConfReducers<S extends OsrdConfState>(): CommonConfRe
state.startTime = action.payload;
},
updateOrigin(state: Draft<S>, action: PayloadAction<ArrayElement<S['pathSteps']>>) {
const prevOriginArrivalType = state.pathSteps[0]?.arrivalType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const prevOriginArrivalType = state.pathSteps[0]?.arrivalType;
const prevOriginArrivalType = state.pathSteps.at(0)?.arrivalType;

}
: null;
state.pathSteps = updateOriginPathStep(state.pathSteps, newPoint, true);
},
updateDestination(state: Draft<S>, action: PayloadAction<ArrayElement<S['pathSteps']>>) {
const prevDestinationArrivalType = state.pathSteps[state.pathSteps.length - 1]?.arrivalType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const prevDestinationArrivalType = state.pathSteps[state.pathSteps.length - 1]?.arrivalType;
const prevDestinationArrivalType = state.pathSteps.at(- 1)?.arrivalType;

* @param {{ hours: number; minutes: number }} - An object containing the hours and the minutes of the arrival time.
* @returns {string} The ISO formatted arrival date string.
*/
export const generateISOArrival = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the function could be used in contexts other than just arrival dates, so I suggest renaming it to something more generic. What do you think?

Suggested change
export const generateISOArrival = (
export const generateISODateFromDateTime = (

Comment on lines 56 to 61
const updateOriginPoint = (pathStep: PathStep | null) => {
dispatch(updateOrigin(pathStep));
if (arrivalDateInput && arrivalTimeInput) {
const newOpArrival = generateISOArrival(arrivalDateInput, arrivalTimeInput);
dispatch(updateOriginArrival(newOpArrival));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid dispatching two actions when arrivalDate and arrivalTime are defined, what do you think about dispatching a single updateOrigin(pathStep) with the pathStep already having the new arrival time set?

The same logic can be applied for updateDestinationPoint

Suggested change
const updateOriginPoint = (pathStep: PathStep | null) => {
dispatch(updateOrigin(pathStep));
if (arrivalDateInput && arrivalTimeInput) {
const newOpArrival = generateISOArrival(arrivalDateInput, arrivalTimeInput);
dispatch(updateOriginArrival(newOpArrival));
}
const updateOriginPoint = (pathStep: PathStep | null) => {
if (!pathStep || !arrivalDateInput || !arrivalTimeInput) {
return dispatch(updateOrigin(pathStep));
}
dispatch(
updateOrigin({
...pathStep,
arrival: generateISOArrival(arrivalDateInput, arrivalTimeInput),
})
);
};

Comment on lines 27 to 33

const [arrivalDateInput, setArrivalDateInput] = useState<Date | undefined>(undefined);
const [arrivalTimeInput, setArrivalTimeInput] = useState<{ hours: number; minutes: number }>({
hours: 0,
minutes: 0,
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that these states are duplicated in StdcmDestination and StdcmOrigin, so we might want to move them up to the parent StdcmConfig. Then, we can pass the necessary data to StdcmDestination and StdcmOrigin.

To simplify things, I suggest unifying the variables. Instead of having arrivalDateInput and arrivalTimeInput, we could use a single variable called scheduleConstraint (you can suggest another name). This could have the following type:

type ScheduleConstraint = {
    date: Date;
    hour: number;
    minutes: number;
}

Then, StdcmConfig can manage this new state variable (scheduleConstraint) and pass it to StdcmDestination and StdcmOrigin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants