Skip to content

Commit

Permalink
Merge pull request #48065 from software-mansion-labs/@szymczak/chat-f…
Browse files Browse the repository at this point in the history
…ilter-is

Add Is filter page
  • Loading branch information
luacmartins authored Sep 5, 2024
2 parents 2de5aea + 370ad45 commit e7bd29a
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 30 deletions.
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5339,6 +5339,11 @@ const CONST = {
DONE: 'done',
PAID: 'paid',
},
CHAT_STATUS: {
UNREAD: 'unread',
PINNED: 'pinned',
DRAFT: 'draft',
},
BULK_ACTION_TYPES: {
EXPORT: 'export',
HOLD: 'hold',
Expand Down Expand Up @@ -5427,6 +5432,7 @@ const CONST = {
KEYWORD: 'keyword',
IN: 'in',
HAS: 'has',
IS: 'is',
},
},

Expand Down
1 change: 1 addition & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const ROUTES = {
SEARCH_ADVANCED_FILTERS_TO: 'search/filters/to',
SEARCH_ADVANCED_FILTERS_IN: 'search/filters/in',
SEARCH_ADVANCED_FILTERS_HAS: 'search/filters/has',
SEARCH_ADVANCED_FILTERS_IS: 'search/filters/is',

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 @@ -48,6 +48,7 @@ const SCREENS = {
ADVANCED_FILTERS_TO_RHP: 'Search_Advanced_Filters_To_RHP',
ADVANCED_FILTERS_IN_RHP: 'Search_Advanced_Filters_In_RHP',
ADVANCED_FILTERS_HAS_RHP: 'Search_Advanced_Filters_Has_RHP',
ADVANCED_FILTERS_IS_RHP: 'Search_Advanced_Filters_Is_RHP',
TRANSACTION_HOLD_REASON_RHP: 'Search_Transaction_Hold_Reason_RHP',
BOTTOM_TAB: 'Search_Bottom_Tab',
},
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3882,6 +3882,10 @@ export default {
currency: 'Currency',
has: 'Has',
link: 'Link',
is: 'Is',
pinned: 'Pinned',
unread: 'Unread',
draft: 'Draft',
amount: {
lessThan: (amount?: string) => `Less than ${amount ?? ''}`,
greaterThan: (amount?: string) => `Greater than ${amount ?? ''}`,
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3933,6 +3933,10 @@ export default {
currency: 'Divisa',
has: 'Tiene',
link: 'Enlace',
is: 'Está',
pinned: 'Fijado',
unread: 'No leído',
draft: 'Borrador',
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 @@ -541,6 +541,7 @@ const SearchAdvancedFiltersModalStackNavigator = createModalStackNavigator<Searc
[SCREENS.SEARCH.ADVANCED_FILTERS_TO_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersToPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_IN_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersInPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_HAS_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersHasPage').default,
[SCREENS.SEARCH.ADVANCED_FILTERS_IS_RHP]: () => require<ReactComponentModule>('@pages/Search/SearchAdvancedFiltersPage/SearchFiltersIsPage').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 @@ -1070,6 +1070,7 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.SEARCH.ADVANCED_FILTERS_TO_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_TO,
[SCREENS.SEARCH.ADVANCED_FILTERS_IN_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_IN,
[SCREENS.SEARCH.ADVANCED_FILTERS_HAS_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_HAS,
[SCREENS.SEARCH.ADVANCED_FILTERS_IS_RHP]: ROUTES.SEARCH_ADVANCED_FILTERS_IS,
},
},
[SCREENS.RIGHT_MODAL.RESTRICTED_ACTION]: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function getTagNamesFromTagsLists(policyTagLists: PolicyTagLists): string[] {
const uniqueTagNames = new Set<string>();

for (const policyTagList of Object.values(policyTagLists ?? {})) {
for (const tag of Object.values(policyTagList.tags)) {
for (const tag of Object.values(policyTagList.tags ?? {})) {
uniqueTagNames.add(getCleanedTagName(tag.name));
}
}
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 @@ -201,7 +201,8 @@ function peg$parse(input, options) {
var peg$c23 = "sortOrder";
var peg$c24 = "policyID";
var peg$c25 = "has";
var peg$c26 = "\"";
var peg$c26 = "is";
var peg$c27 = "\"";

var peg$r0 = /^[:=]/;
var peg$r1 = /^[^"\r\n]/;
Expand Down Expand Up @@ -235,11 +236,12 @@ function peg$parse(input, options) {
var peg$e24 = peg$literalExpectation("sortOrder", false);
var peg$e25 = peg$literalExpectation("policyID", 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$e27 = peg$literalExpectation("is", false);
var peg$e28 = peg$literalExpectation("\"", false);
var peg$e29 = peg$classExpectation(["\"", "\r", "\n"], true, false);
var peg$e30 = peg$classExpectation([["A", "Z"], ["a", "z"], ["0", "9"], "_", "@", ".", "/", "#", "&", "+", "-", "\\", "'", ",", ";"], false, false);
var peg$e31 = peg$otherExpectation("whitespace");
var peg$e32 = peg$classExpectation([" ", "\t", "\r", "\n"], false, false);

var peg$f0 = function(filters) {
const withDefaults = applyDefaults(filters);
Expand Down Expand Up @@ -314,10 +316,11 @@ function peg$parse(input, options) {
var peg$f27 = function() { return "sortOrder"; };
var peg$f28 = function() { return "policyID"; };
var peg$f29 = function() { return "has"; };
var peg$f30 = function(parts) { return parts.join(''); };
var peg$f31 = function(chars) { return chars.join(''); };
var peg$f30 = function() { return "is"; };
var peg$f31 = function(parts) { return parts.join(''); };
var peg$f32 = function(chars) { return chars.join(''); };
var peg$f33 = function() { return "and"; };
var peg$f33 = function(chars) { return chars.join(''); };
var peg$f34 = 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 @@ -954,6 +957,21 @@ function peg$parse(input, options) {
s1 = peg$f29();
}
s0 = s1;
if (s0 === peg$FAILED) {
s0 = peg$currPos;
if (input.substr(peg$currPos, 2) === peg$c26) {
s1 = peg$c26;
peg$currPos += 2;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e27); }
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f30();
}
s0 = s1;
}
}
}
}
Expand Down Expand Up @@ -1000,7 +1018,7 @@ function peg$parse(input, options) {
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f30(s1);
s1 = peg$f31(s1);
}
s0 = s1;

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

s0 = peg$currPos;
if (input.charCodeAt(peg$currPos) === 34) {
s1 = peg$c26;
s1 = peg$c27;
peg$currPos++;
} else {
s1 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e27); }
if (peg$silentFails === 0) { peg$fail(peg$e28); }
}
if (s1 !== peg$FAILED) {
s2 = [];
Expand All @@ -1025,7 +1043,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e28); }
if (peg$silentFails === 0) { peg$fail(peg$e29); }
}
while (s3 !== peg$FAILED) {
s2.push(s3);
Expand All @@ -1034,19 +1052,19 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e28); }
if (peg$silentFails === 0) { peg$fail(peg$e29); }
}
}
if (input.charCodeAt(peg$currPos) === 34) {
s3 = peg$c26;
s3 = peg$c27;
peg$currPos++;
} else {
s3 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e27); }
if (peg$silentFails === 0) { peg$fail(peg$e28); }
}
if (s3 !== peg$FAILED) {
peg$savedPos = s0;
s0 = peg$f31(s2);
s0 = peg$f32(s2);
} else {
peg$currPos = s0;
s0 = peg$FAILED;
Expand All @@ -1069,7 +1087,7 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e29); }
if (peg$silentFails === 0) { peg$fail(peg$e30); }
}
if (s2 !== peg$FAILED) {
while (s2 !== peg$FAILED) {
Expand All @@ -1079,15 +1097,15 @@ function peg$parse(input, options) {
peg$currPos++;
} else {
s2 = peg$FAILED;
if (peg$silentFails === 0) { peg$fail(peg$e29); }
if (peg$silentFails === 0) { peg$fail(peg$e30); }
}
}
} else {
s1 = peg$FAILED;
}
if (s1 !== peg$FAILED) {
peg$savedPos = s0;
s1 = peg$f32(s1);
s1 = peg$f33(s1);
}
s0 = s1;

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

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

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 @@ -135,6 +135,7 @@ key
/ "sortOrder" { return "sortOrder"; }
/ "policyID" { return "policyID"; }
/ "has" { return "has"; }
/ "is" { return "is"; }

