Skip to content

Commit

Permalink
Search by Category Including Subcategory
Browse files Browse the repository at this point in the history
- Added a new option switch to have the category autocomplete match on category group names
  • Loading branch information
Wizmaster committed May 9, 2024
1 parent 7c658da commit 6c08db7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ export function CategoryAutocomplete({
...props
}: CategoryAutocompleteProps) {
const { grouped: defaultCategoryGroups = [] } = useCategories();
const [autocompleteCategoryMatchGroup = false] = useLocalPref(
'autocompleteCategoryMatchGroup',
);
const categorySuggestions: CategoryAutocompleteItem[] = useMemo(
() =>
(categoryGroups || defaultCategoryGroups).reduce(
Expand Down Expand Up @@ -201,7 +204,10 @@ export function CategoryAutocomplete({
return suggestions.filter(suggestion => {
return (
suggestion.id === 'split' ||
defaultFilterSuggestion(suggestion, value)
defaultFilterSuggestion(suggestion, value) ||
(autocompleteCategoryMatchGroup &&
suggestion.group &&
defaultFilterSuggestion(suggestion.group, value))
);
});
}}
Expand Down
38 changes: 38 additions & 0 deletions packages/desktop-client/src/components/settings/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';

import { useLocalPref } from '../../hooks/useLocalPref';
import { Text } from '../common/Text';
import { Checkbox } from '../forms';

import { Setting } from './UI';

export function AutocompleteSettings() {
const [
autocompleteCategoryMatchGroup = false,
setAutocompleteCategoryMatchGroupPref,
] = useLocalPref('autocompleteCategoryMatchGroup');

return (
<Setting
primaryAction={
<Text style={{ display: 'flex' }}>
<Checkbox
id="settings-autocompleteCategoryMatchGroup"
checked={!!autocompleteCategoryMatchGroup}
onChange={e =>
setAutocompleteCategoryMatchGroupPref(e.currentTarget.checked)
}
/>
<label htmlFor="settings-autocompleteCategoryMatchGroup">
Category autocomplete search match on category group names
</label>
</Text>
}
>
<Text>
<strong>Autocomplete</strong> change the behavior of the autocomplete
dropdowns.
</Text>
</Setting>
);
}
2 changes: 2 additions & 0 deletions packages/desktop-client/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { FormField, FormLabel } from '../forms';
import { Page } from '../Page';
import { useServerVersion } from '../ServerContext';

import { AutocompleteSettings } from './Autocomplete';
import { EncryptionSettings } from './Encryption';
import { ExperimentalFeatures } from './Experimental';
import { ExportBudget } from './Export';
Expand Down Expand Up @@ -174,6 +175,7 @@ export function Settings() {

<AdvancedToggle>
<AdvancedAbout />
<AutocompleteSettings />
<ResetCache />
<ResetSync />
<FixSplits />
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/types/prefs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type LocalPrefs = Partial<
reportsViewSummary: boolean;
reportsViewLabel: boolean;
'mobile.showSpentColumn': boolean;
autocompleteCategoryMatchGroup: boolean;
} & Record<`flags.${FeatureFlag}`, boolean>
>;

Expand Down
5 changes: 5 additions & 0 deletions upcoming-release-notes/2731.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: Enhancements
authors: [Wizmaster]
---
Add option to have the Category autocomplete match on Category Group names

0 comments on commit 6c08db7

Please sign in to comment.