Skip to content

Commit 4fd8e5c

Browse files
committed
feat: show reset filters button when type and status filters change
1 parent 9e15e3a commit 4fd8e5c

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/libs/actions/Search.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import {isReportListItemType, isTransactionListItemType} from '@libs/SearchUIUti
1818
import playSound, {SOUNDS} from '@libs/Sound';
1919
import CONST from '@src/CONST';
2020
import ONYXKEYS from '@src/ONYXKEYS';
21-
import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm';
21+
import {FILTER_KEYS} from '@src/types/form/SearchAdvancedFiltersForm';
22+
import type {SearchAdvancedFiltersForm} from '@src/types/form/SearchAdvancedFiltersForm';
2223
import type {LastPaymentMethod, LastPaymentMethodType, SearchResults} from '@src/types/onyx';
2324
import type {SearchPolicy, SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults';
2425
import type Nullable from '@src/types/utils/Nullable';
@@ -421,10 +422,20 @@ function clearAllFilters() {
421422
}
422423

423424
function clearAdvancedFilters() {
424-
const values: Partial<Record<ValueOf<typeof FILTER_KEYS>, null>> = {};
425+
const values: Partial<Nullable<SearchAdvancedFiltersForm>> = {};
425426
Object.values(FILTER_KEYS)
426-
.filter((key) => !([FILTER_KEYS.TYPE, FILTER_KEYS.STATUS, FILTER_KEYS.GROUP_BY] as string[]).includes(key))
427+
.filter((key) => key !== FILTER_KEYS.GROUP_BY)
427428
.forEach((key) => {
429+
if (key === FILTER_KEYS.TYPE) {
430+
values[key] = CONST.SEARCH.DATA_TYPES.EXPENSE;
431+
return;
432+
}
433+
434+
if (key === FILTER_KEYS.STATUS) {
435+
values[key] = CONST.SEARCH.STATUS.EXPENSE.ALL;
436+
return;
437+
}
438+
428439
values[key] = null;
429440
});
430441

src/pages/Search/SearchAdvancedFiltersPage.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ function SearchAdvancedFiltersPage() {
1919
const [searchAdvancedFilters = emptySearchFilters] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM, {canBeMissing: true});
2020

2121
const shouldShowResetFilters = Object.entries(searchAdvancedFilters)
22-
.filter(([key]) => !([CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE, CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS, CONST.SEARCH.SYNTAX_ROOT_KEYS.GROUP_BY] as string[]).includes(key))
22+
.filter(([key]) => {
23+
if (key === CONST.SEARCH.SYNTAX_ROOT_KEYS.GROUP_BY) {
24+
return false;
25+
}
26+
27+
if (key === CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE) {
28+
return searchAdvancedFilters.type !== CONST.SEARCH.DATA_TYPES.EXPENSE;
29+
}
30+
31+
if (key === CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS) {
32+
return searchAdvancedFilters.status !== CONST.SEARCH.STATUS.EXPENSE.ALL;
33+
}
34+
35+
return true;
36+
})
2337
.some(([, value]) => (Array.isArray(value) ? value.length !== 0 : !!value));
2438

2539
return (

0 commit comments

Comments
 (0)