identifier
= parts:(quotedString / alphanumeric)+ { return parts.join(''); }
Expand Down
16 changes: 15 additions & 1 deletion src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ function getChatFiltersTranslationKey(has: ValueOf<typeof CONST.SEARCH.CHAT_TYPE
}
}

function getChatStatusTranslationKey(chatStatus: ValueOf<typeof CONST.SEARCH.CHAT_STATUS>): TranslationPaths {
// eslint-disable-next-line default-case
switch (chatStatus) {
case CONST.SEARCH.CHAT_STATUS.PINNED:
return 'search.filters.pinned';
case CONST.SEARCH.CHAT_STATUS.UNREAD:
return 'search.filters.unread';
case CONST.SEARCH.CHAT_STATUS.DRAFT:
return 'search.filters.draft';
}
}

/**
* Given object with chosen search filters builds correct query string from them
*/
Expand Down Expand Up @@ -458,7 +470,8 @@ function buildQueryStringFromFilters(filterValues: Partial<SearchAdvancedFilters
filterKey === FILTER_KEYS.FROM ||
filterKey === FILTER_KEYS.TO ||
filterKey === FILTER_KEYS.IN ||
filterKey === FILTER_KEYS.HAS) &&
filterKey === FILTER_KEYS.HAS ||
filterKey === FILTER_KEYS.IS) &&
Array.isArray(filterValue) &&
filterValue.length > 0
) {
Expand Down Expand Up @@ -605,4 +618,5 @@ export {
isCannedSearchQuery,
getExpenseTypeTranslationKey,
getChatFiltersTranslationKey,
getChatStatusTranslationKey,
};
19 changes: 17 additions & 2 deletions src/pages/Search/AdvancedSearchFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ const baseFilterConfig = {
description: 'common.in' as const,
route: ROUTES.SEARCH_ADVANCED_FILTERS_IN,
},
is: {
getTitle: getFilterIsDisplayTitle,
description: 'search.filters.is' as const,
route: ROUTES.SEARCH_ADVANCED_FILTERS_IS,
},
};

