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

Add <DateFilter > component #2849

Merged
merged 5 commits into from
Aug 7, 2024
Merged

Add <DateFilter > component #2849

merged 5 commits into from
Aug 7, 2024

Conversation

balanza
Copy link
Member

@balanza balanza commented Aug 2, 2024

Description

Add component to filter some dates in the past. It can be configured with the options to show, although it has some defaults. Please take a look at the storybook for all the configurable options.

Every option is composed of a triple:

  • ID of the option
  • value function, to calculate the actual date at selection time
  • rendering function, to show a custom label for the option; this function is optional and falls back to the id.

As a shortcut, an option can be specified as just its ID if it's available amongst the pre-configured ones/

The exposed interface comes with some assumptions, I'll leave comments in this PR pointing to the relevant code parts.


The component has also been added as a configurable filter in <ComposedFilter />.

.sort((a, b) => b[1]().getTime() - a[1]().getTime());

const getSelectedOption = (options, value) => {
const selectedId = Array.isArray(value) ? value[0] : value;
Copy link
Member Author

Choose a reason for hiding this comment

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

decision Ideally, the option ID is enough to set the selected item. However, the value exposed on change is a couple [ID, date] and I thought it would be convenient to accept it as value as well otherwise it would require us to handle the difference in format when storing it in the local/global state.

if (
Array.isArray(option) &&
typeof option[1] === 'function' &&
option[1]() instanceof Date
Copy link
Member Author

Choose a reason for hiding this comment

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

decision Options come with a value function so that the actual reference date is calculated at selection time. That's simpler for the consumer as it already has a date, as expected from a date filter, which can just store the value and use it at its convenience.

That comes with a little drawback: if the date reflects a period (for example, 10 minutes ago), that value is never updated unless a new selection is made.

Another viable solution would be to return a number instead of a Date object; such a number can represent the milliseconds back from now. Being a relative value it does not have to update. However, the using component must handle the calculation itself.

Copy link
Member

Choose a reason for hiding this comment

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

I am fine with the decision/tradeoff choice made.

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

I don't see any major blocker. Eager to start using it in the activity log page 😄

A thought that came to my mind is about what gets send to the API call.
I believe the following format is what is going to be send and what the API accepts 2024-08-05T08:00:16.549046Z, @gagandeepb could you confirm, please?

question: should we be concerned about browser timezone vs server timezone? 🤔

};

export const WithCustomOptions = {
args: {
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: since no title has been provided, the rendered story shows Filter undefined

Copy link
Member

Choose a reason for hiding this comment

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

title still missing 🙈

assets/js/common/DateFilter/DateFilter.jsx Outdated Show resolved Hide resolved
assets/js/common/DateFilter/DateFilter.jsx Outdated Show resolved Hide resolved
if (
Array.isArray(option) &&
typeof option[1] === 'function' &&
option[1]() instanceof Date
Copy link
Member

Choose a reason for hiding this comment

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

I am fine with the decision/tradeoff choice made.

*
* @component
* @example
* // <DateFilter
Copy link
Member

Choose a reason for hiding this comment

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

question: what we currently do is selecting a moment in the past (1h ago, etc...) and we want it to be the starting point of a timeframe within which we want to filter some resource (activity log at the moment).

DateFilter, is quite generic and might lead to thinking it is about selecting a specific date (which somehow happens under the hood).
What about a more specific name for the actual use case? Something around timeframe/timespan?
(TimeSpan is also something in ActivityLogsSettingsModal, tho, which is not the same thing, I reckon)

Copy link
Member Author

Choose a reason for hiding this comment

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

might lead to thinking it is about selecting a specific date

It's exactly what happens. There are shortcuts, but also a date picker (which will be implemented in the next iteration)

Copy link
Member

Choose a reason for hiding this comment

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

Ok, feel free to keep current name 👍

Copy link
Contributor

@gagandeepb gagandeepb left a comment

Choose a reason for hiding this comment

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

If server assumes system/db time is UTC, the browser would/should do the same, I guess. All timestamps are assumed to be UTC, in ISO8601 format serialized as a string and expected in this format by the BE API. cc: @nelsonkopliku

@balanza
Copy link
Member Author

balanza commented Aug 6, 2024

question: should we be concerned about browser timezone vs server timezone?

@nelsonkopliku I think we shouldn't, the filter should refer to values as they come from the server. It will be up to the user to consider that he/she is looking at something generated into a server with its timezone.

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

At the end, what did you decide to do or not do with regards to the following 😅:

  • comment on prefill vs prefilled and the question about it defaulting to true
  • comment about a story showing Filter undefined because of a missing title

@balanza
Copy link
Member Author

balanza commented Aug 7, 2024

At the end, what did you decide to do or not do with regards to the following 😅:

  • comment on prefill vs prefilled and the question about it defaulting to true
  • comment about a story showing Filter undefined because of a missing title

Yes, I missed that. Done in f5b9d3d

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

LGTM, just the story needs to be adjusted.

};

export const WithCustomOptions = {
args: {
Copy link
Member

Choose a reason for hiding this comment

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

title still missing 🙈

@balanza balanza merged commit 2ebad62 into main Aug 7, 2024
27 checks passed
@balanza balanza deleted the ui-date-filter branch August 7, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants