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

Add ability to bulk select cards from the same bank in the Card filter #53389

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
951f85b
add expensify card feeds to card filter
SzymczakJ Dec 2, 2024
4113519
add company card feeds to card filter
SzymczakJ Dec 2, 2024
e0d5bf8
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Dec 3, 2024
9336e8f
add handling of domain feeds
SzymczakJ Dec 5, 2024
defc543
add search input
SzymczakJ Dec 5, 2024
98b3512
improve naming
SzymczakJ Dec 5, 2024
a5545b7
fix typescript
SzymczakJ Dec 5, 2024
6ebe579
fix typescript
SzymczakJ Dec 5, 2024
a1ae60e
add lowercase filtring
SzymczakJ Dec 6, 2024
d9f0e8a
wrap workspaceFeeds data in useMemo
SzymczakJ Dec 6, 2024
42ecedc
fix filter not appearing bug
SzymczakJ Dec 6, 2024
93e23ca
fix export bug
SzymczakJ Dec 6, 2024
00f3ad8
fix linter
SzymczakJ Dec 6, 2024
cfb2417
fix PR comments
SzymczakJ Dec 9, 2024
6f8efac
fix wrong card names bug
SzymczakJ Dec 9, 2024
bd92551
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Dec 10, 2024
5d93a9d
add tests to card filter data generation
SzymczakJ Dec 11, 2024
ab009cc
fix buildSubstitutionsMapTest tests
SzymczakJ Dec 11, 2024
e9cb9da
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Dec 11, 2024
cec56f7
clean up Search tests
SzymczakJ Dec 11, 2024
9068aa8
delete redundant comments
SzymczakJ Dec 11, 2024
313bb46
fix PR comments
SzymczakJ Dec 11, 2024
0f274f9
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Dec 17, 2024
a48f976
fix typo
SzymczakJ Dec 17, 2024
5f21294
fix linter warnings
SzymczakJ Dec 17, 2024
b4e5aab
add api call
SzymczakJ Dec 17, 2024
e18af2a
fix linter warning
SzymczakJ Dec 17, 2024
fc3f071
fix linter
SzymczakJ Dec 17, 2024
947d918
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Dec 18, 2024
6ad3f86
fix PR comments
SzymczakJ Dec 19, 2024
d340930
fix PR comments
SzymczakJ Dec 20, 2024
719a972
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Jan 7, 2025
306f6c6
fix card filter SelectionList selection behaviour
SzymczakJ Jan 7, 2025
415ef30
filter out unissued cards in card filter page
SzymczakJ Jan 7, 2025
00dc930
include lastFourPan in card filter search
SzymczakJ Jan 7, 2025
a49beaf
change cardList item design
SzymczakJ Jan 8, 2025
4954b15
fix tests and eslint
SzymczakJ Jan 8, 2025
2a8fe1d
Merge branch 'main' into @szymczak/add-feeds-to-card-filter
SzymczakJ Jan 8, 2025
79a5c3d
fix typescript error
SzymczakJ Jan 8, 2025
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
27 changes: 18 additions & 9 deletions src/components/Search/SearchPageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as SearchActions from '@libs/actions/Search';
import * as CardUtils from '@libs/CardUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getAllTaxRates} from '@libs/PolicyUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
Expand Down Expand Up @@ -47,7 +48,9 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
const personalDetails = usePersonalDetails();
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const taxRates = getAllTaxRates();
const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const [userCardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const [workspaceCardFeeds = {}] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`);
SzymczakJ marked this conversation as resolved.
Show resolved Hide resolved
const allCards = useMemo(() => CardUtils.mergeCardListWithWorkspaceFeeds(workspaceCardFeeds, userCardList), [userCardList, workspaceCardFeeds]);
const [currencyList = {}] = useOnyx(ONYXKEYS.CURRENCY_LIST);
const [policyCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES);
const [policyTagsLists] = useOnyx(ONYXKEYS.COLLECTION.POLICY_TAGS);
Expand Down Expand Up @@ -181,7 +184,13 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {

const reportIDList = selectedReports?.filter((report) => !!report).map((report) => report.reportID) ?? [];
SearchActions.exportSearchItemsToCSV(
{query: status, jsonQuery: JSON.stringify(queryJSON), reportIDList, transactionIDList: selectedTransactionsKeys, policyIDs: [activeWorkspaceID ?? '']},
{
query: status,
jsonQuery: JSON.stringify(queryJSON),
reportIDList,
transactionIDList: selectedTransactionsKeys,
policyIDs: activeWorkspaceID ? [activeWorkspaceID] : [''],
},
() => {
setIsDownloadErrorModalVisible(true);
},
Expand Down Expand Up @@ -265,20 +274,20 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {

return options;
}, [
queryJSON,
status,
selectedTransactionsKeys,
selectedTransactions,
isOffline,
selectedReports,
translate,
hash,
lastPaymentMethods,
status,
queryJSON,
activeWorkspaceID,
theme.icon,
styles.colorMuted,
styles.fontWeightNormal,
isOffline,
activeWorkspaceID,
selectedReports,
styles.textWrap,
lastPaymentMethods,
]);

if (shouldUseNarrowLayout) {
Expand Down Expand Up @@ -326,7 +335,7 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
}

const onFiltersButtonPress = () => {
const filterFormValues = SearchQueryUtils.buildFilterFormValuesFromQuery(queryJSON, policyCategories, policyTagsLists, currencyList, personalDetails, cardList, reports, taxRates);
const filterFormValues = SearchQueryUtils.buildFilterFormValuesFromQuery(queryJSON, policyCategories, policyTagsLists, currencyList, personalDetails, allCards, reports, taxRates);
SearchActions.updateAdvancedFilters(filterFormValues);

Navigation.navigate(ROUTES.SEARCH_ADVANCED_FILTERS);
Expand Down
10 changes: 7 additions & 3 deletions src/components/Search/SearchPageHeaderInput.tsx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Console error:

Screenshot 2024-12-19 at 9 22 14 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see such error, also everything that could cause "update max depth exceeded" seems wrapped in useMemo, so I don't see a case when this error pops up. Do you have some specific steps of reproduction for this error?
Screenshot 2024-12-20 at 11 52 47

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as SearchActions from '@libs/actions/Search';
import * as CardUtils from '@libs/CardUtils';
import Navigation from '@libs/Navigation/Navigation';
import {getAllTaxRates} from '@libs/PolicyUtils';
import type {OptionData} from '@libs/ReportUtils';
Expand Down Expand Up @@ -71,10 +72,13 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps
const personalDetails = usePersonalDetails();
const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT);
const taxRates = useMemo(() => getAllTaxRates(), []);
const [userCardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const [workspaceCardFeeds = {}] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`);
const allCards = useMemo(() => CardUtils.mergeCardListWithWorkspaceFeeds(workspaceCardFeeds, userCardList), [userCardList, workspaceCardFeeds]);

