From 9641b55de9d743051a3898ac3e6bcc836c27dd66 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 6 Mar 2025 16:07:22 +0700 Subject: [PATCH 1/3] fix: hide disabled list report fields --- .../ReportActionItem/MoneyReportView.tsx | 17 +++++++++++++++-- src/libs/actions/Policy/ReportField.ts | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/MoneyReportView.tsx b/src/components/ReportActionItem/MoneyReportView.tsx index d54d456507d3e..42a7f79d85240 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) || (isReportFieldOfTypeTitle(reportField, false) && !reportField?.deletable) || (!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) || (isReportFieldOfTypeTitle(reportField, false) && !reportField?.deletable)) { + if (shouldHideSingleReportField(reportField)) { return null; } diff --git a/src/libs/actions/Policy/ReportField.ts b/src/libs/actions/Policy/ReportField.ts index 2ada745ca6cf4..8856237e39960 100644 --- a/src/libs/actions/Policy/ReportField.ts +++ b/src/libs/actions/Policy/ReportField.ts @@ -184,7 +184,6 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR 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[]; From 1e71655ff201cf1ab9862d27f4df476b19ac9ab5 Mon Sep 17 00:00:00 2001 From: daledah Date: Thu, 6 Mar 2025 16:17:40 +0700 Subject: [PATCH 2/3] fix: test --- src/libs/actions/Policy/ReportField.ts | 4 +--- tests/actions/ReportFieldTest.ts | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/actions/Policy/ReportField.ts b/src/libs/actions/Policy/ReportField.ts index 8856237e39960..c8796909e8b35 100644 --- a/src/libs/actions/Policy/ReportField.ts +++ b/src/libs/actions/Policy/ReportField.ts @@ -182,9 +182,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR isTax: false, }; - const optimisticReportFieldDataForPolicy: OnyxValueWithOfflineFeedback = { - ...newReportField, - }; + const optimisticReportFieldDataForPolicy: OnyxValueWithOfflineFeedback = newReportField; const policyExpenseReports = Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID && report.type === CONST.REPORT.TYPE.EXPENSE) as Report[]; 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, From 569a17ca22cb977f198d80ad569c0b9199d32e9f Mon Sep 17 00:00:00 2001 From: daledah Date: Fri, 7 Mar 2025 10:12:57 +0700 Subject: [PATCH 3/3] refactor: remove duplicate code --- src/libs/actions/Policy/ReportField.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Policy/ReportField.ts b/src/libs/actions/Policy/ReportField.ts index c8796909e8b35..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,8 +182,6 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR isTax: false, }; - const optimisticReportFieldDataForPolicy: OnyxValueWithOfflineFeedback = newReportField; - const policyExpenseReports = Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID && report.type === CONST.REPORT.TYPE.EXPENSE) as Report[]; const optimisticData = [ @@ -202,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}, }, }, })), @@ -251,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);