Skip to content

Commit 6aaca9e

Browse files
committed
decoupling policy
1 parent 04ad1eb commit 6aaca9e

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,18 @@ function MoneyRequestReportTransactionList({
334334
shouldShowCommentsColumn,
335335
shouldShowReimbursableColumn: hasNonReimbursableTransactions(transactions),
336336
reportCurrency: report?.currency,
337-
policy,
337+
isPolicyTaxEnabled: isTaxEnabled,
338338
});
339-
}, [transactions, currentUserDetails?.accountID, isExpenseReportViewFromIOUReport, shouldShowBillableColumn, shouldShowCommentsColumn, reportDetailsColumns, report?.currency, policy]);
339+
}, [
340+
transactions,
341+
currentUserDetails?.accountID,
342+
isExpenseReportViewFromIOUReport,
343+
shouldShowBillableColumn,
344+
shouldShowCommentsColumn,
345+
reportDetailsColumns,
346+
report?.currency,
347+
isTaxEnabled,
348+
]);
340349

341350
const {windowWidth, windowHeight} = useWindowDimensions();
342351
const minTableWidth = getTableMinWidth(columnsToShow);

src/libs/SearchUIUtils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ import {
118118
isPolicyAdmin,
119119
isPolicyApprover,
120120
isPolicyPayer,
121-
isPolicyTaxEnabled,
122121
} from './PolicyUtils';
123122
import {
124123
getIOUActionForReportID,
@@ -5132,7 +5131,7 @@ function getColumnsToShow({
51325131
shouldShowCommentsColumn = false,
51335132
reportCurrency,
51345133
shouldUseStrictDefaultExpenseColumns = false,
5135-
policy,
5134+
isPolicyTaxEnabled = false,
51365135
}: {
51375136
currentAccountID: number | undefined;
51385137
data: OnyxTypes.SearchResults['data'] | OnyxTypes.Transaction[];
@@ -5146,7 +5145,7 @@ function getColumnsToShow({
51465145
shouldShowCommentsColumn?: boolean;
51475146
reportCurrency?: string;
51485147
shouldUseStrictDefaultExpenseColumns?: boolean;
5149-
policy?: OnyxTypes.Policy;
5148+
isPolicyTaxEnabled?: boolean;
51505149
}): SearchColumnType[] {
51515150
if (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) {
51525151
const defaultReportColumns: SearchColumnType[] = [
@@ -5393,7 +5392,7 @@ function getColumnsToShow({
53935392
// When the user explicitly selected the tax columns (customResult) and the workspace
53945393
// has taxes enabled, keep them regardless of per-transaction values — older expenses
53955394
// created before taxes were turned on still have null taxCode/taxAmount/taxValue.
5396-
const hasTaxInfo = (!!customResult && isPolicyTaxEnabled(policy)) || !!transaction.taxCode || !!transaction.taxAmount || !!transaction.taxValue;
5395+
const hasTaxInfo = (!!customResult && isPolicyTaxEnabled) || !!transaction.taxCode || !!transaction.taxAmount || !!transaction.taxValue;
53975396
if (hasTaxInfo) {
53985397
columns[CONST.SEARCH.TABLE_COLUMNS.TAX_RATE] = true;
53995398
columns[CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT] = true;

src/pages/settings/Report/ReportDetailsColumnsPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {setReportDetailsColumns} from '@libs/actions/ReportLayout';
99
import {hasNonReimbursableTransactions, isBillableEnabledOnPolicy} from '@libs/MoneyRequestReportUtils';
1010
import Navigation from '@libs/Navigation/Navigation';
1111
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
12+
import {isPolicyTaxEnabled} from '@libs/PolicyUtils';
1213
import {isIOUReport} from '@libs/ReportUtils';
1314
import {getColumnsToShow} from '@libs/SearchUIUtils';
1415
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
@@ -80,7 +81,7 @@ function ReportDetailsColumnsPage() {
8081
shouldShowBillableColumn: isBillableEnabledOnPolicy(policy),
8182
shouldShowReimbursableColumn: hasNonReimbursableTransactions(reportTransactions),
8283
reportCurrency: report?.currency,
83-
policy,
84+
isPolicyTaxEnabled: isPolicyTaxEnabled(policy),
8485
});
8586

8687
// Filter to only columns available in the custom columns list (drops RECEIPT/TYPE/COMMENTS etc.)

tests/unit/Search/SearchUIUtilsTest.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
4141
import ROUTES from '@src/ROUTES';
4242
import type * as OnyxTypes from '@src/types/onyx';
4343
import type {CustomCardFeedData} from '@src/types/onyx/CardFeeds';
44-
import type Policy from '@src/types/onyx/Policy';
4544
import type {Connections} from '@src/types/onyx/Policy';
4645
import type {SearchDataTypes} from '@src/types/onyx/SearchResults';
4746
import getOnyxValue from '../../utils/getOnyxValue';
@@ -8279,15 +8278,13 @@ describe('SearchUIUtils', () => {
82798278
taxCode: undefined,
82808279
taxAmount: undefined,
82818280
};
8282-
const taxEnabledPolicy = {...policy, tax: {trackingEnabled: true}} as unknown as Policy;
8283-
82848281
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.TAX_RATE, CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT, CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT];
82858282
const columns = SearchUIUtils.getColumnsToShow({
82868283
currentAccountID: submitterAccountID,
82878284
data: [legacyTransaction],
82888285
visibleColumns,
82898286
isExpenseReportView: true,
8290-
policy: taxEnabledPolicy,
8287+
isPolicyTaxEnabled: true,
82918288
});
82928289

82938290
expect(columns).toContain(CONST.SEARCH.TABLE_COLUMNS.TAX_RATE);
@@ -8307,15 +8304,13 @@ describe('SearchUIUtils', () => {
83078304
taxCode: undefined,
83088305
taxAmount: undefined,
83098306
};
8310-
const taxEnabledPolicy = {...policy, tax: {trackingEnabled: true}} as unknown as Policy;
8311-
83128307
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.MERCHANT, CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT];
83138308
const columns = SearchUIUtils.getColumnsToShow({
83148309
currentAccountID: submitterAccountID,
83158310
data: [legacyTransaction],
83168311
visibleColumns,
83178312
isExpenseReportView: true,
8318-
policy: taxEnabledPolicy,
8313+
isPolicyTaxEnabled: true,
83198314
});
83208315

83218316
expect(columns).not.toContain(CONST.SEARCH.TABLE_COLUMNS.TAX_RATE);
@@ -8333,15 +8328,13 @@ describe('SearchUIUtils', () => {
83338328
taxCode: undefined,
83348329
taxAmount: undefined,
83358330
};
8336-
const taxDisabledPolicy = {...policy, tax: {trackingEnabled: false}} as unknown as Policy;
8337-
83388331
const visibleColumns = [CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.TABLE_COLUMNS.TAX_RATE, CONST.SEARCH.TABLE_COLUMNS.TAX_AMOUNT, CONST.SEARCH.TABLE_COLUMNS.TOTAL_AMOUNT];
83398332
const columns = SearchUIUtils.getColumnsToShow({
83408333
currentAccountID: submitterAccountID,
83418334
data: [legacyTransaction],
83428335
visibleColumns,
83438336
isExpenseReportView: true,
8344-
policy: taxDisabledPolicy,
8337+
isPolicyTaxEnabled: false,
83458338
});
83468339

83478340
expect(columns).not.toContain(CONST.SEARCH.TABLE_COLUMNS.TAX_RATE);

0 commit comments

Comments
 (0)