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

Improve filtering dates for specific operators #3362

Open
wants to merge 22 commits into
base: develop
Choose a base branch
from

Conversation

saba-mo
Copy link
Contributor

@saba-mo saba-mo commented May 12, 2023

Resolves #3338

Hoist P/R Checklist

Pull request authors: Review and check off the below. Items that do not apply can also be
checked off to indicate they have been considered. If unclear if a step is relevant, please leave
unchecked and note in comments.

  • Caught up with develop branch as of last change.
  • Added CHANGELOG entry, or determined not required.
  • Reviewed for breaking changes, added breaking-change label + CHANGELOG if so.
  • Updated doc comments / prop-types, or determined not required.
  • Reviewed and tested on Mobile, or determined not required.
  • Created Toolbox branch / PR, or determined not required.

If your change is still a WIP, please use the "Create draft pull request" option in the split
button below to indicate it is not ready yet for a final review.

Pull request reviewers: when merging this P/R, please consider using a squash commit to
collapse multiple intermediate commits into a single commit representing the overall feature
change. This helps keep the commit log clean and easy to scan across releases. PRs containing a
single commit should be rebased when possible.

@saba-mo
Copy link
Contributor Author

saba-mo commented May 12, 2023

Hi Tom, this PR is far from complete but I wanted you to have something to look at. The issue I'm still facing is that the converted values in the FilterChooserFieldSpec are not the values used for comparison when filtering. I am checking FieldFilter's getTestFn to log the actual filter value and record value being compared.

I think the getTestFn could be the place to implement this detection/conversion, and it would address both filterChooser and gridFilter. However, line 110 of FieldFilter sets the filter's fieldType based on the store's fieldType for that field, not taking into account what is set in the FieldSpec by the developer. I think if we could detect the correct fieldSpec, we could handle the implementation in FieldFilter by converting the value on line 175, but I'm not sure how big of a change it is/if we'd want to add fieldType when constructing a FieldFilter.

Another issue I anticipate, though am hopefully wrong, is that for GridFilter, in order to provide a fieldType that differs from the column's fieldType, the dev would need to specify the fieldSpec for all filterable columns by providing a filterModel config and no longer be able to simply set filterModel: true on the gridModel. Maybe an argument for making this the default behavior for date filtering.

@saba-mo saba-mo requested a review from TomTirapani May 12, 2023 01:04
Comment on lines 78 to 80
this.enableValues =
!this.isMismatchedDateFieldType &&
(this.hasExplicitValues || (enableValues ?? this.isEnumerableByDefault));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we said we don't want to enable the Values tab in this situation, right? It could be the dev's responsibility to set enableValues to false on the fieldSpec, but I think the default behavior of not showing it for dates makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

It would be great to enableValues if we could find a clean way to restrict the values to the unique local dates in the dataset, rather than the full date timestamp. If this proves too complex however perhaps its not worth it.

