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

Add more search filters #52938

Merged
merged 26 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 23 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
9 changes: 9 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6070,13 +6070,22 @@ const CONST = {
REPORT_ID: 'reportID',
KEYWORD: 'keyword',
IN: 'in',
SUBMITTED: 'submitted',
APPROVED: 'approved',
PAID: 'paid',
EXPORTED: 'exported',
POSTED: 'posted',
},
EMPTY_VALUE: 'none',
SEARCH_ROUTER_ITEM_TYPE: {
CONTEXTUAL_SUGGESTION: 'contextualSuggestion',
AUTOCOMPLETE_SUGGESTION: 'autocompleteSuggestion',
SEARCH: 'searchItem',
},
DATE_MODIFIERS: {
BEFORE: 'Before',
AFTER: 'After',
},
},

REFERRER: {
Expand Down
5 changes: 5 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ const ROUTES = {
SEARCH_ADVANCED_FILTERS_FROM: 'search/filters/from',
SEARCH_ADVANCED_FILTERS_TO: 'search/filters/to',
SEARCH_ADVANCED_FILTERS_IN: 'search/filters/in',
SEARCH_ADVANCED_FILTERS_SUBMITTED: 'search/filters/submitted',
SEARCH_ADVANCED_FILTERS_APPROVED: 'search/filters/approved',
SEARCH_ADVANCED_FILTERS_PAID: 'search/filters/paid',
SEARCH_ADVANCED_FILTERS_EXPORTED: 'search/filters/exported',
SEARCH_ADVANCED_FILTERS_POSTED: 'search/filters/posted',
SEARCH_REPORT: {
route: 'search/view/:reportID/:reportActionID?',
getRoute: ({reportID, reportActionID, backTo}: {reportID: string; reportActionID?: string; backTo?: string}) => {
Expand Down
5 changes: 5 additions & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const SCREENS = {
REPORT_RHP: 'Search_Report_RHP',
ADVANCED_FILTERS_RHP: 'Search_Advanced_Filters_RHP',
ADVANCED_FILTERS_DATE_RHP: 'Search_Advanced_Filters_Date_RHP',
ADVANCED_FILTERS_SUBMITTED_RHP: 'Search_Advanced_Filters_Submitted_RHP',
ADVANCED_FILTERS_APPROVED_RHP: 'Search_Advanced_Filters_Approved_RHP',
ADVANCED_FILTERS_PAID_RHP: 'Search_Advanced_Filters_Paid_RHP',
ADVANCED_FILTERS_EXPORTED_RHP: 'Search_Advanced_Filters_Exported_RHP',
ADVANCED_FILTERS_POSTED_RHP: 'Search_Advanced_Filters_Posted_RHP',
ADVANCED_FILTERS_CURRENCY_RHP: 'Search_Advanced_Filters_Currency_RHP',
ADVANCED_FILTERS_DESCRIPTION_RHP: 'Search_Advanced_Filters_Description_RHP',
ADVANCED_FILTERS_MERCHANT_RHP: 'Search_Advanced_Filters_Merchant_RHP',
Expand Down
87 changes: 87 additions & 0 deletions src/components/Search/SearchDateFilterBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {format} from 'date-fns';
import React from 'react';
import {useOnyx} from 'react-native-onyx';
import DatePicker from '@components/DatePicker';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormOnyxValues} from '@components/Form/types';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {updateAdvancedFilters} from '@libs/actions/Search';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {SearchDateFilterKeys} from './types';

type SearchDateFilterBaseProps = {
/** Key used for the date filter */
dateKey: SearchDateFilterKeys;

/** The translation key for the page title */
titleKey: TranslationPaths;
};

function SearchDateFilterBase({dateKey, titleKey}: SearchDateFilterBaseProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();

const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM);
const unformattedDateAfter = searchAdvancedFiltersForm?.[`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.AFTER}`];
const unformattedDateBefore = searchAdvancedFiltersForm?.[`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.BEFORE}`];
const dateAfter = unformattedDateAfter ? format(unformattedDateAfter, 'yyyy-MM-dd') : undefined;
const dateBefore = unformattedDateBefore ? format(unformattedDateBefore, 'yyyy-MM-dd') : undefined;

const updateDateFilter = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM>) => {
updateAdvancedFilters(values);
Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS);
};

return (
<ScreenWrapper
testID={SearchDateFilterBase.displayName}
shouldShowOfflineIndicatorInWideScreen
offlineIndicatorStyle={styles.mtAuto}
includeSafeAreaPaddingBottom
shouldEnableMaxHeight
>
<HeaderWithBackButton
title={translate(titleKey)}
onBackButtonPress={() => {
Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS);
}}
/>
<FormProvider
style={[styles.flex1, styles.ph5]}
formID={ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM}
onSubmit={updateDateFilter}
submitButtonText={translate('common.save')}
enabledWhenOffline
>
<InputWrapper
InputComponent={DatePicker}
inputID={`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.AFTER}`}
label={translate('search.filters.date.after')}
defaultValue={dateAfter}
maxDate={CONST.CALENDAR_PICKER.MAX_DATE}
minDate={CONST.CALENDAR_PICKER.MIN_DATE}
/>
<InputWrapper
InputComponent={DatePicker}
inputID={`${dateKey}${CONST.SEARCH.DATE_MODIFIERS.BEFORE}`}
label={translate('search.filters.date.before')}
defaultValue={dateBefore}
maxDate={CONST.CALENDAR_PICKER.MAX_DATE}
Copy link
Contributor

@dukenv0307 dukenv0307 Dec 4, 2024

Choose a reason for hiding this comment

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

should we handle maxDate and minDate of dateBefore based on dateAfter and vice versa?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't do that for the current date filter, so I'm inclined to not change the behaviour as part of this PR.

minDate={CONST.CALENDAR_PICKER.MIN_DATE}
/>
</FormProvider>
</ScreenWrapper>
);
}

