Skip to content

Commit 26c5732

Browse files
author
Nabi Ebrahimi
committed
Fix excessive gap after Total column in expense report view
1 parent c7ea04a commit 26c5732

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/libs/SearchUIUtils.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5277,8 +5277,8 @@ function getColumnsToShow({
52775277
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: shouldShowReimbursableColumn,
52785278
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: shouldShowBillableColumn,
52795279
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: false,
5280-
[CONST.SEARCH.TABLE_COLUMNS.TOTAL]: true,
52815280
[CONST.SEARCH.TABLE_COLUMNS.COMMENTS]: shouldShowCommentsColumn,
5281+
[CONST.SEARCH.TABLE_COLUMNS.TOTAL]: true,
52825282
}
52835283
: {
52845284
[CONST.SEARCH.TABLE_COLUMNS.AVATAR]: true,
@@ -5340,7 +5340,12 @@ function getColumnsToShow({
53405340
}
53415341

53425342
if (shouldShowCommentsColumn && !addedColumns.has(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)) {
5343-
result.push(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
5343+
const totalIndex = result.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL);
5344+
if (totalIndex === -1) {
5345+
result.push(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
5346+
} else {
5347+
result.splice(totalIndex, 0, CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
5348+
}
53445349
}
53455350

53465351
// Don't return early — fall through to updateColumns to detect empty columns

tests/unit/Search/SearchUIUtilsTest.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8251,7 +8251,7 @@ describe('SearchUIUtils', () => {
82518251
expect(columns).not.toContain(CONST.SEARCH.TABLE_COLUMNS.TAG);
82528252
});
82538253

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

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

82728272
expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
8273-
// COMMENTS should be at the end
8274-
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.length - 1);
8273+
// TOTAL should be at the end, with COMMENTS immediately before it
8274+
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.length - 2);
8275+
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL)).toBe(columns.length - 1);
8276+
});
8277+
8278+
test('Should place COMMENTS right before TOTAL in default expense report view', () => {
8279+
const baseTransaction = searchResults.data[`transactions_${transactionID}`];
8280+
const testTransaction = {
8281+
...baseTransaction,
8282+
transactionID: 'test',
8283+
merchant: 'Test Merchant',
8284+
};
8285+
8286+
const columns = SearchUIUtils.getColumnsToShow({
8287+
currentAccountID: submitterAccountID,
8288+
data: [testTransaction],
8289+
isExpenseReportView: true,
8290+
shouldShowCommentsColumn: true,
8291+
});
8292+
8293+
expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
8294+
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL) - 1);
82758295
});
82768296

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

0 commit comments

Comments
 (0)