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

Fixed the "Is blank"/"Is not blank" filters for the tags field type #3637

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

Conversation

jskupsik
Copy link
Contributor

@jskupsik jskupsik commented Apr 22, 2024

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.

@jskupsik
Copy link
Contributor Author

jskupsik commented Apr 22, 2024

Client has complained that the "Is blank"/"Is not blank" filter options present in the custom filter on the grid column filter do not work as an "is empty"/"is non-empty" when set on a tag/array object. I have fixed this by making filter op/values of "= null" and "!= null" also succeed for the cases of "empty array" and "non-empty array".

@jskupsik
Copy link
Contributor Author

  • Fixed bug where opening the grid filter for a tags column would cause error + clearing of that field.
  • Fixed bug where selecting 'is (not) blank' for a tag would introduce an erroneous selectable value '[blank]' in the Value filter and the Custom filter's 'Includes'/'Excludes', which would result in a bogus 'includes undefined'.
  • Fixed bug where switching between the Value and Custom tab did not initialize the filter value.

@jskupsik
Copy link
Contributor Author

})
// Filter out the null tag value as it isn't a valid value to display in value lists.
// It is set by 'is blank'/'is not blank' filters.
.filter(it => isEqual(it, [null]))
Copy link
Member

Choose a reason for hiding this comment

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

seems safe enough, independent of whether we continue to put null in as filter values.

@@ -119,6 +119,6 @@ const switcherButton = hoistCmp.factory<ColumnHeaderFilterModel>(({model, id, ti
text: title,
active: activeTabId === id,
outlined: true,
onClick: () => tabContainerModel.activateTab(id)
onClick: () => model.activateTab(id)
Copy link
Member

Choose a reason for hiding this comment

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

tabContainerModel reference no longer needed on line 114

@@ -128,14 +130,14 @@ export class FieldFilter extends Filter {
switch (op) {
Copy link
Member

Choose a reason for hiding this comment

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

would rValue and fValue be more helpful here? Very hard to keep track of which is which.

Copy link
Member

Choose a reason for hiding this comment

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

Great suggestion! Might I suggest we are even more explicit and call them recordVal and filterVal (i.e. more characters for the source than the word 'value')

return columnFilters.some(it => !['=', '!=', 'includes'].includes(it.op));
return columnFilters.some(
it =>
!['=', '!=', 'includes'].includes(it.op) ||
Copy link
Member

@lbwexler lbwexler Jul 6, 2024

Choose a reason for hiding this comment

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

this code (line 75 and 77) would be easier to grok if we expanded out to equals checks, and did not try to use the javascript 'includes' function . We are already dealing with an 'includes' filter and it is confusing!

@@ -82,7 +82,7 @@ export class CustomRowModel extends HoistModel {
makeObservable(this);

let newOp = op as OperatorOptionValue;
if (isNil(value)) {
if (isNil(value) || (isArray(value) && isEmpty(value))) {
Copy link
Member

Choose a reason for hiding this comment

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

might add a util isEmptyArray() -- we do this check 4 times in this PR -- might be others in hoist

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.

Thanks for this Jakub - looks and works great! Thanks also for setting up the Toolbox branch, made it very easy to reproduce the issues against develop before testing your fixes in this branch.

@@ -128,14 +130,14 @@ export class FieldFilter extends Filter {
switch (op) {
Copy link
Member

Choose a reason for hiding this comment

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

Great suggestion! Might I suggest we are even more explicit and call them recordVal and filterVal (i.e. more characters for the source than the word 'value')

return filterModel.toDisplayValue(value);
});
// The parseVal of tag will castArray the value a second time, so make sure to flatten at the end.
const newValues = flatten(
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing, but I think this would be more readable if we flatten() on line 96 as we push to filterValues

@TomTirapani
Copy link
Member

I noticed a minor issue when playing around with this - here's how to reproduce:

  1. Set a filter using the values tab (e.g. tag1 & tag2)
  2. Switch to the custom filter tab and replace the "includes" filter with an "is blank" / "is not blank" filter
  3. Switch back to the values tab and it will say "Custom filter active". If you click Clear the custom filter will be removed, but tag1 and tag2 will still be selected despite there being no filter.

I think the fix is probably as simple as syncing the values tab to the filter after clicking the central clear button.

Screenshot 2024-07-08 at 13 14 27

@amcclain
Copy link
Member

@jskupsik - wanted to ensure that you saw the comments above from earlier in the summer. It would be good to catch this up and have another look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants