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

create advanced filters has #47918

Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5229,6 +5229,7 @@ const CONST = {
EXPENSE: 'expense',
INVOICE: 'invoice',
TRIP: 'trip',
CHAT: 'chat',
},
ACTION_TYPES: {
VIEW: 'view',
Expand Down Expand Up @@ -5272,6 +5273,10 @@ const CONST = {
PAID: 'paid',
},
},
CHAT_TYPES: {
LINK: 'link',
ATTACHMENT: 'attachment',
},
TABLE_COLUMNS: {
RECEIPT: 'receipt',
DATE: 'date',
Expand Down Expand Up @@ -5318,6 +5323,7 @@ const CONST = {
CARD_ID: 'cardID',
REPORT_ID: 'reportID',
KEYWORD: 'keyword',
HAS: 'has',
},
},

Expand Down
1 change: 1 addition & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ROUTES = {
SEARCH_ADVANCED_FILTERS_TAG: 'search/filters/tag',
SEARCH_ADVANCED_FILTERS_FROM: 'search/filters/from',
SEARCH_ADVANCED_FILTERS_TO: 'search/filters/to',
SEARCH_ADVANCED_FILTERS_HAS: 'search/filters/has',

SEARCH_REPORT: {
route: 'search/view/:reportID',
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const SCREENS = {
ADVANCED_FILTERS_TAG_RHP: 'Search_Advanced_Filters_Tag_RHP',
ADVANCED_FILTERS_FROM_RHP: 'Search_Advanced_Filters_From_RHP',
ADVANCED_FILTERS_TO_RHP: 'Search_Advanced_Filters_To_RHP',
ADVANCED_FILTERS_HAS_RHP: 'Search_Advanced_Filters_Has_RHP',
TRANSACTION_HOLD_REASON_RHP: 'Search_Transaction_Hold_Reason_RHP',
BOTTOM_TAB: 'Search_Bottom_Tab',
},
Expand Down
6 changes: 5 additions & 1 deletion src/components/Search/SearchMultipleSelectionPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useCallback, useMemo, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import Button from '@components/Button';
import SelectionList from '@components/SelectionList';
import SelectableListItem from '@components/SelectionList/SelectableListItem';
Expand Down Expand Up @@ -28,6 +28,10 @@ function SearchMultipleSelectionPicker({items, initiallySelectedItems, pickerTit
const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState('');
const [selectedItems, setSelectedItems] = useState<SearchMultipleSelectionPickerItem[]>(initiallySelectedItems ?? []);

useEffect(() => {
setSelectedItems(initiallySelectedItems ?? []);
}, [initiallySelectedItems]);

const {sections, noResultsFound} = useMemo(() => {
const selectedItemsSection = selectedItems
.filter((item) => item?.name.toLowerCase().includes(debouncedSearchTerm?.toLowerCase()))
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3799,6 +3799,8 @@ export default {
keyword: 'Keyword',
hasKeywords: 'Has keywords',
currency: 'Currency',
has: 'Has',
link: 'Link',
amount: {
lessThan: (amount?: string) => `Less than ${amount ?? ''}`,
greaterThan: (amount?: string) => `Greater than ${amount ?? ''}`,
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3849,6 +3849,8 @@ export default {
keyword: 'Palabra clave',
hasKeywords: 'Tiene palabras clave',
currency: 'Divisa',
has: 'Tiene',
link: 'Enlace',
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
amount: {
lessThan: (amount?: string) => `Menos de ${amount ?? ''}`,
greaterThan: (amount?: string) => `Más que ${amount ?? ''}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ const SearchAdvancedFiltersModalStackNavigator = createModalStackNavigator<Searc
[SCREENS.SEARCH.ADVANCED_FILTERS_TAG_RHP]: () => require<ReactComponentModule>('../../../../pages/Search/SearchAdvancedFiltersPage/SearchFiltersTagPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_FROM_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersFromPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_TO_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersToPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_HAS_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersHasPage').default,
});

const RestrictedActionModalStackNavigator = createModalStackNavigator<SearchReportParamList>({
Expand Down
1 change: 1 addition & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.SEARCH.ADVANCED_FILTERS_TAG_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_TAG,
[SCREENS.SEARCH.ADVANCED_FILTERS_FROM_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_FROM,
[SCREENS.SEARCH.ADVANCED_FILTERS_TO_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_TO,
[SCREENS.SEARCH.ADVANCED_FILTERS_HAS_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_HAS,
},
},
[SCREENS.RIGHT_MODAL.RESTRICTED_ACTION]: {
Expand Down
66 changes: 42 additions & 24 deletions src/libs/SearchParser/searchParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ function peg$parse(input, options) {
var peg$c22 = "sortBy";
var peg$c23 = "sortOrder";
var peg$c24 = "policyID";
var peg$c25 = "\"";
var peg$c25 = "has";
var peg$c26 = "\"";

var peg$r0 = /^[:=]/;
var peg$r1 = /^[^"\r\n]/;
Expand Down Expand Up @@ -233,11 +234,12 @@ function peg$parse(input, options) {
var peg$e23 = peg$literalExpectation("sortBy", false);
var peg$e24 = peg$literalExpectation("sortOrder", false);
var peg$e25 = peg$literalExpectation("policyID", false);
var peg$e26 = peg$literalExpectation("\"", false);
var peg$e27 = peg$classExpectation(["\"", "\r", "\n"], true, false);
var peg$e28 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false);
var peg$e29 = peg$otherExpectation("whitespace");
var peg$e30 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false);
var peg$e26 = peg$literalExpectation("has", false);
var peg$e27 = peg$literalExpectation("\"", false);
var peg$e28 = peg$classExpectation(["\"", "\r", "\n"], true, false);
var peg$e29 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false);
var peg$e30 = peg$otherExpectation("whitespace");
var peg$e31 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false);

var peg$f0 = function(filters) {
const withDefaults = applyDefaults(filters);
Expand Down Expand Up @@ -311,10 +313,11 @@ function peg$parse(input, options) {
var peg$f26 = function() { return "sortBy"; };
var peg$f27 = function() { return "sortOrder"; };
var peg$f28 = function() { return "policyID"; };
var peg$f29 = function(parts) { return parts.join(''); };
var peg$f30 = function(chars) { return chars.join(''); };
var peg$f29 = function() { return "has"; };
var peg$f30 = function(parts) { return parts.join(''); };
var peg$f31 = function(chars) { return chars.join(''); };
var peg$f32 = function() { return "and"; };
var peg$f32 = function(chars) { return chars.join(''); };
var peg$f33 = function() { return "and"; };
var peg$currPos = options.peg$currPos | 0;
var peg$savedPos = peg$currPos;
var peg$posDetailsCache = [{ line: 1, column: 1 }];
Expand Down Expand Up @@ -937,6 +940,21 @@ function peg$parse(input, options) {
s1 = peg$f28();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 3) === peg$c25) {
s1 = peg$c25;
peg$currPos += 3;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e26); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f29();
}
s0 = s1;
}
}
}
}
Expand Down Expand Up @@ -982,7 +1000,7 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f29(s1);
s1 = peg$f30(s1);
}
s0 = s1;

Expand All @@ -994,11 +1012,11 @@ function peg$parse(input, options) {

s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 34) {
s1 = peg$c25;
s1 = peg$c26;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e26); }
if (peg$silentFails === 0) { peg$fail(peg$e27); }
}
if (s1 !== peg$FAILED) {
s2 = [];
Expand All @@ -1007,7 +1025,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e27); }
if (peg$silentFails === 0) { peg$fail(peg$e28); }
}
while (s3 !== peg$FAILED) {
s2.push(s3);
Expand All @@ -1016,19 +1034,19 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e27); }
if (peg$silentFails === 0) { peg$fail(peg$e28); }
}
}
if (input.charCodeAt(peg$currPos) === 34) {
s3 = peg$c25;
s3 = peg$c26;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e26); }
if (peg$silentFails === 0) { peg$fail(peg$e27); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f30(s2);
s0 = peg$f31(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
Expand All @@ -1051,7 +1069,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e28); }
if (peg$silentFails === 0) { peg$fail(peg$e29); }
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
Expand All @@ -1061,15 +1079,15 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e28); }
if (peg$silentFails === 0) { peg$fail(peg$e29); }
}
}
} else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f31(s1);
s1 = peg$f32(s1);
}
s0 = s1;

Expand All @@ -1082,7 +1100,7 @@ function peg$parse(input, options) {
s0 = peg$currPos;
s1 = peg$parse_();
peg$savedPos = s0;
s1 = peg$f32();
s1 = peg$f33();
s0 = s1;

return s0;
Expand All @@ -1098,7 +1116,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e30); }
if (peg$silentFails === 0) { peg$fail(peg$e31); }
}
while (s1 !== peg$FAILED) {
s0.push(s1);
Expand All @@ -1107,12 +1125,12 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e30); }
if (peg$silentFails === 0) { peg$fail(peg$e31); }
}
}
peg$silentFails--;
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e29); }
if (peg$silentFails === 0) { peg$fail(peg$e30); }

return s0;
}
Expand Down
1 change: 1 addition & 0 deletions src/libs/SearchParser/searchParser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ key
/ "sortBy" { return "sortBy"; }
/ "sortOrder" { return "sortOrder"; }
/ "policyID" { return "policyID"; }
/ "has" { return "has"; }

identifier
= parts:(quotedString / alphanumeric)+ { return parts.join(''); }
Expand Down
14 changes: 13 additions & 1 deletion src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,16 @@ function getExpenseTypeTranslationKey(expenseType: ValueOf<typeof CONST.SEARCH.T
}
}

function getChatFiltersTranslationKey(has: ValueOf<typeof CONST.SEARCH.CHAT_TYPES>): TranslationPaths {
// eslint-disable-next-line default-case
switch (has) {
case CONST.SEARCH.CHAT_TYPES.LINK:
return 'search.filters.link';
case CONST.SEARCH.CHAT_TYPES.ATTACHMENT:
return 'common.attachment';
}
}

/**
* Given object with chosen search filters builds correct query string from them
*/
Expand All @@ -453,7 +463,8 @@ function buildQueryStringFromFilters(filterValues: Partial<SearchAdvancedFilters
filterKey === FILTER_KEYS.TAG ||
filterKey === FILTER_KEYS.CURRENCY ||
filterKey === FILTER_KEYS.FROM ||
filterKey === FILTER_KEYS.TO) &&
filterKey === FILTER_KEYS.TO ||
filterKey === FILTER_KEYS.HAS) &&
Array.isArray(filterValue) &&
filterValue.length > 0
) {
Expand Down Expand Up @@ -588,4 +599,5 @@ export {
shouldShowYear,
buildCannedSearchQuery,
getExpenseTypeTranslationKey,
getChatFiltersTranslationKey,
};
Loading
Loading