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

2808: Add a filter by date option to events #2898

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

bahaaTuffaha
Copy link
Contributor

Short description

Filtering events by date

Proposed changes

For web:

  • Created a component called CustomDatePicker and used Input type='date' as date picker.

For native:

  • Created a component called CustomDatePicker used react-native TextInput and IconButton to show calendar modal.
  • Another component I added is for Calender Range picker called CalendarRangeModal I used react-native-calendars library and tried to mimic the styling like the design in figma.

Shared:

  • Created a hook called useDateFilter that accepts events then will validate and returns filteredEvents.

Side effects

None.

Resolved issues

Fixes: #2808


Copy link
Member

@steffenkleinle steffenkleinle left a comment

Choose a reason for hiding this comment

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

Hey, thank you for your PR, looks pretty nice already! Nice work 🎉

I just reviewed and tested native so far and everything works and looks as expected. I will review web once the comments have been addressed (I think the PR is quite huge, perhaps it would be better to merge it one by one and split up the PR, if possible).

I have a few remarks regarding coding style and complexity. If you feel like I misunderstood something or your solution makes more sense, please tell.

General changes that would be a good addition:

  • Use DateTime to avoid manual parsing and formatting as well as validating
  • Clicking next to the date picker could/should close it for better UX
  • If you delete a slash in the date picker, you can't readd it (since the keyboard only shows numbers). A better choice would perhaps be to implement fields for day, month, and year separately, so you can only edit either one at a time. Not sure if this is an optimal solution though, so if you have any other ideas let me know.

Keep in mind that I did not mention every occurrence of things that could be improved, please apply the suggestions to other parts in the code, too.

web/tsconfig.json Outdated Show resolved Hide resolved
assets/icons/calendar-events.svg Outdated Show resolved Hide resolved
assets/icons/expand.svg Outdated Show resolved Hide resolved
assets/icons/shrink.svg Outdated Show resolved Hide resolved
native/src/components/CalendarRangeModal.tsx Outdated Show resolved Hide resolved
translations/translations.json Outdated Show resolved Hide resolved
native/src/utils/calendarRangeUtils.ts Outdated Show resolved Hide resolved
native/src/utils/calendarRangeUtils.ts Outdated Show resolved Hide resolved
shared/hooks/useDateFilter.ts Outdated Show resolved Hide resolved
native/src/components/CalendarRangeModal.tsx Outdated Show resolved Hide resolved
native/src/components/CalendarRangeModal.tsx Outdated Show resolved Hide resolved
native/src/components/CalendarRangeModal.tsx Outdated Show resolved Hide resolved
native/src/components/CalendarRangeModal.tsx Outdated Show resolved Hide resolved
native/src/components/CalendarRangeModal.tsx Outdated Show resolved Hide resolved
shared/hooks/useDateFilter.ts Outdated Show resolved Hide resolved
shared/hooks/useDateFilter.ts Outdated Show resolved Hide resolved
translations/translations.json Show resolved Hide resolved
web/src/components/FilterToggle.tsx Show resolved Hide resolved
web/src/components/FilterToggle.tsx Outdated Show resolved Hide resolved
native/src/components/DatePicker.tsx Outdated Show resolved Hide resolved
native/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
native/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
web/src/components/DatePicker.tsx Outdated Show resolved Hide resolved
web/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
web/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
web/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
@steffenkleinle
Copy link
Member

steffenkleinle commented Sep 12, 2024

Some thoughts on the behavior:

  • My personal opinion is that if I never selected a time period, no filtering should be done and all events should be shown. Only if I manually set a start and end date, I want the events to be filtered.
  • Usually, confirming actions, i.e. ok in this case, are placed on the right side while `cancel´ should be placed on the left side of the screen (at least for LTR languages): https://m2.material.io/components/dialogs#actions. This is also the case in the designs.
  • If an invalid date range is selected with the date picker (i.e. no start date, no end date, end date before start date) it should not be possible to press ok (as nothing will happen anyway and the user will be confused about that). Instead the button should be disabled, greyed out.
  • If a date is selected that is before the current fromDate (and if set, the toDate), it should be set as new fromDate and toDate should be cleared. Currently, if only a fromDate is selected, the following happens (see screenshot)

One more general question:
Is there any reason you chose the names fromDate and toDate over e.g. startDate and endDate?

@steffenkleinle
Copy link
Member

Sadly I just realized we have another problem. A lot of our events are recurring, i.e. happening multiple times, for example every week. Our filtering should reflect that and include events that have recurrences in the selected time period. This might not be that easy, so perhaps we should do that in a separate PR. Has to be done before this is good to go though sadly :/

@bahaaTuffaha
Copy link
Contributor Author

Sadly I just realized we have another problem. A lot of our events are recurring, i.e. happening multiple times, for example every week. Our filtering should reflect that and include events that have recurrences in the selected time period. This might not be that easy, so perhaps we should do that in a separate PR. Has to be done before this is good to go though sadly :/

I think it can be done by modifying the filter maybe using rrule.between() event.date has recurrenceRule type RRuleType | null

@bahaaTuffaha bahaaTuffaha marked this pull request as ready for review September 13, 2024 11:11
Comment on lines +22 to +23
justify-content: ${props => (props.theme.contentDirection === 'rtl' ? 'flex-start' : 'flex-end')};
flex-direction: ${props => (props.theme.contentDirection === 'rtl' ? 'row-reverse' : 'row')};
Copy link
Member

Choose a reason for hiding this comment

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

Do we need both to be LTR/RTL dependent?

web/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
native/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
web/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
web/src/components/DatePicker.tsx Outdated Show resolved Hide resolved
@@ -76,7 +76,12 @@ const DatePicker = ({ title, date, setDate, error }: DatePickerProps): ReactElem
return (
<DateContainer>
<StyledTitle>{title}</StyledTitle>
<StyledInput alt='Date-input' type='date' value={date?.toFormat(INPUT_DATE_FORMAT)} onChange={handleDateChange} />
<StyledInput
placeholder='Date-input'
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, as this is user readable sometimes, I think this should for example be:

Suggested change
placeholder='Date-input'
placeholder={DateTime.now().toLocaleString()}

You should be able to assert on this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a reason for this: I used in the test getByPlaceholderText() I think this better than alt='Date-input' or getByTestId()

shared/hooks/useDateFilter.ts Outdated Show resolved Hide resolved
native/src/components/EventsDateFilter.tsx Outdated Show resolved Hide resolved
Copy link

codeclimate bot commented Sep 19, 2024

Code Climate has analyzed commit 52db677 and detected 4 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 4

The test coverage on the diff in this pull request is 57.8% (50% is the threshold).

This pull request will bring the total coverage in the repository to 73.8%.

View more on Code Climate.

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.

Add a filter by date option to events
2 participants