Skip to content

Commit

Permalink
Update CategoryAutocomplete.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
postonsundays committed Jan 10, 2024
1 parent e792afb commit bbbcef1
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import { View } from '../common/View';

import { Autocomplete, defaultFilterSuggestion } from './Autocomplete';

Check warning on line 23 in packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx

View workflow job for this annotation

GitHub Actions / lint

'defaultFilterSuggestion' is defined but never used. Allowed unused vars must match /^_/u

type CategorySuggestion = CategoryEntity & { group?: CategoryGroupEntity };

export type CategoryListProps = {
items: Array<CategoryEntity & { group?: CategoryGroupEntity }>;
items: Array<CategorySuggestion>;
getItemProps?: (arg: { item }) => Partial<ComponentProps<typeof View>>;
highlightedIndex: number;
embedded: boolean;
Expand Down Expand Up @@ -150,14 +152,7 @@ export function CategoryAutocomplete({
}
return 0;
}}
filterSuggestions={(suggestions, value) => {
return suggestions.filter(suggestion => {
return (
suggestion.id === 'split' ||
defaultFilterSuggestion(suggestion, value)
);
});
}}
filterSuggestions={filterCategorySuggestions}
suggestions={categorySuggestions}
renderItems={(items, getItemProps, highlightedIndex) => (
<CategoryList
Expand Down Expand Up @@ -330,3 +325,15 @@ export function CategoryItem({
function defaultRenderCategoryItem(props: CategoryItemProps) {
return <CategoryItem {...props} />;
}

function filterCategorySuggestions(suggestions: CategorySuggestion[], value) {
return suggestions.filter(suggestion => {
return (
suggestion.id === 'split' ||
[suggestion.name, suggestion.group.name]
.join(' ')
.toLowerCase()
.includes(value.toLowerCase())
);
});
}

0 comments on commit bbbcef1

Please sign in to comment.