const {type, inputQuery: originalInputQuery} = queryJSON;
const isCannedQuery = SearchQueryUtils.isCannedSearchQuery(queryJSON);
const queryText = SearchQueryUtils.buildUserReadableQueryString(queryJSON, personalDetails, reports, taxRates);
const queryText = SearchQueryUtils.buildUserReadableQueryString(queryJSON, personalDetails, reports, taxRates, allCards);
const headerText = isCannedQuery ? translate(getHeaderContent(type).titleText) : '';

// The actual input text that the user sees
Expand Down Expand Up @@ -107,9 +111,9 @@ function SearchPageHeaderInput({queryJSON, children}: SearchPageHeaderInputProps
}, [queryText]);

useEffect(() => {
const substitutionsMap = buildSubstitutionsMap(originalInputQuery, personalDetails, reports, taxRates);
const substitutionsMap = buildSubstitutionsMap(originalInputQuery, personalDetails, reports, taxRates, allCards);
setAutocompleteSubstitutions(substitutionsMap);
}, [originalInputQuery, personalDetails, reports, taxRates]);
}, [allCards, originalInputQuery, personalDetails, reports, taxRates]);

const onSearchQueryChange = useCallback(
(userQuery: string) => {
Expand Down
14 changes: 9 additions & 5 deletions src/components/Search/SearchRouter/SearchRouterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ function SearchRouterList(
const statusAutocompleteList = Object.values({...CONST.SEARCH.STATUS.TRIP, ...CONST.SEARCH.STATUS.INVOICE, ...CONST.SEARCH.STATUS.CHAT, ...CONST.SEARCH.STATUS.TRIP});
const expenseTypes = Object.values(CONST.SEARCH.TRANSACTION_TYPE);

const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const cardAutocompleteList = Object.values(cardList);
const [userCardList = {}] = useOnyx(ONYXKEYS.CARD_LIST);
const [workspaceCardFeeds = {}] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`);
const allCards = useMemo(() => CardUtils.mergeCardListWithWorkspaceFeeds(workspaceCardFeeds, userCardList), [userCardList, workspaceCardFeeds]);
const cardAutocompleteList = Object.values(allCards);

const participantsAutocompleteList = useMemo(() => {
if (!areOptionsInitialized) {
return [];
Expand Down Expand Up @@ -179,7 +182,7 @@ function SearchRouterList(
if (currentUser) {
autocompleteOptions.push({
name: currentUser.displayName ?? Str.removeSMSDomain(currentUser.login ?? ''),
accountID: currentUser.accountID?.toString() ?? '-1',
accountID: currentUser.accountID.toString(),
});
}

Expand Down Expand Up @@ -341,7 +344,7 @@ function SearchRouterList(

return filteredCards.map((card) => ({
filterKey: CONST.SEARCH.SEARCH_USER_FRIENDLY_KEYS.CARD_ID,
text: CardUtils.getCardDescription(card.cardID),
text: CardUtils.getCardDescription(card.cardID, allCards),
autocompleteID: card.cardID.toString(),
mapKey: CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID,
}));
Expand All @@ -365,6 +368,7 @@ function SearchRouterList(
statusAutocompleteList,
expenseTypes,
cardAutocompleteList,
allCards,
]);

const sortedRecentSearches = useMemo(() => {
Expand All @@ -374,7 +378,7 @@ function SearchRouterList(
const recentSearchesData = sortedRecentSearches?.slice(0, 5).map(({query, timestamp}) => {
const searchQueryJSON = SearchQueryUtils.buildSearchQueryJSON(query);
return {
text: searchQueryJSON ? SearchQueryUtils.buildUserReadableQueryString(searchQueryJSON, personalDetails, reports, taxRates) : query,
text: searchQueryJSON ? SearchQueryUtils.buildUserReadableQueryString(searchQueryJSON, personalDetails, reports, taxRates, allCards) : query,
singleIcon: Expensicons.History,
searchQuery: query,
keyForList: timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function buildSubstitutionsMap(
personalDetails: OnyxTypes.PersonalDetailsList | undefined,
reports: OnyxCollection<OnyxTypes.Report>,
allTaxRates: Record<string, string[]>,
cardList: OnyxTypes.CardList,
): SubstitutionMap {
const parsedQuery = parser.parse(query) as {ranges: SearchAutocompleteQueryRange[]};

Expand Down Expand Up @@ -61,7 +62,7 @@ function buildSubstitutionsMap(
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN ||
filterKey === CONST.SEARCH.SYNTAX_FILTER_KEYS.CARD_ID
) {
const displayValue = SearchQueryUtils.getFilterDisplayValue(filterKey, filterValue, personalDetails, reports);
const displayValue = SearchQueryUtils.getFilterDisplayValue(filterKey, filterValue, personalDetails, reports, cardList);

// If displayValue === filterValue, then it means there is nothing to substitute, so we don't add any key to map
if (displayValue !== filterValue) {
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/usePaymentMethodState/types.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type {ViewStyle} from 'react-native';
import type {StyleProp, ViewStyle} from 'react-native';
import type {AccountData} from '@src/types/onyx';
import type IconAsset from '@src/types/utils/IconAsset';

type FormattedSelectedPaymentMethodIcon = {
icon: IconAsset;
iconHeight?: number;
iconWidth?: number;
iconStyles?: ViewStyle[];
iconStyles?: StyleProp<ViewStyle>;
iconSize?: number;
};

Expand Down
7 changes: 7 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4599,6 +4599,13 @@ const translations = {
greaterThan: ({amount}: OptionalParam<RequestAmountParams> = {}) => `Greater than ${amount ?? ''}`,
between: ({greaterThan, lessThan}: FiltersAmountBetweenParams) => `Between ${greaterThan} and ${lessThan}`,
},
card: {
expensify: 'Expensify',
individualCards: 'Individual cards',
cardFeeds: 'Card feeds',
cardFeedName: ({cardFeedBankName, cardFeedLabel}: {cardFeedBankName: string; cardFeedLabel?: string}) =>
`All ${cardFeedBankName}${cardFeedLabel ? ` - ${cardFeedLabel}` : ''}`,
},
current: 'Current',
past: 'Past',
submitted: 'Submitted',
Expand Down
7 changes: 7 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4643,6 +4643,13 @@ const translations = {
link: 'Enlace',
pinned: 'Fijado',
unread: 'No leído',
card: {
expensify: 'Expensify',
individualCards: 'Tarjetas individuales',
cardFeeds: 'Flujos de tarjetas',
cardFeedName: ({cardFeedBankName, cardFeedLabel}: {cardFeedBankName: string; cardFeedLabel?: string}) =>
`Todo ${cardFeedBankName}${cardFeedLabel ? ` - ${cardFeedLabel}` : ''}`,
},
amount: {
lessThan: ({amount}: OptionalParam<RequestAmountParams> = {}) => `Menos de ${amount ?? ''}`,
greaterThan: ({amount}: OptionalParam<RequestAmountParams> = {}) => `Más que ${amount ?? ''}`,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/ExportSearchItemsToCSVParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type ExportSearchItemsToCSVParams = {
jsonQuery: SearchQueryString;
reportIDList: string[];
transactionIDList: string[];
policyIDs: string[];
policyIDs?: string[];
};

export default ExportSearchItemsToCSVParams;
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ const READ_COMMANDS = {
OPEN_POLICY_COMPANY_CARDS_FEED: 'OpenPolicyCompanyCardsFeed',
OPEN_POLICY_COMPANY_CARDS_PAGE: 'OpenPolicyCompanyCardsPage',
OPEN_POLICY_EDIT_CARD_LIMIT_TYPE_PAGE: 'OpenPolicyEditCardLimitTypePage',
OPEN_SEARCH_FILTERS_CARD_PAGE: 'OpenSearchFiltersCardPage',
OPEN_WORKSPACE_INVITE_PAGE: 'OpenWorkspaceInvitePage',
OPEN_DRAFT_WORKSPACE_REQUEST: 'OpenDraftWorkspaceRequest',
OPEN_POLICY_WORKFLOWS_PAGE: 'OpenPolicyWorkflowsPage',
Expand Down Expand Up @@ -1012,6 +1013,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_POLICY_COMPANY_CARDS_PAGE]: Parameters.OpenPolicyExpensifyCardsPageParams;
[READ_COMMANDS.OPEN_POLICY_COMPANY_CARDS_FEED]: Parameters.OpenPolicyCompanyCardsFeedParams;
[READ_COMMANDS.OPEN_POLICY_EDIT_CARD_LIMIT_TYPE_PAGE]: Parameters.OpenPolicyEditCardLimitTypePageParams;
[READ_COMMANDS.OPEN_SEARCH_FILTERS_CARD_PAGE]: null;
[READ_COMMANDS.OPEN_POLICY_PROFILE_PAGE]: Parameters.OpenPolicyProfilePageParams;
[READ_COMMANDS.OPEN_POLICY_INITIAL_PAGE]: Parameters.OpenPolicyInitialPageParams;
[READ_COMMANDS.OPEN_SUBSCRIPTION_PAGE]: null;
Expand Down
30 changes: 25 additions & 5 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,34 @@ function isCorporateCard(cardID: number) {
* @param cardID
* @returns string in format %<bank> - <lastFourPAN || Not Activated>%.
*/
function getCardDescription(cardID?: number) {
function getCardDescription(cardID?: number, cards: CardList = allCards) {
if (!cardID) {
return '';
}
const card = allCards[cardID];
const card = cards[cardID];
if (!card) {
return '';
}
const cardDescriptor = card.state === CONST.EXPENSIFY_CARD.STATE.NOT_ACTIVATED ? Localize.translateLocal('cardTransactions.notActivated') : card.lastFourPAN;
return cardDescriptor ? `${card.bank} - ${cardDescriptor}` : `${card.bank}`;
const humanReadableBankName = card.bank === CONST.EXPENSIFY_CARD.BANK ? CONST.EXPENSIFY_CARD.BANK : getCardFeedName(card.bank as CompanyCardFeed);
return cardDescriptor ? `${humanReadableBankName} - ${cardDescriptor}` : `${humanReadableBankName}`;
}

function isCard(item: Card | Record<string, string>): item is Card {
return typeof item === 'object' && 'cardID' in item && !!item.cardID && 'bank' in item && !!item.bank;
}

function mergeCardListWithWorkspaceFeeds(workspaceFeeds: Record<string, WorkspaceCardsList | undefined>, cardList = allCards) {
const feedCards: CardList = {...cardList};
Object.values(workspaceFeeds ?? {}).forEach((currentCardFeed) => {
Object.values(currentCardFeed ?? {}).forEach((card) => {
if (!isCard(card)) {
return;
}
feedCards[card.cardID] = card;
});
});
return feedCards;
}

/**
Expand Down Expand Up @@ -203,8 +221,8 @@ function getEligibleBankAccountsForCard(bankAccountsList: OnyxEntry<BankAccountL
function sortCardsByCardholderName(cardsList: OnyxEntry<WorkspaceCardsList>, personalDetails: OnyxEntry<PersonalDetailsList>): Card[] {
const {cardList, ...cards} = cardsList ?? {};
return Object.values(cards).sort((cardA: Card, cardB: Card) => {
const userA = personalDetails?.[cardA.accountID ?? '-1'] ?? {};
const userB = personalDetails?.[cardB.accountID ?? '-1'] ?? {};
const userA = cardA.accountID ? personalDetails?.[cardA.accountID] : {};
const userB = cardB.accountID ? personalDetails?.[cardB.accountID] : {};

const aName = PersonalDetailsUtils.getDisplayNameOrDefault(userA);
const bName = PersonalDetailsUtils.getDisplayNameOrDefault(userB);
Expand Down Expand Up @@ -415,4 +433,6 @@ export {
hasOnlyOneCardToAssign,
checkIfNewFeedConnected,
getDefaultCardName,
mergeCardListWithWorkspaceFeeds,
isCard,
};
13 changes: 10 additions & 3 deletions src/libs/SearchQueryUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,13 @@ function getPolicyIDFromSearchQuery(queryJSON: SearchQueryJSON) {
/**
* Returns the human-readable "pretty" string for a specified filter value.
*/
function getFilterDisplayValue(filterName: string, filterValue: string, personalDetails: OnyxTypes.PersonalDetailsList | undefined, reports: OnyxCollection<OnyxTypes.Report>) {
function getFilterDisplayValue(
filterName: string,
filterValue: string,
personalDetails: OnyxTypes.PersonalDetailsList | undefined,
reports: OnyxCollection<OnyxTypes.Report>,
cardList: OnyxTypes.CardList,
) {
if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM || filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.TO) {
// login can be an empty string
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand All @@ -546,7 +552,7 @@ function getFilterDisplayValue(filterName: string, filterValue: string, personal
if (Number.isNaN(cardID)) {
return filterValue;
}
return CardUtils.getCardDescription(cardID) || filterValue;
return CardUtils.getCardDescription(cardID, cardList) || filterValue;
}
if (filterName === CONST.SEARCH.SYNTAX_FILTER_KEYS.IN) {
return ReportUtils.getReportName(reports?.[`${ONYXKEYS.COLLECTION.REPORT}${filterValue}`]) || filterValue;
Expand All @@ -569,6 +575,7 @@ function buildUserReadableQueryString(
PersonalDetails: OnyxTypes.PersonalDetailsList | undefined,
reports: OnyxCollection<OnyxTypes.Report>,
taxRates: Record<string, string[]>,
cardList: OnyxTypes.CardList,
) {
const {type, status} = queryJSON;
const filters = queryJSON.flatFilters;
Expand Down Expand Up @@ -600,7 +607,7 @@ function buildUserReadableQueryString(
} else {
displayQueryFilters = queryFilter.map((filter) => ({
operator: filter.operator,
value: getFilterDisplayValue(key, filter.value.toString(), PersonalDetails, reports),
value: getFilterDisplayValue(key, filter.value.toString(), PersonalDetails, reports, cardList),
}));
}
title += buildFilterValuesString(getUserFriendlyKey(key), displayQueryFilters);
Expand Down
14 changes: 12 additions & 2 deletions src/libs/actions/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {PaymentData, SearchQueryJSON} from '@components/Search/types';
import type {ReportListItemType, TransactionListItemType} from '@components/SelectionList/types';
import * as API from '@libs/API';
import type {ExportSearchItemsToCSVParams, SubmitReportParams} from '@libs/API/parameters';
import {SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import {READ_COMMANDS, SIDE_EFFECT_REQUEST_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as ApiUtils from '@libs/ApiUtils';
import fileDownload from '@libs/fileDownload';
import enhanceParameters from '@libs/Network/enhanceParameters';
Expand Down Expand Up @@ -208,6 +208,15 @@ function deleteSavedSearch(hash: number) {
API.write(WRITE_COMMANDS.DELETE_SAVED_SEARCH, {hash}, {optimisticData, failureData, successData});
}

function openSearchFiltersCardPage() {
const optimisticData: OnyxUpdate[] = [{onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`, value: null}];
SzymczakJ marked this conversation as resolved.
Show resolved Hide resolved

const successData: OnyxUpdate[] = [{onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`, value: null}];

const failureData: OnyxUpdate[] = [{onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`, value: null}];
API.read(READ_COMMANDS.OPEN_SEARCH_FILTERS_CARD_PAGE, null, {optimisticData, successData, failureData});
}

function search({queryJSON, offset}: {queryJSON: SearchQueryJSON; offset?: number}) {
const {optimisticData, finallyData} = getOnyxLoadingData(queryJSON.hash);
const {flatFilters, ...queryJSONWithoutFlatFilters} = queryJSON;
Expand Down Expand Up @@ -334,7 +343,7 @@ function deleteMoneyRequestOnSearch(hash: number, transactionIDList: string[]) {

type Params = Record<string, ExportSearchItemsToCSVParams>;

function exportSearchItemsToCSV({query, jsonQuery, reportIDList, transactionIDList, policyIDs}: ExportSearchItemsToCSVParams, onDownloadFailed: () => void) {
function exportSearchItemsToCSV({query, jsonQuery, reportIDList, transactionIDList, policyIDs = ['']}: ExportSearchItemsToCSVParams, onDownloadFailed: () => void) {
const finalParameters = enhanceParameters(WRITE_COMMANDS.EXPORT_SEARCH_ITEMS_TO_CSV, {
query,
jsonQuery,
Expand Down Expand Up @@ -406,4 +415,5 @@ export {
approveMoneyRequestOnSearch,
handleActionButtonPress,
submitMoneyRequestOnSearch,
openSearchFiltersCardPage,
};
Loading
Loading