Skip to content

Commit aa13260

Browse files
authored
Merge pull request Expensify#90301 from nabi-ebrahimi/fix/excessive-gap-after-total-column
Fix excessive gap after Total column in expense report view
2 parents 196ec16 + 26c5732 commit aa13260

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
@@ -5295,8 +5295,8 @@ function getColumnsToShow({
52955295
[CONST.SEARCH.TABLE_COLUMNS.REIMBURSABLE]: shouldShowReimbursableColumn,
52965296
[CONST.SEARCH.TABLE_COLUMNS.BILLABLE]: shouldShowBillableColumn,
52975297
[CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT]: false,
5298-
[CONST.SEARCH.TABLE_COLUMNS.TOTAL]: true,
52995298
[CONST.SEARCH.TABLE_COLUMNS.COMMENTS]: shouldShowCommentsColumn,
5299+
[CONST.SEARCH.TABLE_COLUMNS.TOTAL]: true,
53005300
}
53015301
: {
53025302
[CONST.SEARCH.TABLE_COLUMNS.AVATAR]: true,
@@ -5358,7 +5358,12 @@ function getColumnsToShow({
53585358
}
53595359

53605360
if (shouldShowCommentsColumn && !addedColumns.has(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)) {
5361-
result.push(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
5361+
const totalIndex = result.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL);
5362+
if (totalIndex === -1) {
5363+
result.push(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
5364+
} else {
5365+
result.splice(totalIndex, 0, CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
5366+
}
53625367
}
53635368

53645369
// 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
@@ -8207,7 +8207,7 @@ describe('SearchUIUtils', () => {
82078207
expect(columns).not.toContain(CONST.SEARCH.TABLE_COLUMNS.TAG);
82088208
});
82098209

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

82188218
// Use custom columns to trigger the custom columns path
8219-
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.MERCHANT, CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT];
8219+
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.TOTAL];
82208220
const columns = SearchUIUtils.getColumnsToShow({
82218221
currentAccountID: submitterAccountID,
82228222
data: [testTransaction],
@@ -8226,8 +8226,28 @@ describe('SearchUIUtils', () => {
82268226
});
82278227

82288228
expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
8229-
// COMMENTS should be at the end
8230-
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.length - 1);
8229+
// TOTAL should be at the end, with COMMENTS immediately before it
8230+
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.length - 2);
8231+
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL)).toBe(columns.length - 1);
8232+
});
8233+
8234+
test('Should place COMMENTS right before TOTAL in default expense report view', () => {
8235+
const baseTransaction = searchResults.data[`transactions_${transactionID}`];
8236+
const testTransaction = {
8237+
...baseTransaction,
8238+
transactionID: 'test',
8239+
merchant: 'Test Merchant',
8240+
};
8241+
8242+
const columns = SearchUIUtils.getColumnsToShow({
8243+
currentAccountID: submitterAccountID,
8244+
data: [testTransaction],
8245+
isExpenseReportView: true,
8246+
shouldShowCommentsColumn: true,
8247+
});
8248+
8249+
expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.COMMENTS);
8250+
expect(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.COMMENTS)).toBe(columns.indexOf(CONST.SEARCH.TABLE_COLUMNS.TOTAL) - 1);
82318251
});
82328252

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

0 commit comments

Comments
 (0)