Skip to content

Commit 279843e

Browse files
Merge pull request #57923 from daledah/fix/56949
fix: hide disabled list report fields
2 parents ef7989f + 1a58a8c commit 279843e

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/components/ReportActionItem/MoneyReportView.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
} from '@libs/ReportUtils';
3535
import AnimatedEmptyStateBackground from '@pages/home/report/AnimatedEmptyStateBackground';
3636
import variables from '@styles/variables';
37+
import CONST from '@src/CONST';
3738
import {clearReportFieldKeyErrors} from '@src/libs/actions/Report';
3839
import ONYXKEYS from '@src/ONYXKEYS';
3940
import ROUTES from '@src/ROUTES';
@@ -95,7 +96,19 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo
9596
const isClosedExpenseReportWithNoExpenses = isClosedExpenseReportWithNoExpensesReportUtils(report);
9697
const isPaidGroupPolicyExpenseReport = isPaidGroupPolicyExpenseReportUtils(report);
9798
const isInvoiceReport = isInvoiceReportUtils(report);
98-
const shouldShowReportField = !isClosedExpenseReportWithNoExpenses && (isPaidGroupPolicyExpenseReport || isInvoiceReport) && (!isCombinedReport || !isOnlyTitleFieldEnabled);
99+
100+
const shouldHideSingleReportField = (reportField: PolicyReportField) => {
101+
const fieldValue = reportField.value ?? reportField.defaultValue;
102+
const hasEnableOption = reportField.type !== CONST.REPORT_FIELD_TYPES.LIST || reportField.disabledOptions.some((option) => !option);
103+
104+
return isReportFieldOfTypeTitle(reportField) || (!fieldValue && !hasEnableOption);
105+
};
106+
107+
const shouldShowReportField =
108+
!isClosedExpenseReportWithNoExpenses &&
109+
(isPaidGroupPolicyExpenseReport || isInvoiceReport) &&
110+
(!isCombinedReport || !isOnlyTitleFieldEnabled) &&
111+
!sortedPolicyReportFields.every(shouldHideSingleReportField);
99112

100113
const renderThreadDivider = useMemo(
101114
() =>
@@ -123,7 +136,7 @@ function MoneyReportView({report, policy, isCombinedReport = false, shouldShowTo
123136
policy?.areReportFieldsEnabled &&
124137
(!isCombinedReport || !isOnlyTitleFieldEnabled) &&
125138
sortedPolicyReportFields.map((reportField) => {
126-
if (isReportFieldOfTypeTitle(reportField)) {
139+
if (shouldHideSingleReportField(reportField)) {
127140
return null;
128141
}
129142

src/libs/actions/Policy/ReportField.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR
168168
const previousFieldList = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.fieldList ?? {};
169169
const fieldID = WorkspaceReportFieldUtils.generateFieldID(name);
170170
const fieldKey = ReportUtils.getReportFieldKey(fieldID);
171-
const newReportField: Omit<OnyxValueWithOfflineFeedback<PolicyReportField>, 'value'> = {
171+
const optimisticReportFieldDataForPolicy: Omit<OnyxValueWithOfflineFeedback<PolicyReportField>, 'value'> = {
172172
name,
173173
type,
174174
defaultValue: initialValue,
@@ -182,11 +182,6 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR
182182
isTax: false,
183183
};
184184

185-
const optimisticReportFieldDataForPolicy: OnyxValueWithOfflineFeedback<PolicyReportField> = {
186-
...newReportField,
187-
value: type === CONST.REPORT_FIELD_TYPES.LIST ? CONST.REPORT_FIELD_TYPES.LIST : null,
188-
};
189-
190185
const policyExpenseReports = Object.values(allReports ?? {}).filter((report) => report?.policyID === policyID && report.type === CONST.REPORT.TYPE.EXPENSE) as Report[];
191186

192187
const optimisticData = [
@@ -205,7 +200,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR
205200
onyxMethod: Onyx.METHOD.MERGE,
206201
value: {
207202
fieldList: {
208-
[fieldKey]: {...newReportField, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
203+
[fieldKey]: {...optimisticReportFieldDataForPolicy, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD},
209204
},
210205
},
211206
})),
@@ -254,7 +249,7 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR
254249

255250
const parameters: CreateWorkspaceReportFieldParams = {
256251
policyID,
257-
reportFields: JSON.stringify([newReportField]),
252+
reportFields: JSON.stringify([optimisticReportFieldDataForPolicy]),
258253
};
259254

260255
API.write(WRITE_COMMANDS.CREATE_WORKSPACE_REPORT_FIELD, parameters, onyxData);

tests/actions/ReportFieldTest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ describe('actions/ReportField', () => {
172172
externalIDs: [],
173173
isTax: false,
174174
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
175-
value: CONST.REPORT_FIELD_TYPES.LIST,
176175
};
177176
const createReportFieldArguments: CreateReportFieldArguments = {
178177
name: reportFieldName,

0 commit comments

Comments
 (0)