@@ -58,6 +58,7 @@ import type {
5858 SearchWithdrawalIDGroup ,
5959} from '@src/types/onyx/SearchResults' ;
6060import type IconAsset from '@src/types/utils/IconAsset' ;
61+ import arraysEqual from '@src/utils/arraysEqual' ;
6162import { hasSynchronizationErrorMessage } from './actions/connections' ;
6263import { canApproveIOU , canIOUBePaid , canSubmitReport , startMoneyRequest } from './actions/IOU' ;
6364import { setIsOpenConfirmNavigateExpensifyClassicModalOpen } from './actions/isOpenConfirmNavigateExpensifyClassicModal' ;
@@ -2049,21 +2050,65 @@ function getExpenseTypeTranslationKey(expenseType: ValueOf<typeof CONST.SEARCH.T
20492050 }
20502051}
20512052
2052- function getSearchColumnTranslationKey ( columnId : ValueOf < typeof CONST . SEARCH . CUSTOM_COLUMNS > ) : TranslationPaths {
2053+ function getCustomColumns ( type : SearchDataTypes ) : SearchCustomColumnIds [ ] {
2054+ // eslint-disable-next-line default-case
2055+ switch ( type ) {
2056+ case CONST . SEARCH . DATA_TYPES . EXPENSE :
2057+ return Object . values ( CONST . SEARCH . CUSTOM_COLUMNS . EXPENSE ) ;
2058+ case CONST . SEARCH . DATA_TYPES . EXPENSE_REPORT :
2059+ return Object . values ( CONST . SEARCH . CUSTOM_COLUMNS . EXPENSE_REPORT ) ;
2060+ case CONST . SEARCH . DATA_TYPES . INVOICE :
2061+ return Object . values ( CONST . SEARCH . CUSTOM_COLUMNS . INVOICE ) ;
2062+ case CONST . SEARCH . DATA_TYPES . TASK :
2063+ return Object . values ( CONST . SEARCH . CUSTOM_COLUMNS . TASK ) ;
2064+ case CONST . SEARCH . DATA_TYPES . TRIP :
2065+ return Object . values ( CONST . SEARCH . CUSTOM_COLUMNS . TRIP ) ;
2066+ case CONST . SEARCH . DATA_TYPES . CHAT :
2067+ return Object . values ( CONST . SEARCH . CUSTOM_COLUMNS . CHAT ) ;
2068+ }
2069+ }
2070+
2071+ function getCustomColumnDefault ( type : SearchDataTypes ) : SearchCustomColumnIds [ ] {
2072+ // eslint-disable-next-line default-case
2073+ switch ( type ) {
2074+ case CONST . SEARCH . DATA_TYPES . EXPENSE :
2075+ return CONST . SEARCH . DEFAULT_COLUMNS . EXPENSE ;
2076+ case CONST . SEARCH . DATA_TYPES . EXPENSE_REPORT :
2077+ return CONST . SEARCH . DEFAULT_COLUMNS . EXPENSE_REPORT ;
2078+ case CONST . SEARCH . DATA_TYPES . INVOICE :
2079+ return CONST . SEARCH . DEFAULT_COLUMNS . INVOICE ;
2080+ case CONST . SEARCH . DATA_TYPES . TASK :
2081+ return CONST . SEARCH . DEFAULT_COLUMNS . TASK ;
2082+ case CONST . SEARCH . DATA_TYPES . TRIP :
2083+ return CONST . SEARCH . DEFAULT_COLUMNS . TRIP ;
2084+ case CONST . SEARCH . DATA_TYPES . CHAT :
2085+ return CONST . SEARCH . DEFAULT_COLUMNS . CHAT ;
2086+ }
2087+ }
2088+
2089+ function getSearchColumnTranslationKey ( columnId : SearchCustomColumnIds ) : TranslationPaths {
20532090 // eslint-disable-next-line default-case
20542091 switch ( columnId ) {
2055- case CONST . SEARCH . CUSTOM_COLUMNS . DATE :
2092+ case CONST . SEARCH . TABLE_COLUMNS . DATE :
20562093 return 'common.date' ;
2057- case CONST . SEARCH . CUSTOM_COLUMNS . STATUS :
2058- return 'common.status' ;
2059- case CONST . SEARCH . CUSTOM_COLUMNS . TITLE :
2060- return 'common.title' ;
2061- case CONST . SEARCH . CUSTOM_COLUMNS . FROM :
2094+ case CONST . SEARCH . TABLE_COLUMNS . MERCHANT :
2095+ return 'common.merchant' ;
2096+ case CONST . SEARCH . TABLE_COLUMNS . FROM :
20622097 return 'common.from' ;
2063- case CONST . SEARCH . CUSTOM_COLUMNS . TO :
2098+ case CONST . SEARCH . TABLE_COLUMNS . TO :
20642099 return 'common.to' ;
2065- case CONST . SEARCH . CUSTOM_COLUMNS . ACTION :
2100+ case CONST . SEARCH . TABLE_COLUMNS . CATEGORY :
2101+ return 'common.category' ;
2102+ case CONST . SEARCH . TABLE_COLUMNS . RECEIPT :
2103+ return 'common.receipt' ;
2104+ case CONST . SEARCH . TABLE_COLUMNS . TAG :
2105+ return 'common.tag' ;
2106+ case CONST . SEARCH . TABLE_COLUMNS . ACTION :
20662107 return 'common.action' ;
2108+ case CONST . SEARCH . TABLE_COLUMNS . TITLE :
2109+ return 'common.title' ;
2110+ case CONST . SEARCH . TABLE_COLUMNS . STATUS :
2111+ return 'common.status' ;
20672112 }
20682113}
20692114
@@ -2571,6 +2616,18 @@ function getColumnsToShow(
25712616 }
25722617 } ;
25732618
2619+ // If the user has set custom columns for the search, we need to respect their preference, and only show
2620+ // them what they want to see
2621+ if ( ! arraysEqual ( Object . values ( CONST . SEARCH . DEFAULT_COLUMNS . EXPENSE ) , visibleColumns ) && visibleColumns . length > 0 ) {
2622+ const requiredColumns = new Set < keyof ColumnVisibility > ( [ CONST . SEARCH . TABLE_COLUMNS . AVATAR , CONST . SEARCH . TABLE_COLUMNS . TOTAL_AMOUNT , CONST . SEARCH . TABLE_COLUMNS . TYPE ] ) ;
2623+
2624+ for ( const column of Object . keys ( columns ) as SearchCustomColumnIds [ ] ) {
2625+ columns [ column ] = visibleColumns . includes ( column ) || requiredColumns . has ( column ) ;
2626+ }
2627+
2628+ return columns ;
2629+ }
2630+
25742631 if ( Array . isArray ( data ) ) {
25752632 for ( const item of data ) {
25762633 updateColumns ( item ) ;
@@ -2765,5 +2822,7 @@ export {
27652822 getTransactionFromTransactionListItem ,
27662823 getSearchColumnTranslationKey ,
27672824 getTableMinWidth ,
2825+ getCustomColumns ,
2826+ getCustomColumnDefault ,
27682827} ;
27692828export type { SavedSearchMenuItem , SearchTypeMenuSection , SearchTypeMenuItem , SearchDateModifier , SearchDateModifierLower , SearchKey , ArchivedReportsIDSet } ;
0 commit comments