diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index a5cd674b35f9b..f4e3302eacf46 100644 --- a/src/components/ReportActionItem/MoneyReportView.tsx +++ b/src/components/ReportActionItem/MoneyReportView.tsx @@ -34,6 +34,7 @@ import { } from '@libs/ReportUtils'; import AnimatedEmptyStateBackground from '@pages/home/report/AnimatedEmptyStateBackground'; import variables from '@styles/variables'; +import CONST from '@src/CONST'; import {clearReportFieldKeyErrors} from '@src/libs/actions/Report'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -95,7 +96,19 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo const isClosedExpenseReportWithNoExpenses = isClosedExpenseReportWithNoExpensesReportUtils(report); const isPaidGroupPolicyExpenseReport = isPaidGroupPolicyExpenseReportUtils(report); const isInvoiceReport = isInvoiceReportUtils(report); - const shouldShowReportField = !isClosedExpenseReportWithNoExpenses && (isPaidGroupPolicyExpenseReport || isInvoiceReport) && (!isCombinedReport || !isOnlyTitleFieldEnabled); + + const shouldHideSingleReportField = (reportField: PolicyReportField) => { + const fieldValue = reportField.value ?? reportField.defaultValue; + const hasEnableOption = reportField.type !== CONST.REPORT_FIELD_TYPES.LIST || reportField.disabledOptions.some((option) => !option); + + return isReportFieldOfTypeTitle(reportField) || (!fieldValue && !hasEnableOption); + }; + + const shouldShowReportField = + !isClosedExpenseReportWithNoExpenses && + (isPaidGroupPolicyExpenseReport || isInvoiceReport) && + (!isCombinedReport || !isOnlyTitleFieldEnabled) && + !sortedPolicyReportFields.every(shouldHideSingleReportField); const renderThreadDivider = useMemo( () => @@ -123,7 +136,7 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo policy?.areReportFieldsEnabled && (!isCombinedReport || !isOnlyTitleFieldEnabled) && sortedPolicyReportFields.map((reportField) => { - if (isReportFieldOfTypeTitle(reportField)) { + if (shouldHideSingleReportField(reportField)) { return null; } diff --git a/src/libs/actions/Policy/ReportField.ts b/src/libs/actions/Policy/ReportField.ts index 2ada745ca6cf4..f5d6946e108d5 100644 --- a/src/libs/actions/Policy/ReportField.ts +++ b/src/libs/actions/Policy/ReportField.ts @@ -168,7 +168,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR const previousFieldList = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.fieldList ?? {}; const fieldID = WorkspaceReportFieldUtils.generateFieldID(name); const fieldKey = ReportUtils.getReportFieldKey(fieldID); - const newReportField: Omit, 'value'> = { + const optimisticReportFieldDataForPolicy: Omit, 'value'> = { name, type, defaultValue: initialValue, @@ -182,11 +182,6 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR isTax: false, }; - const optimisticReportFieldDataForPolicy: OnyxValueWithOfflineFeedback = { - ...newReportField, - value: type === CONST.REPORT_FIELD_TYPES.LIST ? CONST.REPORT_FIELD_TYPES.LIST : null, - }; - const policyExpenseReports = Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID && report.type === CONST.REPORT.TYPE.EXPENSE) as Report[]; const optimisticData = [ @@ -205,7 +200,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR onyxMethod: Onyx.METHOD.MERGE, value: { fieldList: { - [fieldKey]: {...newReportField, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, + [fieldKey]: {...optimisticReportFieldDataForPolicy, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, }, }, })), @@ -254,7 +249,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR const parameters: CreateWorkspaceReportFieldParams = { policyID, - reportFields: JSON.stringify([newReportField]), + reportFields: JSON.stringify([optimisticReportFieldDataForPolicy]), }; API.write(WRITE_COMMANDS.CREATE_WORKSPACE_REPORT_FIELD, parameters, onyxData); diff --git a/tests/actions/ReportFieldTest.ts b/tests/actions/ReportFieldTest.ts index 823cb1cc02dba..53178c3bf8bac 100644 --- a/tests/actions/ReportFieldTest.ts +++ b/tests/actions/ReportFieldTest.ts @@ -172,7 +172,6 @@ describe('actions/ReportField', () => { externalIDs: [], isTax: false, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - value: CONST.REPORT_FIELD_TYPES.LIST, }; const createReportFieldArguments: CreateReportFieldArguments = { name: reportFieldName,