SearchDateFilterBase.displayName = 'SearchDateFilterBase';

export default SearchDateFilterBase;
9 changes: 9 additions & 0 deletions src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ type QueryFilter = {
value: string | number;
};

type SearchDateFilterKeys =
| typeof CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE
| typeof CONST.SEARCH.SYNTAX_FILTER_KEYS.SUBMITTED
| typeof CONST.SEARCH.SYNTAX_FILTER_KEYS.APPROVED
| typeof CONST.SEARCH.SYNTAX_FILTER_KEYS.PAID
| typeof CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPORTED
| typeof CONST.SEARCH.SYNTAX_FILTER_KEYS.POSTED;

type SearchFilterKey =
| ValueOf<typeof CONST.SEARCH.SYNTAX_FILTER_KEYS>
| typeof CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE
Expand Down Expand Up @@ -129,6 +137,7 @@ export type {
SelectedTransactionInfo,
SelectedTransactions,
SearchColumnType,
SearchDateFilterKeys,
SearchStatus,
SearchQueryAST,
SearchQueryJSON,
Expand Down
5 changes: 5 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4571,6 +4571,11 @@ const translations = {
},
current: 'Current',
past: 'Past',
submitted: 'Submitted',
approved: 'Approved',
paid: 'Paid',
exported: 'Exported',
posted: 'Posted',
},
noCategory: 'No category',
noTag: 'No tag',
Expand Down
5 changes: 5 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4620,6 +4620,11 @@ const translations = {
},
current: 'Actual',
past: 'Anterior',
submitted: 'Enviado',
approved: 'Aprobado',
paid: 'Pagado',
exported: 'Exportado',
posted: 'Contabilizado',
},
noCategory: 'Sin categoría',
noTag: 'Sin etiqueta',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,11 @@ const SearchReportModalStackNavigator = createModalStackNavigator<SearchReportPa
const SearchAdvancedFiltersModalStackNavigator = createModalStackNavigator<SearchAdvancedFiltersParamList>({
[SCREENS.SEARCH.ADVANCED_FILTERS_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_DATE_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersDatePage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_SUBMITTED_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersSubmittedPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_APPROVED_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersApprovedPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_PAID_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersPaidPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_EXPORTED_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersExportedPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_POSTED_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersPostedPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_CURRENCY_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersCurrencyPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_DESCRIPTION_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersDescriptionPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_MERCHANT_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersMerchantPage').default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const CENTRAL_PANE_TO_RHP_MAPPING: Partial<Record<CentralPaneName, string[]>> =
SCREENS.SEARCH.ADVANCED_FILTERS_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_CURRENCY_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_DATE_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_SUBMITTED_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_APPROVED_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_PAID_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_EXPORTED_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_POSTED_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_DESCRIPTION_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_MERCHANT_RHP,
SCREENS.SEARCH.ADVANCED_FILTERS_REPORT_ID_RHP,
Expand Down
5 changes: 5 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,11 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
screens: {
[SCREENS.SEARCH.ADVANCED_FILTERS_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS,
[SCREENS.SEARCH.ADVANCED_FILTERS_DATE_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_DATE,
[SCREENS.SEARCH.ADVANCED_FILTERS_SUBMITTED_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_SUBMITTED,
[SCREENS.SEARCH.ADVANCED_FILTERS_APPROVED_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_APPROVED,
[SCREENS.SEARCH.ADVANCED_FILTERS_PAID_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_PAID,
[SCREENS.SEARCH.ADVANCED_FILTERS_EXPORTED_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_EXPORTED,
[SCREENS.SEARCH.ADVANCED_FILTERS_POSTED_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_POSTED,
[SCREENS.SEARCH.ADVANCED_FILTERS_CURRENCY_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_CURRENCY,
[SCREENS.SEARCH.ADVANCED_FILTERS_MERCHANT_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_MERCHANT,
[SCREENS.SEARCH.ADVANCED_FILTERS_DESCRIPTION_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_DESCRIPTION,
Expand Down
Loading
Loading