Skip to content

Commit

Permalink
update some filters
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Nov 6, 2024
1 parent 95d29e9 commit 13f03dc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/libs/SearchParser/searchParser.peggy
Original file line number Diff line number Diff line change
Expand Up @@ -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:(","+)? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ 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();
const {translate} = useLocalize();

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(() => {
Expand Down Expand Up @@ -52,7 +53,7 @@ function SearchFiltersCardPage() {

const handleConfirmSelection = useCallback(() => {
SearchActions.updateAdvancedFilters({
cardID: newCards,
[FILTER_KEYS.CARD_ID]: newCards,
});

Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<typeof CONST.SEARCH.TRANSACTION_TYPE>))
.map((expenseType) => {
const expenseTypeName = translate(getExpenseTypeTranslationKey(expenseType as ValueOf<typeof CONST.SEARCH.TRANSACTION_TYPE>));
Expand All @@ -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 (
<ScreenWrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 SearchFiltersTaxRatePage() {
const styles = useThemeStyles();
Expand All @@ -22,14 +23,14 @@ function SearchFiltersTaxRatePage() {
const allTaxRates = getAllTaxRates();
const selectedTaxesItems: SearchMultipleSelectionPickerItem[] = [];
Object.entries(allTaxRates).forEach(([taxRateName, taxRateKeys]) => {
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;

Expand Down

0 comments on commit 13f03dc

Please sign in to comment.