From 4c1dd134fbafaff98d9a6f2425e9cee0b9fb8d21 Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:16:26 +0200 Subject: [PATCH 1/5] add reset filters header button to advanced search --- src/languages/en.ts | 1 + src/languages/es.ts | 1 + src/pages/Search/SearchAdvancedFiltersPage.tsx | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 8a8fc815ddb4..c2af30410f0d 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -3721,6 +3721,7 @@ export default { search: { resultsAreLimited: 'Search results are limited.', viewResults: 'View results', + resetFilters: 'Reset filters', searchResults: { emptyResults: { title: 'Nothing to show', diff --git a/src/languages/es.ts b/src/languages/es.ts index a51ce1d91bf7..8ccedc39b5fb 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -3771,6 +3771,7 @@ export default { search: { resultsAreLimited: 'Los resultados de búsqueda están limitados.', viewResults: 'Ver resultados', + resetFilters: 'Restablecer filtros', searchResults: { emptyResults: { title: 'No hay nada que ver aquí', diff --git a/src/pages/Search/SearchAdvancedFiltersPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage.tsx index 28241b143a9f..bc62b68f0265 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage.tsx @@ -4,10 +4,19 @@ import ScreenWrapper from '@components/ScreenWrapper'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import AdvancedSearchFilters from './AdvancedSearchFilters'; +import TextLink from '@components/TextLink'; +import * as SearchActions from '@userActions/Search'; +import type {SearchAdvancedFiltersForm} from '@src/types/form'; +import {useOnyx} from 'react-native-onyx'; +import ONYXKEYS from '@src/ONYXKEYS'; +import { isEmptyObject } from '@src/types/utils/EmptyObject'; function SearchAdvancedFiltersPage() { const styles = useThemeStyles(); const {translate} = useLocalize(); + const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); + + const shouldShowResetFilters = Object.values(searchAdvancedFilters).some(value => Array.isArray(value) ? value.length !== 0 : value !== ''); return ( - + + {shouldShowResetFilters && + + {translate('search.resetFilters')} + + } + ); From 7912c21253e3cf35f2a13ebe6ab0c6aebd86c34c Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:17:15 +0200 Subject: [PATCH 2/5] fix prettier --- src/pages/Search/SearchAdvancedFiltersPage.tsx | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/pages/Search/SearchAdvancedFiltersPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage.tsx index bc62b68f0265..87fa3ad3078a 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage.tsx @@ -1,22 +1,21 @@ import React from 'react'; +import {useOnyx} from 'react-native-onyx'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; +import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import AdvancedSearchFilters from './AdvancedSearchFilters'; -import TextLink from '@components/TextLink'; import * as SearchActions from '@userActions/Search'; -import type {SearchAdvancedFiltersForm} from '@src/types/form'; -import {useOnyx} from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; -import { isEmptyObject } from '@src/types/utils/EmptyObject'; +import type {SearchAdvancedFiltersForm} from '@src/types/form'; +import AdvancedSearchFilters from './AdvancedSearchFilters'; function SearchAdvancedFiltersPage() { const styles = useThemeStyles(); const {translate} = useLocalize(); const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); - const shouldShowResetFilters = Object.values(searchAdvancedFilters).some(value => Array.isArray(value) ? value.length !== 0 : value !== ''); + const shouldShowResetFilters = Object.values(searchAdvancedFilters).some((value) => (Array.isArray(value) ? value.length !== 0 : value !== '')); return ( - {shouldShowResetFilters && - - {translate('search.resetFilters')} - - } + {shouldShowResetFilters && {translate('search.resetFilters')}} From e04fc69e124b4dc2ac9a16a57619b5eac75f3bfb Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:57:35 +0200 Subject: [PATCH 3/5] use boolean cast to assert if value is truthy --- src/pages/Search/SearchAdvancedFiltersPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Search/SearchAdvancedFiltersPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage.tsx index 87fa3ad3078a..d38ff755f210 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage.tsx @@ -15,7 +15,7 @@ function SearchAdvancedFiltersPage() { const {translate} = useLocalize(); const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); - const shouldShowResetFilters = Object.values(searchAdvancedFilters).some((value) => (Array.isArray(value) ? value.length !== 0 : value !== '')); + const shouldShowResetFilters = Object.values(searchAdvancedFilters).some((value) => (Array.isArray(value) ? !!value.length : !!value)); return ( Date: Thu, 29 Aug 2024 10:59:30 +0200 Subject: [PATCH 4/5] change value length check --- src/pages/Search/SearchAdvancedFiltersPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/Search/SearchAdvancedFiltersPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage.tsx index d38ff755f210..d8fc7a7ed49e 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage.tsx @@ -15,7 +15,7 @@ function SearchAdvancedFiltersPage() { const {translate} = useLocalize(); const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); - const shouldShowResetFilters = Object.values(searchAdvancedFilters).some((value) => (Array.isArray(value) ? !!value.length : !!value)); + const shouldShowResetFilters = Object.values(searchAdvancedFilters).some((value) => (Array.isArray(value) ? value.length !== 0 : !!value)); return ( Date: Thu, 29 Aug 2024 11:30:25 +0200 Subject: [PATCH 5/5] declare default value outside of destructuring to fix react compiler error --- src/pages/Search/SearchAdvancedFiltersPage.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/Search/SearchAdvancedFiltersPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage.tsx index d8fc7a7ed49e..9c205de2433b 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage.tsx @@ -13,7 +13,9 @@ import AdvancedSearchFilters from './AdvancedSearchFilters'; function SearchAdvancedFiltersPage() { const styles = useThemeStyles(); const {translate} = useLocalize(); - const [searchAdvancedFilters = {} as SearchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); + + const emptySearchFilters: SearchAdvancedFiltersForm = {} as SearchAdvancedFiltersForm; + const [searchAdvancedFilters = emptySearchFilters] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); const shouldShowResetFilters = Object.values(searchAdvancedFilters).some((value) => (Array.isArray(value) ? value.length !== 0 : !!value));