Skip to content

Commit 8ce880f

Browse files
authored
Merge pull request Expensify#75923 from ShridharGoel/advanceFilter
Populate advance filter amounts for negative expenses
2 parents 8f6de1c + 600f6e9 commit 8ce880f

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/components/Search/SearchFiltersAmountBase.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ function SearchFiltersAmountBase({title, filterKey, testID}: {title: Translation
222222
role={CONST.ROLE.PRESENTATION}
223223
ref={inputCallbackRef}
224224
inputMode={CONST.INPUT_MODE.DECIMAL}
225+
shouldAllowNegative
225226
autoFocus
226227
uncontrolled
227228
/>

src/libs/SearchQueryUtils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,19 +819,19 @@ function buildFilterFormValuesFromQuery(
819819
// backend amount is an integer and is 2 digits longer than frontend amount
820820
filtersForm[equalToKey] =
821821
filterList
822-
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2))
822+
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2, true))
823823
?.value.toString() ?? filtersForm[equalToKey];
824824
filtersForm[lessThanKey] =
825825
filterList
826-
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.LOWER_THAN && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2))
826+
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.LOWER_THAN && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2, true))
827827
?.value.toString() ?? filtersForm[lessThanKey];
828828
filtersForm[greaterThanKey] =
829829
filterList
830-
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.GREATER_THAN && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2))
830+
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.GREATER_THAN && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2, true))
831831
?.value.toString() ?? filtersForm[greaterThanKey];
832832
filtersForm[negatedKey] =
833833
filterList
834-
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.NOT_EQUAL_TO && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2))
834+
.find((filter) => filter.operator === CONST.SEARCH.SYNTAX_OPERATORS.NOT_EQUAL_TO && validateAmount(filter.value.toString(), 0, CONST.IOU.AMOUNT_MAX_LENGTH + 2, true))
835835
?.value.toString() ?? filtersForm[negatedKey];
836836
}
837837

tests/unit/Search/SearchQueryUtilsTest.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,33 @@ describe('SearchQueryUtils', () => {
335335
action: undefined,
336336
});
337337
});
338+
339+
test('parses negative backend amounts into filter form values', () => {
340+
const policyCategories = {};
341+
const policyTags = {};
342+
const currencyList = {};
343+
const personalDetails = {};
344+
const cardList = {};
345+
const reports = {};
346+
const taxRates = {};
347+
348+
const queryString = 'sortBy:date sortOrder:desc type:expense amount<-12345 amount>-67890 amount:-54321';
349+
const queryJSON = buildSearchQueryJSON(queryString);
350+
351+
if (!queryJSON) {
352+
throw new Error('Failed to parse query string');
353+
}
354+
355+
const result = buildFilterFormValuesFromQuery(queryJSON, policyCategories, policyTags, currencyList, personalDetails, cardList, reports, taxRates);
356+
357+
expect(result).toEqual({
358+
type: 'expense',
359+
status: CONST.SEARCH.STATUS.EXPENSE.ALL,
360+
amountLessThan: '-12345',
361+
amountGreaterThan: '-67890',
362+
amountEqualTo: '-54321',
363+
});
364+
});
338365
});
339366

340367
describe('shouldHighlight', () => {

0 commit comments

Comments
 (0)