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

III-6257-Sort the days of the opening hours #924

Merged
merged 5 commits into from
Oct 14, 2024
Merged

III-6257-Sort the days of the opening hours #924

merged 5 commits into from
Oct 14, 2024

Conversation

vhande
Copy link
Contributor

@vhande vhande commented Oct 11, 2024

Added

  • Sort the days of the opening hours

Ticket: https://jira.uitdatabank.be/browse/III-6257

@@ -145,11 +145,15 @@ const CalendarOpeninghoursModal = ({
idToChange: string,
) => {
const checked = event.target.checked;
const daysOrder = Object.values(DaysOfWeek);
Copy link
Contributor

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

Comment on lines 154 to 156
openingHour.dayOfWeek.sort((a, b) => {
return daysOrder.indexOf(a) - daysOrder.indexOf(b);
});
Copy link
Contributor

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

Suggested change
openingHour.dayOfWeek.sort((a, b) => {
return daysOrder.indexOf(a) - daysOrder.indexOf(b);
});
openingHour.dayOfWeek.sort((a, b) => {
return DaysOfWeek.indexOf(a) - DaysOfWeek.indexOf(b);
});

@vhande vhande merged commit 6b4a633 into main Oct 14, 2024
5 checks passed
@vhande vhande deleted the feature/III-6257 branch October 14, 2024 09:24
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.

2 participants