-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: develop
Are you sure you want to change the base?
Conversation
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. |
data/filter/BaseFilterFieldSpec.ts
Outdated
this.enableValues = | ||
!this.isMismatchedDateFieldType && | ||
(this.hasExplicitValues || (enableValues ?? this.isEnumerableByDefault)); |
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.
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.
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.
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.
data/filter/BaseFilterFieldSpec.ts
Outdated
@@ -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 ['>', '>=', '<', '<=']; |
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.
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.
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.
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 :|
valueType: fieldSpec.isMismatchedDateFieldType | ||
? 'date' | ||
: (fieldSpec.fieldType as 'localDate' | 'date') |
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.
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.
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.
Makes sense - we need to input to be able to read dates
since that is what the filter is actually using 👍
cmp/filter/impl/Option.ts
Outdated
fieldType = | ||
fieldType === 'tags' | ||
? 'string' | ||
: fieldSpec.isMismatchedDateFieldType | ||
? 'date' | ||
: fieldType; |
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.
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).
@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. |
# Conflicts: # CHANGELOG.md
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.
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.
data/filter/BaseFilterFieldSpec.ts
Outdated
@@ -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 ['>', '>=', '<', '<=']; |
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.
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 :|
valueType: fieldSpec.isMismatchedDateFieldType | ||
? 'date' | ||
: (fieldSpec.fieldType as 'localDate' | 'date') |
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.
Makes sense - we need to input to be able to read dates
since that is what the filter is actually using 👍
data/filter/BaseFilterFieldSpec.ts
Outdated
this.enableValues = | ||
!this.isMismatchedDateFieldType && | ||
(this.hasExplicitValues || (enableValues ?? this.isEnumerableByDefault)); |
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.
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.
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. |
See #3389 for details on why we are not pursuing enabling the Values tab and = and != operators. |
@amcclain wanted to take a look at this as well -- adding as a reviewer |
@amcclain -- do you want to take a look at this? Would love to include this one in the current release if possible |
@lbwexler yes, will do - caught it up with develop, will look further this morning / early afternoon. |
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.
develop
branch as of last change.breaking-change
label + CHANGELOG if so.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.