@@ -165,6 +189,7 @@ export abstract class BaseFilterFieldSpec extends HoistBase {
private getDefaultOperators(): FieldFilterOperator[] {
if (this.isBoolFieldType) return ['='];
if (this.isCollectionType) return ['includes', 'excludes'];
if (this.isMismatchedDateFieldType) return ['>', '>=', '<', '<='];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ensures the FilterChooser and GridFilter will offer the same operators for this field, which is not currently the case in the ActivityTracking example - only the GridFilter offers equals/does not equal.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be using the ActivityTracking tab as gospel for the operators we want to support - it would be better if we could support the full range of operators normally available for localDates.

That said, to support e.g. date = 2023-05-31, we need to produce a compound "between" filter like date >= 2023-05-31 00:00:00 AND date < 2023-06-01 00:00:00. Honestly not sure its worth the complexity :|

Comment on lines 85 to 87
valueType: fieldSpec.isMismatchedDateFieldType
? 'date'
: (fieldSpec.fieldType as 'localDate' | 'date')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that if you picked a date and then closed and reopened the popover, the dateInput wouldn't render the value, due to the difference in fieldTypes.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense - we need to input to be able to read dates since that is what the filter is actually using 👍

Comment on lines 73 to 78
fieldType =
fieldType === 'tags'
? 'string'
: fieldSpec.isMismatchedDateFieldType
? 'date'
: fieldType;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use localDate as the fieldType, we end up passing a date to the localDate case in Field's parseFieldValue function and would then need to use LocalDate.from(val) instead of LocalDate.get(val).

@saba-mo
Copy link
Contributor Author

saba-mo commented May 19, 2023

@TomTirapani FilterChooser and GridFilter now provide the same behavior as long as the developer indicates 'localDate' as the fieldSpec's fieldType. If we move forward with this approach, I wonder how we can make it more obvious that it's necessary, since I imagine it's a rather common use case. I believe this approach also still allows for true datetime comparisons.

@saba-mo saba-mo marked this pull request as ready for review May 19, 2023 23:14
@saba-mo saba-mo changed the title Handle filtering dates as localDates Improve filtering dates for specific operators May 19, 2023
Copy link
Member

@TomTirapani TomTirapani left a comment

Choose a reason for hiding this comment

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

This looks and works great.

It's a shame we can't support the full "local date experience"; namely, the Values tab and = and != operators. We'll need to assess the added complexity of supporting them and see if its worth it for this convenience feature - I hope we can find a way to support the former without too much work, but I suspect the latter is just not worth the complexity of producing compound filters.

@@ -165,6 +189,7 @@ export abstract class BaseFilterFieldSpec extends HoistBase {
private getDefaultOperators(): FieldFilterOperator[] {
if (this.isBoolFieldType) return ['='];
if (this.isCollectionType) return ['includes', 'excludes'];
if (this.isMismatchedDateFieldType) return ['>', '>=', '<', '<='];
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should be using the ActivityTracking tab as gospel for the operators we want to support - it would be better if we could support the full range of operators normally available for localDates.

That said, to support e.g. date = 2023-05-31, we need to produce a compound "between" filter like date >= 2023-05-31 00:00:00 AND date < 2023-06-01 00:00:00. Honestly not sure its worth the complexity :|

Comment on lines 85 to 87
valueType: fieldSpec.isMismatchedDateFieldType
? 'date'
: (fieldSpec.fieldType as 'localDate' | 'date')
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense - we need to input to be able to read dates since that is what the filter is actually using 👍

Comment on lines 78 to 80
this.enableValues =
!this.isMismatchedDateFieldType &&
(this.hasExplicitValues || (enableValues ?? this.isEnumerableByDefault));
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to enableValues if we could find a clean way to restrict the values to the unique local dates in the dataset, rather than the full date timestamp. If this proves too complex however perhaps its not worth it.

@saba-mo
Copy link
Contributor Author

saba-mo commented Jun 2, 2023

Regarding enabling the Values tab, I'm still investigating how to compare the correct values, but it looks like in order to get just the unique local dates to appear in the tab, we could check filterDateAsLocalDate in the ValuesTabModel's values getter and return the converted values there. We'd have to check it again in the value column renderer and override the date column's renderer which likely includes a timestamp (as is the case of the activity tracking grid). I can't think of a specific example right now, but it could be problematic to not allow the developer to provide a custom renderer.

@saba-mo
Copy link
Contributor Author

saba-mo commented Jun 13, 2023

See #3389 for details on why we are not pursuing enabling the Values tab and = and != operators.

@TomTirapani TomTirapani self-requested a review June 20, 2023 17:12
@lbwexler lbwexler self-requested a review June 26, 2023 21:37
@lbwexler lbwexler requested a review from amcclain June 26, 2023 21:39
@lbwexler
Copy link
Member

@amcclain wanted to take a look at this as well -- adding as a reviewer

@lbwexler
Copy link
Member

lbwexler commented Jul 7, 2023

@amcclain -- do you want to take a look at this? Would love to include this one in the current release if possible

@amcclain
Copy link
Member

amcclain commented Jul 7, 2023

@lbwexler yes, will do - caught it up with develop, will look further this morning / early afternoon.

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.

FilterChooser and GridFilter should modify date values for certain filter operators by default
4 participants