const typeFiltersKeys: Record<string, Array<ValueOf<typeof CONST.SEARCH.SYNTAX_FILTER_KEYS>>> = {
[CONST.SEARCH.DATA_TYPES.EXPENSE]: ['date', 'currency', 'merchant', 'description', 'reportID', 'amount', 'category', 'keyword', 'taxRate', 'expenseType', 'tag', 'from', 'to', 'cardID'],
[CONST.SEARCH.DATA_TYPES.INVOICE]: ['date', 'currency', 'merchant', 'description', 'reportID', 'amount', 'category', 'keyword', 'taxRate', 'tag', 'from', 'to', 'cardID'],
[CONST.SEARCH.DATA_TYPES.TRIP]: ['date', 'currency', 'merchant', 'description', 'reportID', 'amount', 'category', 'keyword', 'taxRate', 'tag', 'from', 'to', 'cardID'],
[CONST.SEARCH.DATA_TYPES.CHAT]: ['date', 'keyword', 'from', 'has', 'in'],
[CONST.SEARCH.DATA_TYPES.CHAT]: ['date', 'keyword', 'from', 'has', 'in', 'is'],
};

function getFilterCardDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, cards: CardList) {
Expand Down Expand Up @@ -232,6 +237,16 @@ function getFilterHasDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, t
: undefined;
}

function getFilterIsDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, translate: LocaleContextProps['translate']) {
const filterValue = filters[CONST.SEARCH.SYNTAX_FILTER_KEYS.IS];
return filterValue
? Object.values(CONST.SEARCH.CHAT_STATUS)
.filter((chatStatus) => filterValue.includes(chatStatus))
.map((chatStatus) => translate(SearchUtils.getChatStatusTranslationKey(chatStatus)))
.join(', ')
: undefined;
}

function AdvancedSearchFilters() {
const {translate} = useLocalize();
const styles = useThemeStyles();
Expand Down Expand Up @@ -278,7 +293,7 @@ function AdvancedSearchFilters() {
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, cardList);
} else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE) {
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, taxRates);
} else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE || key === CONST.SEARCH.SYNTAX_FILTER_KEYS.HAS) {
} else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE || key === CONST.SEARCH.SYNTAX_FILTER_KEYS.HAS || key === CONST.SEARCH.SYNTAX_FILTER_KEYS.IS) {
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters, translate);
} else if (key === CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM || key === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO) {
filterTitle = baseFilterConfig[key].getTitle(searchAdvancedFilters[key] ?? [], personalDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ function SearchFiltersExpenseTypePage() {
);
}

SearchFiltersExpenseTypePage.displayName = 'SearchFiltersCategoryPage';
SearchFiltersExpenseTypePage.displayName = 'SearchFiltersExpenseTypePage';

export default SearchFiltersExpenseTypePage;
Loading

0 comments on commit e7bd29a

Please sign in to comment.