Skip to content
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
9 changes: 7 additions & 2 deletions src/libs/SearchUIUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5277,8 +5277,8 @@ function getColumnsToShow({
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: shouldShowReimbursableColumn,
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: shouldShowBillableColumn,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: false,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL]: true,
[CONST.SEARCH.TABLE_COLUMNS.COMMENTS]: shouldShowCommentsColumn,
[CONST.SEARCH.TABLE_COLUMNS.TOTAL]: true,
}
: {
[CONST.SEARCH.TABLE_COLUMNS.AVATAR]: true,
Expand Down Expand Up @@ -5340,7 +5340,12 @@ function getColumnsToShow({
}

if (shouldShowCommentsColumn && !addedColumns.has(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)) {
result.push(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
const totalIndex = result.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL);
if (totalIndex === -1) {
result.push(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
} else {
result.splice(totalIndex, 0, CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
}
}

// Don't return early — fall through to updateColumns to detect empty columns
Expand Down
28 changes: 24 additions & 4 deletions tests/unit/Search/SearchUIUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8251,7 +8251,7 @@ describe('SearchUIUtils', () => {
expect(columns).not.toContain(CONST.SEARCH.TABLE_COLUMNS.TAG);
});

test('Should include COMMENTS column at the end in expense report view with custom columns', () => {
test('Should place COMMENTS right before TOTAL in expense report view with custom columns', () => {
const baseTransaction = searchResults.data[`transactions_${transactionID}`];
const testTransaction = {
...baseTransaction,
Expand All @@ -8260,7 +8260,7 @@ describe('SearchUIUtils', () => {
};

// Use custom columns to trigger the custom columns path
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.MERCHANT, CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT];
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.TOTAL];
const columns = SearchUIUtils.getColumnsToShow({
currentAccountID: submitterAccountID,
data: [testTransaction],
Expand All @@ -8270,8 +8270,28 @@ describe('SearchUIUtils', () => {
});

expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
// COMMENTS should be at the end
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.length - 1);
// TOTAL should be at the end, with COMMENTS immediately before it
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.length - 2);
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL)).toBe(columns.length - 1);
});

test('Should place COMMENTS right before TOTAL in default expense report view', () => {
const baseTransaction = searchResults.data[`transactions_${transactionID}`];
const testTransaction = {
...baseTransaction,
transactionID: 'test',
merchant: 'Test Merchant',
};

const columns = SearchUIUtils.getColumnsToShow({
currentAccountID: submitterAccountID,
data: [testTransaction],
isExpenseReportView: true,
shouldShowCommentsColumn: true,
});

expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL) - 1);
});

test('Should not duplicate COMMENTS column when already in visible columns', () => {
Expand Down
Loading