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

Always show categories, tags and taxes columns #43206

Merged
merged 2 commits into from
Jun 6, 2024
Merged
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
6 changes: 3 additions & 3 deletions src/components/SelectionList/SearchTableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ const SearchColumns: SearchColumnConfig[] = [
{
columnName: CONST.SEARCH_TABLE_COLUMNS.CATEGORY,
translationKey: 'common.category',
shouldShow: (data: OnyxTypes.SearchResults['data']) => SearchUtils.getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.CATEGORY),
shouldShow: () => true,
},
{
columnName: CONST.SEARCH_TABLE_COLUMNS.TAG,
translationKey: 'common.tag',
shouldShow: (data: OnyxTypes.SearchResults['data']) => SearchUtils.getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.TAG),
shouldShow: () => true,
},
{
columnName: CONST.SEARCH_TABLE_COLUMNS.TAX_AMOUNT,
translationKey: 'common.tax',
shouldShow: (data: OnyxTypes.SearchResults['data']) => SearchUtils.getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.TAX_AMOUNT),
shouldShow: () => true,
isColumnSortable: false,
},
{
Expand Down
24 changes: 7 additions & 17 deletions src/libs/SearchUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,8 @@ function getShouldShowMerchant(data: OnyxTypes.SearchResults['data']): boolean {
});
}

function getShouldShowColumn(data: OnyxTypes.SearchResults['data'], columnName: ValueOf<typeof CONST.SEARCH_TABLE_COLUMNS>) {
return Object.values(data).some((item) => !!item[columnName]);
}

function getTransactionsSections(data: OnyxTypes.SearchResults['data']): TransactionListItemType[] {
const shouldShowMerchant = getShouldShowMerchant(data);
const shouldShowCategory = getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.CATEGORY);
const shouldShowTag = getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.TAG);
const shouldShowTax = getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.TAX_AMOUNT);

return Object.entries(data)
.filter(([key]) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION))
Expand All @@ -107,19 +100,16 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data']): Transac
formattedMerchant,
date,
shouldShowMerchant,
shouldShowCategory,
shouldShowTag,
shouldShowTax,
shouldShowCategory: true,
shouldShowTag: true,
shouldShowTax: true,
keyForList: transactionItem.transactionID,
};
});
}

function getReportSections(data: OnyxTypes.SearchResults['data']): ReportListItemType[] {
const shouldShowMerchant = getShouldShowMerchant(data);
const shouldShowCategory = getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.CATEGORY);
const shouldShowTag = getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.TAG);
const shouldShowTax = getShouldShowColumn(data, CONST.SEARCH_TABLE_COLUMNS.TAX_AMOUNT);

const reportIDToTransactions: Record<string, ReportListItemType> = {};
for (const key in data) {
Expand Down Expand Up @@ -152,9 +142,9 @@ function getReportSections(data: OnyxTypes.SearchResults['data']): ReportListIte
formattedMerchant,
date,
shouldShowMerchant,
shouldShowCategory,
shouldShowTag,
shouldShowTax,
shouldShowCategory: true,
shouldShowTag: true,
shouldShowTax: true,
keyForList: transactionItem.transactionID,
};
if (reportIDToTransactions[reportKey]?.transactions) {
Expand Down Expand Up @@ -240,5 +230,5 @@ function getSearchParams() {
return topmostCentralPaneRoute?.params as CentralPaneNavigatorParamList['Search_Central_Pane'];
}

export {getListItem, getQueryHash, getSections, getSortedSections, getShouldShowColumn, getShouldShowMerchant, getSearchType, getSearchParams};
export {getListItem, getQueryHash, getSections, getSortedSections, getShouldShowMerchant, getSearchType, getSearchParams};
export type {SearchColumnType, SortOrder};
Loading