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

Rename search filters #51996

Closed
wants to merge 5 commits into from
Closed
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
14 changes: 7 additions & 7 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5913,24 +5913,24 @@ 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',
FROM: 'from',
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',
},
Expand Down
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions src/components/Search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
16 changes: 8 additions & 8 deletions src/libs/SearchParser/autocompleteParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "!=";
Expand All @@ -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");
Expand Down Expand Up @@ -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); }
Expand All @@ -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); }
Expand Down
4 changes: 2 additions & 2 deletions src/libs/SearchParser/autocompleteParser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ autocompleteKey "key"
/ "tag"
/ "category"
/ "to"
/ "taxRate"
/ "tax-rate"
/ "from"
/ "expenseType"
/ "expense-type"
/ "type"
/ "status"
)
Expand Down
52 changes: 26 additions & 26 deletions src/libs/SearchParser/searchParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ">=";
Expand All @@ -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);
Expand Down Expand Up @@ -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); }
Expand All @@ -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); }
Expand Down Expand Up @@ -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); }
Expand Down
10 changes: 5 additions & 5 deletions src/libs/SearchParser/searchParser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ key "key"
/ "amount"
/ "merchant"
/ "description"
/ "reportID"
/ "reportid"
/ "keyword"
/ "in"
/ "currency"
/ "tag"
/ "category"
/ "to"
/ "taxRate"
/ "cardID"
/ "tax-rate"
/ "card"
/ "from"
/ "expenseType"
/ "expense-type"
)

defaultKey "default key"
= @("type" / "status" / "sortBy" / "sortOrder" / "policyID")
= @("type" / "status" / "sort-by" / "sort-order" / "workspace")

identifier
= (","+)? parts:(quotedString / alphanumeric)|1.., ","+| empty:(","+)? {
Expand Down
22 changes: 11 additions & 11 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ function findIDFromDisplayValue(filterName: ValueOf<typeof CONST.SEARCH.SYNTAX_F
*/
function getQueryHash(query: SearchQueryJSON): number {
let orderedQuery = '';
if (query.policyID) {
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID}:${query.policyID} `;
if (query.workspace) {
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID}:${query.workspace} `;
}
orderedQuery += `${CONST.SEARCH.SYNTAX_ROOT_KEYS.TYPE}:${query.type}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}:${query.status}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${query.sortBy}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}:${query.sortOrder}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_BY}:${query['sort-by']}`;
orderedQuery += ` ${CONST.SEARCH.SYNTAX_ROOT_KEYS.SORT_ORDER}:${query['sort-order']}`;

query.flatFilters.forEach((filter) => {
filter.filters.sort((a, b) => localeCompare(a.value.toString(), b.value.toString()));
Expand Down Expand Up @@ -301,7 +301,7 @@ function buildSearchQueryString(queryJSON?: SearchQueryJSON) {
*/
function buildQueryStringFromFilterFormValues(filterValues: Partial<SearchAdvancedFiltersForm>) {
// 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}`);
Expand All @@ -317,8 +317,8 @@ function buildQueryStringFromFilterFormValues(filterValues: Partial<SearchAdvanc
filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.STATUS}:${sanitizedStatus}`);
}

if (policyID) {
const sanitizedPolicyID = sanitizeSearchValue(policyID);
if (workspace) {
const sanitizedPolicyID = sanitizeSearchValue(workspace);
filtersString.push(`${CONST.SEARCH.SYNTAX_ROOT_KEYS.POLICY_ID}:${sanitizedPolicyID}`);
}

Expand Down Expand Up @@ -389,7 +389,7 @@ function buildFilterFormValuesFromQuery(
) {
const filters = queryJSON.flatFilters;
const filtersForm = {} as Partial<SearchAdvancedFiltersForm>;
const policyID = queryJSON.policyID;
const policyID = queryJSON.workspace;
for (const queryFilter of filters) {
const filterKey = queryFilter.key;
const filterList = queryFilter.filters;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading
Loading