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

Issue 1930/smart search min matching tags #1948

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

Conversation

awarn
Copy link
Collaborator

@awarn awarn commented May 12, 2024

Description

Fixes two issues with SmartSearch form for matching tags when setting the number of tags to match "at least".

Note that the filter being specified does not seem to work correctly. Regardless of number of tags set to match against, it still seems to behave as the "any" variant of the filter.

Changes

  • The upper bound of the number is now set by the number of selectable tags, not the number of selected.
  • Allows the number input to be empty (so you can delete it using a keyboard) without the form resetting to the match "any" variant.

Related issues

Resolves #1930

Copy link
Contributor

@kaulfield23 kaulfield23 left a comment

Choose a reason for hiding this comment

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

Nice! Now I can give input using keyboard as well! 😄but I found something to be fixed in codes!

@@ -1,4 +1,4 @@
import { FormEvent } from 'react';
import { FormEvent, useState } from 'react';
import { Box, Chip, MenuItem } from '@mui/material';
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes the lint error. import { Box, Chip, MenuItem } from '@mui/material'; should be on line 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll resolve this, no problem! Don't know why my own linting hook did not catch it.

@@ -51,6 +51,10 @@ const PersonTags = ({
tags: [],
});

const [selected, setSelected] = useState<CONDITION_OPERATOR | 'min_matching'>(
filter.config.condition
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason why condition is 'any' when editing is that min_matching also has the condition 'any'. The key to differentiating between 'any' and 'at least' is the presence of min_matching. It would look like this:

  • at least : {condition:'any', min_matching:1, tags:[1,2]}
  • any : {condition:'any', tags:[1,2]}

Copy link
Collaborator Author

@awarn awarn May 15, 2024

Choose a reason for hiding this comment

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

It's what happens on old line 163 that is causing headaches: min_matching: +e.target.value. That forces a zero to be entered when the user deletes the value. So they can never empty the input. We want to change min_matching to be able to have an empty value, but the smartsearch config is only typed for either a number or undefined for min_matching currently.

Which causes problems because we cant resolve this cleanly:

  • at least : {condition:'any', min_matching: undefined, tags:[1,2]}
  • any : {condition:'any', tags:[1,2]}

So we need something extra. Which is what the selected being able to have a value of 'min_matching' is for. The alternative is to extend the type for min_matching to allow a null value, but I was scared of touching that.

Copy link
Member

Choose a reason for hiding this comment

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

I'm just throwing in two things that may be relevant here:

First, as you point out, { foo: undefined } is not the same as {}. But type-wise, I think they are. So it should be possible to delete the min_matching attribute, not just setting it to undefined:

delete obj['min_matching']; // results in object without `min_matching`
obj.min_matching = undefined; // results in object with `min_matching` attribute (value `undefined`)

But second, and more importantly, there is a mistake in the code as it exists on main, because min_matching should not be combined with the any operator, it should be combined with the some operator. That hopefully makes fixing this even easier, because the operator alone should be enough to decide whether to show "at least" or "any" in the UI.

@kaulfield23
Copy link
Contributor

I think it should limit the maximum number, otherwise the sentence can be like this
image
Which looks weird to me

@awarn
Copy link
Collaborator Author

awarn commented May 15, 2024

The problem is that I can't think of a smart way of explaining the upper limit to the user, and the lack of that is what caused part of the bug report in #1930 to start with. You can't go from left to right - "Add", "at least", [number], [tags...] - you have to go - "Add", "at least", [tags...], [number]. We would have to add some extra note, or rearrange the sentence.

@kaulfield23
Copy link
Contributor

Could you also add this logic to src\features\smartSearch\components\filters\Journey\index.tsx when you continue to work on this? Since journey smart search filter copied the same logic from personTag, it has the same bug.

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.

Smart search: Cannot select number in "at least" option in tags filter
3 participants