Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
() =>
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 3 additions & 8 deletions src/libs/actions/Policy/ReportField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<OnyxValueWithOfflineFeedback<PolicyReportField>, 'value'> = {
const optimisticReportFieldDataForPolicy: Omit<OnyxValueWithOfflineFeedback<PolicyReportField>, 'value'> = {
name,
type,
defaultValue: initialValue,
Expand All @@ -182,11 +182,6 @@ function createReportField(policyID: string, {name, type, initialValue}: CreateR
isTax: false,
};

const optimisticReportFieldDataForPolicy: OnyxValueWithOfflineFeedback<PolicyReportField> = {
...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 = [
Expand All @@ -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},
},
},
})),
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion tests/actions/ReportFieldTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down