Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Details Revamp] Allow Editing Report Title from Details Page #44671

Merged
5 changes: 5 additions & 0 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ type MenuItemBaseProps = {
/** Text to display under the main item */
furtherDetails?: string;

/** Render custom content under the main item */
furtherDetailsContent?: () => ReactNode;

/** The function that should be called when this component is LongPressed or right-clicked. */
onSecondaryInteraction?: (event: GestureResponderEvent | MouseEvent) => void;

Expand Down Expand Up @@ -335,6 +338,7 @@ function MenuItem(
iconRight = Expensicons.ArrowRight,
furtherDetailsIcon,
furtherDetails,
furtherDetailsContent,
description,
helperText,
helperTextStyle,
Expand Down Expand Up @@ -680,6 +684,7 @@ function MenuItem(
</Text>
</View>
)}
{!!furtherDetailsContent && <View style={[styles.flexRow, styles.alignItemsCenter]}>{furtherDetailsContent()}</View>}
{titleComponent}
</View>
</View>
Expand Down
7 changes: 5 additions & 2 deletions src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ function MoneyReportView({report, policy}: MoneyReportViewProps) {
<>
{ReportUtils.reportFieldsEnabled(report) &&
sortedPolicyReportFields.map((reportField) => {
const isTitleField = ReportUtils.isReportFieldOfTypeTitle(reportField);
const fieldValue = isTitleField ? report.reportName : reportField.value ?? reportField.defaultValue;
if (ReportUtils.isReportFieldOfTypeTitle(reportField)) {
return null;
}

const fieldValue = reportField.value ?? reportField.defaultValue;
const isFieldDisabled = ReportUtils.isReportFieldDisabled(report, reportField, policy);
const fieldKey = ReportUtils.getReportFieldKey(reportField.fieldID);

Expand Down
44 changes: 43 additions & 1 deletion src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {View} from 'react-native';
import {Str} from 'expensify-common';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx, withOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
Expand Down Expand Up @@ -527,6 +528,45 @@
</OfflineWithFeedback>
);

const titleField = useMemo<OnyxTypes.PolicyReportField | undefined>((): OnyxTypes.PolicyReportField | undefined => {
const fields = ReportUtils.getAvailableReportFields(report, Object.values(policy?.fieldList ?? {}));
return fields.find((reportField) => ReportUtils.isReportFieldOfTypeTitle(reportField));
}, []);

Check warning on line 534 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

React Hook useMemo has missing dependencies: 'policy?.fieldList' and 'report'. Either include them or remove the dependency array
const fieldKey = ReportUtils.getReportFieldKey(titleField?.fieldID ?? '-1');
const isFieldDisabled = ReportUtils.isReportFieldDisabled(report, titleField, policy);

const shouldShowTitleField = caseID !== CASES.MONEY_REQUEST && !isFieldDisabled;

const nameSectionTitleField = titleField && (
<OfflineWithFeedback
pendingAction={report.pendingFields?.[fieldKey]}
errors={report.errorFields?.[fieldKey]}
errorRowStyles={styles.ph5}
key={`menuItem-${fieldKey}`}
onClose={() => Report.clearReportFieldErrors(report.reportID, titleField)}
>
<View style={[styles.flex1, !isFieldDisabled && styles.mt3]}>
<MenuItemWithTopDescription
shouldShowRightIcon={!isFieldDisabled}
interactive={!isFieldDisabled}
title={reportName}
titleStyle={styles.newKansasLarge}
shouldCheckActionAllowedOnPress={false}
description={Str.UCFirst(titleField.name)}
onPress={() => Navigation.navigate(ROUTES.EDIT_REPORT_FIELD_REQUEST.getRoute(report.reportID, report.policyID ?? '-1', titleField.fieldID ?? '-1'))}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming from this #44963, After editing the title, the user should be returned to the Details RHP instead of dismissing the RHP modal.

furtherDetailsContent={() => (

Check failure on line 557 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “ReportDetailsPage” and pass data as props. If you want to allow component creation in props, set allowAsProps option to true
<ParentNavigationSubtitle
parentNavigationSubtitleData={parentNavigationSubtitleData}
parentReportID={report?.parentReportID}
parentReportActionID={report?.parentReportActionID}
pressableStyles={[styles.mt1, styles.mw100]}
/>
)}
/>
</View>
</OfflineWithFeedback>
);

const navigateBackToAfterDelete = useRef<Route>();

const deleteTransaction = useCallback(() => {
Expand Down Expand Up @@ -555,9 +595,11 @@
<ScrollView style={[styles.flex1]}>
<View style={[styles.reportDetailsTitleContainer, styles.pb0]}>
{renderedAvatar}
{isExpenseReport && nameSectionExpenseIOU}
{isExpenseReport && !shouldShowTitleField && nameSectionExpenseIOU}
</View>

{isExpenseReport && shouldShowTitleField && nameSectionTitleField}

grgia marked this conversation as resolved.
Show resolved Hide resolved
{!isExpenseReport && nameSectionGroupWorkspace}

{shouldShowReportDescription && (
Expand Down
Loading