-
Notifications
You must be signed in to change notification settings - Fork 0
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
III-6257-Sort the days of the opening hours #924
Conversation
@@ -145,11 +145,15 @@ const CalendarOpeninghoursModal = ({ | |||
idToChange: string, | |||
) => { | |||
const checked = event.target.checked; | |||
const daysOrder = Object.values(DaysOfWeek); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot rely on the order of the values from an object.
It may work now, but it may not work at some point according to the js spec.
keys and values in an object don't maintain a certain order, because they use a hashmap datastructure behind the scenes.
Since the codebase only uses the values anyways, never specific days we can refactor the DaysOfWeek to this:
const DaysOfWeek = [
'monday',
'tuesday',
'wednesday',
'thursday',
'friday',
'saturday',
'sunday',
] as const;
type DayOfWeek = (typeof DaysOfWeek)[number];
Arrays do maintain their order of elements
openingHour.dayOfWeek.sort((a, b) => { | ||
return daysOrder.indexOf(a) - daysOrder.indexOf(b); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the change above this becomes
openingHour.dayOfWeek.sort((a, b) => { | |
return daysOrder.indexOf(a) - daysOrder.indexOf(b); | |
}); | |
openingHour.dayOfWeek.sort((a, b) => { | |
return DaysOfWeek.indexOf(a) - DaysOfWeek.indexOf(b); | |
}); |
Added
Ticket: https://jira.uitdatabank.be/browse/III-6257