From 284189bd2fe9cf55c985eb64cc60faaf4844e398 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 4 Nov 2024 14:01:02 -0700 Subject: [PATCH 1/5] update grammar --- src/libs/SearchParser/autocompleteParser.js | 16 +++--- .../SearchParser/autocompleteParser.peggy | 4 +- src/libs/SearchParser/searchParser.js | 52 +++++++++---------- src/libs/SearchParser/searchParser.peggy | 10 ++-- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/libs/SearchParser/autocompleteParser.js b/src/libs/SearchParser/autocompleteParser.js index be57ff8a67a5..52f04f414e2a 100644 --- a/src/libs/SearchParser/autocompleteParser.js +++ b/src/libs/SearchParser/autocompleteParser.js @@ -181,9 +181,9 @@ function peg$parse(input, options) { var peg$c3 = "tag"; var peg$c4 = "category"; var peg$c5 = "to"; - var peg$c6 = "taxRate"; + var peg$c6 = "tax-rate"; var peg$c7 = "from"; - var peg$c8 = "expenseType"; + var peg$c8 = "expense-type"; var peg$c9 = "type"; var peg$c10 = "status"; var peg$c11 = "!="; @@ -206,9 +206,9 @@ function peg$parse(input, options) { var peg$e4 = peg$literalExpectation("tag", false); var peg$e5 = peg$literalExpectation("category", false); var peg$e6 = peg$literalExpectation("to", false); - var peg$e7 = peg$literalExpectation("taxRate", false); + var peg$e7 = peg$literalExpectation("tax-rate", false); var peg$e8 = peg$literalExpectation("from", false); - var peg$e9 = peg$literalExpectation("expenseType", false); + var peg$e9 = peg$literalExpectation("expense-type", false); var peg$e10 = peg$literalExpectation("type", false); var peg$e11 = peg$literalExpectation("status", false); var peg$e12 = peg$otherExpectation("operator"); @@ -605,9 +605,9 @@ function peg$parse(input, options) { if (peg$silentFails === 0) { peg$fail(peg$e6); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c6) { + if (input.substr(peg$currPos, 8) === peg$c6) { s1 = peg$c6; - peg$currPos += 7; + peg$currPos += 8; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e7); } @@ -621,9 +621,9 @@ function peg$parse(input, options) { if (peg$silentFails === 0) { peg$fail(peg$e8); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c8) { + if (input.substr(peg$currPos, 12) === peg$c8) { s1 = peg$c8; - peg$currPos += 11; + peg$currPos += 12; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e9); } diff --git a/src/libs/SearchParser/autocompleteParser.peggy b/src/libs/SearchParser/autocompleteParser.peggy index 89d89fd07cd4..e0a2ac786169 100644 --- a/src/libs/SearchParser/autocompleteParser.peggy +++ b/src/libs/SearchParser/autocompleteParser.peggy @@ -56,9 +56,9 @@ autocompleteKey "key" / "tag" / "category" / "to" - / "taxRate" + / "tax-rate" / "from" - / "expenseType" + / "expense-type" / "type" / "status" ) diff --git a/src/libs/SearchParser/searchParser.js b/src/libs/SearchParser/searchParser.js index c94222f3a6e9..79a88e160afc 100644 --- a/src/libs/SearchParser/searchParser.js +++ b/src/libs/SearchParser/searchParser.js @@ -184,22 +184,22 @@ function peg$parse(input, options) { var peg$c1 = "amount"; var peg$c2 = "merchant"; var peg$c3 = "description"; - var peg$c4 = "reportID"; + var peg$c4 = "reportid"; var peg$c5 = "keyword"; var peg$c6 = "in"; var peg$c7 = "currency"; var peg$c8 = "tag"; var peg$c9 = "category"; var peg$c10 = "to"; - var peg$c11 = "taxRate"; - var peg$c12 = "cardID"; + var peg$c11 = "tax-rate"; + var peg$c12 = "dard"; var peg$c13 = "from"; - var peg$c14 = "expenseType"; + var peg$c14 = "expense-type"; var peg$c15 = "type"; var peg$c16 = "status"; - var peg$c17 = "sortBy"; - var peg$c18 = "sortOrder"; - var peg$c19 = "policyID"; + var peg$c17 = "sort-by"; + var peg$c18 = "sort-order"; + var peg$c19 = "workspacec"; var peg$c20 = ","; var peg$c21 = "!="; var peg$c22 = ">="; @@ -221,23 +221,23 @@ function peg$parse(input, options) { var peg$e3 = peg$literalExpectation("amount", false); var peg$e4 = peg$literalExpectation("merchant", false); var peg$e5 = peg$literalExpectation("description", false); - var peg$e6 = peg$literalExpectation("reportID", false); + var peg$e6 = peg$literalExpectation("reportid", false); var peg$e7 = peg$literalExpectation("keyword", false); var peg$e8 = peg$literalExpectation("in", false); var peg$e9 = peg$literalExpectation("currency", false); var peg$e10 = peg$literalExpectation("tag", false); var peg$e11 = peg$literalExpectation("category", false); var peg$e12 = peg$literalExpectation("to", false); - var peg$e13 = peg$literalExpectation("taxRate", false); - var peg$e14 = peg$literalExpectation("cardID", false); + var peg$e13 = peg$literalExpectation("tax-rate", false); + var peg$e14 = peg$literalExpectation("dard", false); var peg$e15 = peg$literalExpectation("from", false); - var peg$e16 = peg$literalExpectation("expenseType", false); + var peg$e16 = peg$literalExpectation("expense-type", false); var peg$e17 = peg$otherExpectation("default key"); var peg$e18 = peg$literalExpectation("type", false); var peg$e19 = peg$literalExpectation("status", false); - var peg$e20 = peg$literalExpectation("sortBy", false); - var peg$e21 = peg$literalExpectation("sortOrder", false); - var peg$e22 = peg$literalExpectation("policyID", false); + var peg$e20 = peg$literalExpectation("sort-by", false); + var peg$e21 = peg$literalExpectation("sort-order", false); + var peg$e22 = peg$literalExpectation("workspacec", false); var peg$e23 = peg$literalExpectation(",", false); var peg$e24 = peg$otherExpectation("operator"); var peg$e25 = peg$classExpectation([":", "="], false, false); @@ -756,17 +756,17 @@ function peg$parse(input, options) { if (peg$silentFails === 0) { peg$fail(peg$e12); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 7) === peg$c11) { + if (input.substr(peg$currPos, 8) === peg$c11) { s1 = peg$c11; - peg$currPos += 7; + peg$currPos += 8; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e13); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c12) { + if (input.substr(peg$currPos, 4) === peg$c12) { s1 = peg$c12; - peg$currPos += 6; + peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e14); } @@ -780,9 +780,9 @@ function peg$parse(input, options) { if (peg$silentFails === 0) { peg$fail(peg$e15); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 11) === peg$c14) { + if (input.substr(peg$currPos, 12) === peg$c14) { s1 = peg$c14; - peg$currPos += 11; + peg$currPos += 12; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e16); } @@ -837,25 +837,25 @@ function peg$parse(input, options) { if (peg$silentFails === 0) { peg$fail(peg$e19); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 6) === peg$c17) { + if (input.substr(peg$currPos, 7) === peg$c17) { s1 = peg$c17; - peg$currPos += 6; + peg$currPos += 7; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e20); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 9) === peg$c18) { + if (input.substr(peg$currPos, 10) === peg$c18) { s1 = peg$c18; - peg$currPos += 9; + peg$currPos += 10; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e21); } } if (s1 === peg$FAILED) { - if (input.substr(peg$currPos, 8) === peg$c19) { + if (input.substr(peg$currPos, 10) === peg$c19) { s1 = peg$c19; - peg$currPos += 8; + peg$currPos += 10; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$e22); } diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index d3aaf5ddf97b..1e74284da16b 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -102,21 +102,21 @@ key "key" / "amount" / "merchant" / "description" - / "reportID" + / "reportid" / "keyword" / "in" / "currency" / "tag" / "category" / "to" - / "taxRate" - / "cardID" + / "tax-rate" + / "dard" / "from" - / "expenseType" + / "expense-type" ) defaultKey "default key" - = @("type" / "status" / "sortBy" / "sortOrder" / "policyID") + = @("type" / "status" / "sort-by" / "sort-order" / "workspacec") identifier = (","+)? parts:(quotedString / alphanumeric)|1.., ","+| empty:(","+)? { From a7ac7eddb23125f0ba1ba96c4595fc897d014477 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 4 Nov 2024 14:10:02 -0700 Subject: [PATCH 2/5] update test --- src/CONST.ts | 14 ++--- tests/unit/SearchAutocompleteParserTest.ts | 73 +++++++++++----------- 2 files changed, 44 insertions(+), 43 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index fbe12d1fdfb2..8e19dbbdcb36 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -5913,14 +5913,14 @@ const CONST = { SYNTAX_ROOT_KEYS: { TYPE: 'type', STATUS: 'status', - SORT_BY: 'sortBy', - SORT_ORDER: 'sortOrder', - POLICY_ID: 'policyID', + SORT_BY: 'sort-by', + SORT_ORDER: 'sort-order', + POLICY_ID: 'workspace', }, SYNTAX_FILTER_KEYS: { DATE: 'date', AMOUNT: 'amount', - EXPENSE_TYPE: 'expenseType', + EXPENSE_TYPE: 'expense-type', CURRENCY: 'currency', MERCHANT: 'merchant', DESCRIPTION: 'description', @@ -5928,9 +5928,9 @@ const CONST = { TO: 'to', CATEGORY: 'category', TAG: 'tag', - TAX_RATE: 'taxRate', - CARD_ID: 'cardID', - REPORT_ID: 'reportID', + TAX_RATE: 'tax-rate', + CARD_ID: 'card', + REPORT_ID: 'reportid', KEYWORD: 'keyword', IN: 'in', }, diff --git a/tests/unit/SearchAutocompleteParserTest.ts b/tests/unit/SearchAutocompleteParserTest.ts index 2571b03089b1..2750b5c6a8e5 100644 --- a/tests/unit/SearchAutocompleteParserTest.ts +++ b/tests/unit/SearchAutocompleteParserTest.ts @@ -1,5 +1,6 @@ import type {SearchQueryJSON} from '@components/Search/types'; import * as autocompleteParser from '@libs/SearchParser/autocompleteParser'; +import CONST from '@src/CONST'; const tests = [ { @@ -27,14 +28,14 @@ const tests = [ query: 'type:expense status:all', expected: { autocomplete: { - key: 'status', + key: CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS, value: 'all', start: 20, length: 3, }, ranges: [ - {key: 'type', value: 'expense', start: 5, length: 7}, - {key: 'status', value: 'all', start: 20, length: 3}, + {key: CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE, value: 'expense', start: 5, length: 7}, + {key: CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS, value: 'all', start: 20, length: 3}, ], }, }, @@ -42,14 +43,14 @@ const tests = [ query: 'in:123456 currency:USD ', expected: { autocomplete: { - key: 'currency', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY, value: 'USD', start: 19, length: 3, }, ranges: [ - {key: 'in', value: '123456', start: 3, length: 6}, - {key: 'currency', value: 'USD', start: 19, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.IN, value: '123456', start: 3, length: 6}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY, value: 'USD', start: 19, length: 3}, ], }, }, @@ -57,15 +58,15 @@ const tests = [ query: 'tag:aa,bbb,cccc', expected: { autocomplete: { - key: 'tag', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, value: 'cccc', start: 11, length: 4, }, ranges: [ - {key: 'tag', value: 'aa', start: 4, length: 2}, - {key: 'tag', value: 'bbb', start: 7, length: 3}, - {key: 'tag', value: 'cccc', start: 11, length: 4}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, value: 'aa', start: 4, length: 2}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, value: 'bbb', start: 7, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, value: 'cccc', start: 11, length: 4}, ], }, }, @@ -73,7 +74,7 @@ const tests = [ query: 'category:', expected: { autocomplete: { - key: 'category', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: '', start: 9, length: 0, @@ -85,26 +86,26 @@ const tests = [ query: 'category:Advertising,', expected: { autocomplete: { - key: 'category', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: '', start: 21, length: 0, }, - ranges: [{key: 'category', value: 'Advertising', start: 9, length: 11}], + ranges: [{key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: 'Advertising', start: 9, length: 11}], }, }, { query: 'in:"Big Room","small room"', expected: { autocomplete: { - key: 'in', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.IN, value: 'small room', start: 14, length: 12, }, ranges: [ - {key: 'in', value: 'Big Room', start: 3, length: 10}, - {key: 'in', value: 'small room', start: 14, length: 12}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.IN, value: 'Big Room', start: 3, length: 10}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.IN, value: 'small room', start: 14, length: 12}, ], }, }, @@ -112,12 +113,12 @@ const tests = [ query: 'category: Car', expected: { autocomplete: { - key: 'category', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: 'Car', start: 12, length: 3, }, - ranges: [{key: 'category', value: 'Car', start: 12, length: 3}], + ranges: [{key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: 'Car', start: 12, length: 3}], }, }, { @@ -125,8 +126,8 @@ const tests = [ expected: { autocomplete: null, ranges: [ - {key: 'type', value: 'expense', start: 5, length: 7}, - {key: 'status', value: 'all', start: 20, length: 3}, + {key: CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE, value: 'expense', start: 5, length: 7}, + {key: CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS, value: 'all', start: 20, length: 3}, ], }, }, @@ -134,19 +135,19 @@ const tests = [ query: 'in:"Big Room" from:Friend category:Car,"Cell Phone" status:all expenseType:card,cash', expected: { autocomplete: { - key: 'expenseType', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE, value: 'cash', start: 80, length: 4, }, ranges: [ - {key: 'in', value: 'Big Room', start: 3, length: 10}, - {key: 'from', value: 'Friend', start: 19, length: 6}, - {key: 'category', value: 'Car', start: 35, length: 3}, - {key: 'category', value: 'Cell Phone', start: 39, length: 12}, - {key: 'status', value: 'all', start: 59, length: 3}, - {key: 'expenseType', value: 'card', start: 75, length: 4}, - {key: 'expenseType', value: 'cash', start: 80, length: 4}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.IN, value: 'Big Room', start: 3, length: 10}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM, value: 'Friend', start: 19, length: 6}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: 'Car', start: 35, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, value: 'Cell Phone', start: 39, length: 12}, + {key: CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS, value: 'all', start: 59, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE, value: 'card', start: 75, length: 4}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE, value: 'cash', start: 80, length: 4}, ], }, }, @@ -154,19 +155,19 @@ const tests = [ query: 'currency:PLN,USD keyword taxRate:tax merchant:"Expensify, Inc." tag:"General Overhead",IT expenseType:card,distance', expected: { autocomplete: { - key: 'expenseType', + key: CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE, value: 'distance', start: 108, length: 8, }, ranges: [ - {key: 'currency', value: 'PLN', start: 9, length: 3}, - {key: 'currency', value: 'USD', start: 13, length: 3}, - {key: 'taxRate', value: 'tax', start: 33, length: 3}, - {key: 'tag', value: 'General Overhead', start: 69, length: 18}, - {key: 'tag', value: 'IT', start: 88, length: 2}, - {key: 'expenseType', value: 'card', start: 103, length: 4}, - {key: 'expenseType', value: 'distance', start: 108, length: 8}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY, value: 'PLN', start: 9, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY, value: 'USD', start: 13, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE, value: 'tax', start: 33, length: 3}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, value: 'General Overhead', start: 69, length: 18}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG, value: 'IT', start: 88, length: 2}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE, value: 'card', start: 103, length: 4}, + {key: CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE, value: 'distance', start: 108, length: 8}, ], }, }, From 95d29e92d2ea0ed0fbbf2c3d617253d747dd67ca Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 4 Nov 2024 14:21:18 -0700 Subject: [PATCH 3/5] update advanced filter --- src/ROUTES.ts | 6 +++--- src/pages/Search/AdvancedSearchFilters.tsx | 14 +++++++------- .../SearchFiltersTaxRatePage.tsx | 3 ++- src/types/form/SearchAdvancedFiltersForm.ts | 10 +++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 45501bf46374..8265d20921df 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -47,13 +47,13 @@ const ROUTES = { SEARCH_ADVANCED_FILTERS_CURRENCY: 'search/filters/currency', SEARCH_ADVANCED_FILTERS_MERCHANT: 'search/filters/merchant', SEARCH_ADVANCED_FILTERS_DESCRIPTION: 'search/filters/description', - SEARCH_ADVANCED_FILTERS_REPORT_ID: 'search/filters/reportID', + SEARCH_ADVANCED_FILTERS_REPORT_ID: 'search/filters/reportid', SEARCH_ADVANCED_FILTERS_AMOUNT: 'search/filters/amount', SEARCH_ADVANCED_FILTERS_CATEGORY: 'search/filters/category', SEARCH_ADVANCED_FILTERS_KEYWORD: 'search/filters/keyword', SEARCH_ADVANCED_FILTERS_CARD: 'search/filters/card', - SEARCH_ADVANCED_FILTERS_TAX_RATE: 'search/filters/taxRate', - SEARCH_ADVANCED_FILTERS_EXPENSE_TYPE: 'search/filters/expenseType', + SEARCH_ADVANCED_FILTERS_TAX_RATE: 'search/filters/tax-rate', + SEARCH_ADVANCED_FILTERS_EXPENSE_TYPE: 'search/filters/expense-type', SEARCH_ADVANCED_FILTERS_TAG: 'search/filters/tag', SEARCH_ADVANCED_FILTERS_FROM: 'search/filters/from', SEARCH_ADVANCED_FILTERS_TO: 'search/filters/to', diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index ce4daabc983a..7ae75fa879a3 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -50,7 +50,7 @@ const baseFilterConfig = { description: 'common.description' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_DESCRIPTION, }, - reportID: { + reportid: { getTitle: getFilterDisplayTitle, description: 'common.reportID' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_REPORT_ID, @@ -70,17 +70,17 @@ const baseFilterConfig = { description: 'search.filters.hasKeywords' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_KEYWORD, }, - cardID: { + card: { getTitle: getFilterCardDisplayTitle, description: 'common.card' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_CARD, }, - taxRate: { + 'tax-rate': { getTitle: getFilterTaxRateDisplayTitle, description: 'workspace.taxes.taxRate' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_TAX_RATE, }, - expenseType: { + 'expense-type': { getTitle: getFilterExpenseDisplayTitle, description: 'search.expenseType' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_EXPENSE_TYPE, @@ -108,9 +108,9 @@ const baseFilterConfig = { }; const typeFiltersKeys: Record>> = { - [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.EXPENSE]: ['date', 'currency', 'merchant', 'description', 'reportid', 'amount', 'category', 'keyword', 'tax-rate', 'expense-type', 'tag', 'from', 'to', 'card'], + [CONST.SEARCH.DATA_TYPES.INVOICE]: ['date', 'currency', 'merchant', 'description', 'reportid', 'amount', 'category', 'keyword', 'tax-rate', 'tag', 'from', 'to', 'card'], + [CONST.SEARCH.DATA_TYPES.TRIP]: ['date', 'currency', 'merchant', 'description', 'reportid', 'amount', 'category', 'keyword', 'tax-rate', 'tag', 'from', 'to', 'card'], [CONST.SEARCH.DATA_TYPES.CHAT]: ['date', 'keyword', 'from', 'in'], }; diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx index 369a99f7072a..c734de47a01b 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx @@ -10,6 +10,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import {getAllTaxRates} from '@libs/PolicyUtils'; import * as SearchActions from '@userActions/Search'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -39,7 +40,7 @@ function SearchFiltersTaxRatePage() { return Object.entries(singlePolicyTaxRates).map(([taxRatekey, taxRate]) => ({name: taxRate.name, value: [taxRatekey]})); }, [allTaxRates, singlePolicyTaxRates]); - const updateTaxRateFilters = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({taxRate: values}), []); + const updateTaxRateFilters = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({[CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE]: values}), []); return ( Date: Wed, 6 Nov 2024 15:51:55 -0700 Subject: [PATCH 4/5] update some filters --- src/libs/SearchParser/searchParser.peggy | 4 ++-- .../SearchAdvancedFiltersPage/SearchFiltersCardPage.tsx | 5 +++-- .../SearchFiltersExpenseTypePage.tsx | 5 +++-- .../SearchAdvancedFiltersPage/SearchFiltersTaxRatePage.tsx | 5 +++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libs/SearchParser/searchParser.peggy b/src/libs/SearchParser/searchParser.peggy index 1e74284da16b..4206356568db 100644 --- a/src/libs/SearchParser/searchParser.peggy +++ b/src/libs/SearchParser/searchParser.peggy @@ -110,13 +110,13 @@ key "key" / "category" / "to" / "tax-rate" - / "dard" + / "card" / "from" / "expense-type" ) defaultKey "default key" - = @("type" / "status" / "sort-by" / "sort-order" / "workspacec") + = @("type" / "status" / "sort-by" / "sort-order" / "workspace") identifier = (","+)? parts:(quotedString / alphanumeric)|1.., ","+| empty:(","+)? { diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCardPage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCardPage.tsx index 67c8a6c9e09e..abd6d839ce61 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCardPage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersCardPage.tsx @@ -16,6 +16,7 @@ import Navigation from '@navigation/Navigation'; import * as SearchActions from '@userActions/Search'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm'; function SearchFiltersCardPage() { const styles = useThemeStyles(); @@ -23,7 +24,7 @@ function SearchFiltersCardPage() { const [cardList] = useOnyx(ONYXKEYS.CARD_LIST); const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); - const currentCards = searchAdvancedFiltersForm?.cardID; + const currentCards = searchAdvancedFiltersForm?.[FILTER_KEYS.CARD_ID]; const [newCards, setNewCards] = useState(currentCards ?? []); const sections = useMemo(() => { @@ -52,7 +53,7 @@ function SearchFiltersCardPage() { const handleConfirmSelection = useCallback(() => { SearchActions.updateAdvancedFilters({ - cardID: newCards, + [FILTER_KEYS.CARD_ID]: newCards, }); Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS); diff --git a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExpenseTypePage.tsx b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExpenseTypePage.tsx index f0e90912302d..d68c478bb92e 100644 --- a/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExpenseTypePage.tsx +++ b/src/pages/Search/SearchAdvancedFiltersPage/SearchFiltersExpenseTypePage.tsx @@ -13,6 +13,7 @@ import * as SearchActions from '@userActions/Search'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import FILTER_KEYS from '@src/types/form/SearchAdvancedFiltersForm'; function SearchFiltersExpenseTypePage() { const styles = useThemeStyles(); @@ -21,7 +22,7 @@ function SearchFiltersExpenseTypePage() { const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); const initiallySelectedItems = useMemo( () => - searchAdvancedFiltersForm?.expenseType + searchAdvancedFiltersForm?.[FILTER_KEYS.EXPENSE_TYPE] ?.filter((expenseType) => Object.values(CONST.SEARCH.TRANSACTION_TYPE).includes(expenseType as ValueOf)) .map((expenseType) => { const expenseTypeName = translate(getExpenseTypeTranslationKey(expenseType as ValueOf)); @@ -38,7 +39,7 @@ function SearchFiltersExpenseTypePage() { }); }, [allExpenseTypes, translate]); - const updateExpenseTypeFilter = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({expenseType: values}), []); + const updateExpenseTypeFilter = useCallback((values: string[]) => SearchActions.updateAdvancedFilters({[CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE]: values}), []); return ( { - searchAdvancedFiltersForm?.taxRate?.forEach((taxRateKey) => { + searchAdvancedFiltersForm?.[FILTER_KEYS.TAX_RATE]?.forEach((taxRateKey) => { if (!taxRateKeys.includes(taxRateKey) || selectedTaxesItems.some((item) => item.name === taxRateName)) { return; } selectedTaxesItems.push({name: taxRateName, value: taxRateKeys}); }); }); - const policyID = searchAdvancedFiltersForm?.policyID ?? '-1'; + const policyID = searchAdvancedFiltersForm?.[FILTER_KEYS.POLICY_ID] ?? '-1'; const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); const singlePolicyTaxRates = policy?.taxRates?.taxes; From 8f55960354f2b5e95710b8f6e6d6247dc347328e Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 6 Nov 2024 16:21:19 -0700 Subject: [PATCH 5/5] update variables --- src/components/Search/types.ts | 6 ++--- src/libs/SearchQueryUtils.ts | 22 ++++++++-------- src/pages/Search/AdvancedSearchFilters.tsx | 30 +++++++++++----------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/components/Search/types.ts b/src/components/Search/types.ts index d5be896c1c50..1481a9bdf077 100644 --- a/src/components/Search/types.ts +++ b/src/components/Search/types.ts @@ -68,10 +68,10 @@ type SearchQueryString = string; type SearchQueryAST = { type: SearchDataTypes; status: SearchStatus; - sortBy: SearchColumnType; - sortOrder: SortOrder; + 'sort-by': SearchColumnType; + 'sort-order': SortOrder; filters: ASTNode; - policyID?: string; + workspace?: string; }; type SearchQueryJSON = { diff --git a/src/libs/SearchQueryUtils.ts b/src/libs/SearchQueryUtils.ts index c84e42704fb9..819772cae8a5 100644 --- a/src/libs/SearchQueryUtils.ts +++ b/src/libs/SearchQueryUtils.ts @@ -218,13 +218,13 @@ function findIDFromDisplayValue(filterName: ValueOf { filter.filters.sort((a, b) => localeCompare(a.value.toString(), b.value.toString())); @@ -301,7 +301,7 @@ function buildSearchQueryString(queryJSON?: SearchQueryJSON) { */ function buildQueryStringFromFilterFormValues(filterValues: Partial) { // We separate type and status filters from other filters to maintain hashes consistency for saved searches - const {type, status, policyID, ...otherFilters} = filterValues; + const {type, status, workspace, ...otherFilters} = filterValues; const filtersString: string[] = []; filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${CONST.SEARCH.TABLE_COLUMNS.DATE}`); @@ -317,8 +317,8 @@ function buildQueryStringFromFilterFormValues(filterValues: Partial; - const policyID = queryJSON.policyID; + const policyID = queryJSON.workspace; for (const queryFilter of filters) { const filterKey = queryFilter.key; const filterList = queryFilter.filters; @@ -471,8 +471,8 @@ function buildFilterFormValuesFromQuery( const [statusKey] = Object.entries(CONST.SEARCH.STATUS).find(([, value]) => Object.values(value).includes(queryJSON.status)) ?? []; filtersForm[FILTER_KEYS.STATUS] = typeKey === statusKey ? queryJSON.status : CONST.SEARCH.STATUS.EXPENSE.ALL; - if (queryJSON.policyID) { - filtersForm[FILTER_KEYS.POLICY_ID] = queryJSON.policyID; + if (queryJSON.workspace) { + filtersForm[FILTER_KEYS.POLICY_ID] = queryJSON.workspace; } return filtersForm; @@ -486,7 +486,7 @@ function buildFilterFormValuesFromQuery( * however there are several places in the app (related to WorkspaceSwitcher) that will accept only a single policyID. */ function getPolicyIDFromSearchQuery(queryJSON: SearchQueryJSON) { - const policyIDFilter = queryJSON.policyID; + const policyIDFilter = queryJSON.workspace; if (!policyIDFilter) { return; diff --git a/src/pages/Search/AdvancedSearchFilters.tsx b/src/pages/Search/AdvancedSearchFilters.tsx index 7ae75fa879a3..1ef37f23a026 100644 --- a/src/pages/Search/AdvancedSearchFilters.tsx +++ b/src/pages/Search/AdvancedSearchFilters.tsx @@ -30,77 +30,77 @@ import type {SearchAdvancedFiltersForm} from '@src/types/form'; import type {CardList, PersonalDetailsList, Report} from '@src/types/onyx'; const baseFilterConfig = { - date: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.DATE]: { getTitle: getFilterDisplayTitle, description: 'common.date' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_DATE, }, - currency: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.CURRENCY]: { getTitle: getFilterDisplayTitle, description: 'common.currency' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_CURRENCY, }, - merchant: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.MERCHANT]: { getTitle: getFilterDisplayTitle, description: 'common.merchant' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_MERCHANT, }, - description: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.DESCRIPTION]: { getTitle: getFilterDisplayTitle, description: 'common.description' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_DESCRIPTION, }, - reportid: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.REPORT_ID]: { getTitle: getFilterDisplayTitle, description: 'common.reportID' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_REPORT_ID, }, - amount: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.AMOUNT]: { getTitle: getFilterDisplayTitle, description: 'common.total' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_AMOUNT, }, - category: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY]: { getTitle: getFilterDisplayTitle, description: 'common.category' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_CATEGORY, }, - keyword: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.KEYWORD]: { getTitle: getFilterDisplayTitle, description: 'search.filters.hasKeywords' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_KEYWORD, }, - card: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID]: { getTitle: getFilterCardDisplayTitle, description: 'common.card' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_CARD, }, - 'tax-rate': { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.TAX_RATE]: { getTitle: getFilterTaxRateDisplayTitle, description: 'workspace.taxes.taxRate' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_TAX_RATE, }, - 'expense-type': { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.EXPENSE_TYPE]: { getTitle: getFilterExpenseDisplayTitle, description: 'search.expenseType' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_EXPENSE_TYPE, }, - tag: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.TAG]: { getTitle: getFilterDisplayTitle, description: 'common.tag' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_TAG, }, - from: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM]: { getTitle: getFilterParticipantDisplayTitle, description: 'common.from' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_FROM, }, - to: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.TO]: { getTitle: getFilterParticipantDisplayTitle, description: 'common.to' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_TO, }, - in: { + [CONST.SEARCH.SYNTAX_FILTER_KEYS.IN]: { getTitle: getFilterInDisplayTitle, description: 'common.in' as const, route: ROUTES.SEARCH_ADVANCED_FILTERS_IN,