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: change margin logic #7980

Merged
merged 1 commit into from
Jul 10, 2024
Merged
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,21 +1,31 @@
import type { Margin } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { PathStep } from 'reducers/osrdconf/types';

const formatMargin = (pathSteps: PathStep[]): Margin => {
const margins: Margin = {
boundaries: [],
values: [],
};
const formatMargin = (pathSteps: PathStep[]): Margin | undefined => {
const boundaries: string[] = [];
const values: string[] = [];

pathSteps.forEach((step, index) => {
if (index === 0) {
margins.values.push(step.theoreticalMargin || 'none');
} else if (step.theoreticalMargin !== pathSteps[index - 1].theoreticalMargin) {
margins.boundaries.push(step.id);
margins.values.push(step.theoreticalMargin || 'none');
values.push(step.theoreticalMargin || 'none');
} else if (index === pathSteps.length - 1) {
if (values.length === 1 && values[0] !== 'none') {
boundaries.push(step.id);
values.push('none');
}
}

// for the other steps, we add the margin if it's different from the previous one
else if (step.theoreticalMargin && step.theoreticalMargin !== values[values.length - 1]) {
boundaries.push(step.id);
values.push(step.theoreticalMargin);
}
});
return margins;

if (values.length === 1) {
return undefined;
}
return { boundaries, values };
};

export default formatMargin;
Loading