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

CB-3753-1809-fr-add-field-hints-in-the-filter-field #3151

Open
wants to merge 11 commits into
base: devel
Choose a base branch
from

Conversation

sergeyteleshev
Copy link
Contributor

No description provided.

@sergeyteleshev sergeyteleshev requested review from Wroud, devnaumov and SychevAndrey and removed request for Wroud and devnaumov December 26, 2024 12:40
@sergeyteleshev sergeyteleshev self-assigned this Dec 26, 2024
Copy link
Contributor

@SychevAndrey SychevAndrey left a comment

Choose a reason for hiding this comment

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

👍🏻

interface InputAutocompleteOptions {
sourceHints: InputAutocompleteProposal[];
matchStrategy?: InputAutocompleteStrategy;
filter?: (suggestion: InputAutocompleteProposal, lastWord?: string) => boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe predicate is more descriptive word for that prop, then filter.

Comment on lines +50 to +52
const words = this.input?.split(' ');

if (!isNotNullDefined(words) || !isNotNullDefined(cursorPosition) || !isNotNullDefined(this.currentWord)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check words and cursor here if currentWord getter should return falsy value if there is no words or cursorPosition?

Comment on lines +101 to +107
(this.matchStrategy === 'startsWith' &&
values.some(value => isNotNullDefined(this.currentWord) && value.startsWith(this.currentWord))) ||
(this.matchStrategy === 'contains' && values.some(value => isNotNullDefined(this.currentWord) && value.includes(this.currentWord))) ||
(this.matchStrategy === 'fuzzy' &&
values.some(value => isNotNullDefined(this.currentWord) && isFuzzySearchable(this.currentWord, value)))
);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(this.matchStrategy === 'startsWith' &&
values.some(value => isNotNullDefined(this.currentWord) && value.startsWith(this.currentWord))) ||
(this.matchStrategy === 'contains' && values.some(value => isNotNullDefined(this.currentWord) && value.includes(this.currentWord))) ||
(this.matchStrategy === 'fuzzy' &&
values.some(value => isNotNullDefined(this.currentWord) && isFuzzySearchable(this.currentWord, value)))
);
})
const isMatch = () => {
const { matchStrategy, currentWord } = this;
if (!isNotNullDefined(currentWord)) {
return false;
}
const matchFunctions: { [key: InputAutocompleteStrategy]: (value: string) => boolean } = {
startsWith: value => value.startsWith(currentWord),
contains: value => value.includes(currentWord),
fuzzy: value => isFuzzySearchable(currentWord, value),
};
return values.some(matchFunctions[matchStrategy]);
};

Maybe like that? And we checked thus.currentWord just above, so maybe we can skip this check:

 if (!isNotNullDefined(currentWord)) {
    return false;
  }

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.

2 participants