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

Search - Add Reset filters button to Advanced Filters page #48243

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3761,6 +3761,7 @@ export default {
search: {
resultsAreLimited: 'Search results are limited.',
viewResults: 'View results',
resetFilters: 'Reset filters',
searchResults: {
emptyResults: {
title: 'Nothing to show',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,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í',
Expand Down
12 changes: 11 additions & 1 deletion src/pages/Search/SearchAdvancedFiltersPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +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 * as SearchActions from '@userActions/Search';
import ONYXKEYS from '@src/ONYXKEYS';
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 !== ''));
Copy link
Contributor

Choose a reason for hiding this comment

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

very small nitpick, but instead of this check value !== '' I would just check something like !!value. Just feels safer and more generalised to check if a value is truthy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, it's more readable that way - corrected 👍


return (
<ScreenWrapper
Expand All @@ -16,7 +24,9 @@ function SearchAdvancedFiltersPage() {
offlineIndicatorStyle={styles.mtAuto}
includeSafeAreaPaddingBottom={false}
>
<HeaderWithBackButton title={translate('search.filtersHeader')} />
<HeaderWithBackButton title={translate('search.filtersHeader')}>
{shouldShowResetFilters && <TextLink onPress={SearchActions.clearAdvancedFilters}>{translate('search.resetFilters')}</TextLink>}
</HeaderWithBackButton>
<AdvancedSearchFilters />
</ScreenWrapper>
);
Expand Down
Loading