Skip to content

Commit

Permalink
Merge pull request Expensify#48110 from Expensify/revert-47694-fix/47…
Browse files Browse the repository at this point in the history
…195-inconsistent-report-mention-rendering

Revert "Don't render report mention markdown if it's not a policy report"
  • Loading branch information
puneetlath authored Aug 27, 2024
2 parents 1d72155 + 8ba7df3 commit 451101c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import isEmpty from 'lodash/isEmpty';
import React, {useContext, useMemo} from 'react';
import React, {useMemo} from 'react';
import type {TextStyle} from 'react-native';
import {StyleSheet} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
Expand All @@ -16,7 +16,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import MentionReportContext from './MentionReportContext';

type MentionReportOnyxProps = {
/** All reports shared with the user */
Expand Down Expand Up @@ -57,12 +56,10 @@ function MentionReportRenderer({style, tnode, TDefaultRenderer, reports, ...defa
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const htmlAttributeReportID = tnode.attributes.reportid;
const {currentReportID: currentReportIDContext} = useContext(MentionReportContext);

const currentReportID = useCurrentReportID();
const currentReportIDValue = currentReportIDContext ?? currentReportID?.currentReportID;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const [currentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentReportIDValue || -1}`);
const [currentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${currentReportID?.currentReportID || -1}`);

// When we invite someone to a room they don't have the policy object, but we still want them to be able to see and click on report mentions, so we only check if the policyID in the report is from a workspace
const isGroupPolicyReport = useMemo(() => currentReport && !isEmptyObject(currentReport) && !!currentReport.policyID && currentReport.policyID !== CONST.POLICY.ID_FAKE, [currentReport]);
Expand All @@ -74,7 +71,7 @@ function MentionReportRenderer({style, tnode, TDefaultRenderer, reports, ...defa
const {reportID, mentionDisplayText} = mentionDetails;

const navigationRoute = reportID ? ROUTES.REPORT_WITH_ID.getRoute(reportID) : undefined;
const isCurrentRoomMention = reportID === currentReportIDValue;
const isCurrentRoomMention = reportID === currentReportID?.currentReportID;

const flattenStyle = StyleSheet.flatten(style as TextStyle);
const {color, ...styleWithoutColor} = flattenStyle;
Expand Down

This file was deleted.

8 changes: 2 additions & 6 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@ type MenuItemBaseProps = {
/** Whether should render error text as HTML or as Text */
shouldRenderErrorAsHTML?: boolean;

/** List of markdown rules that will be ignored */
excludedMarkdownRules?: string[];

/** Should check anonymous user in onPress function */
shouldCheckActionAllowedOnPress?: boolean;

Expand Down Expand Up @@ -412,7 +409,6 @@ function MenuItem(
shouldParseHelperText = false,
shouldRenderHintAsHTML = false,
shouldRenderErrorAsHTML = false,
excludedMarkdownRules = [],
shouldCheckActionAllowedOnPress = true,
onSecondaryInteraction,
titleWithTooltips,
Expand Down Expand Up @@ -468,8 +464,8 @@ function MenuItem(
if (!title || !shouldParseTitle) {
return '';
}
return Parser.replace(title, {shouldEscapeText, disabledRules: excludedMarkdownRules});
}, [title, shouldParseTitle, shouldEscapeText, excludedMarkdownRules]);
return Parser.replace(title, {shouldEscapeText});
}, [title, shouldParseTitle, shouldEscapeText]);

const helperHtml = useMemo(() => {
if (!helperText || !shouldParseHelperText) {
Expand Down
40 changes: 17 additions & 23 deletions src/components/MoneyRequestConfirmationListFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import type * as OnyxTypes from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {Unit} from '@src/types/onyx/Policy';
import ConfirmedRoute from './ConfirmedRoute';
import MentionReportContext from './HTMLEngineProvider/HTMLRenderers/MentionReportRenderer/MentionReportContext';
import MenuItem from './MenuItem';
import MenuItemWithTopDescription from './MenuItemWithTopDescription';
import PDFThumbnail from './PDFThumbnail';
Expand Down Expand Up @@ -267,8 +266,6 @@ function MoneyRequestConfirmationListFooter({
const resolvedThumbnail = isLocalFile ? receiptThumbnail : tryResolveUrlFromApiRoot(receiptThumbnail ?? '');
const resolvedReceiptImage = isLocalFile ? receiptImage : tryResolveUrlFromApiRoot(receiptImage ?? '');

const mentionReportContextValue = useMemo(() => ({currentReportID: reportID}), [reportID]);

// An intermediate structure that helps us classify the fields as "primary" and "supplementary".
// The primary fields are always shown to the user, while an extra action is needed to reveal the supplementary ones.
const classifiedFields = [
Expand Down Expand Up @@ -299,26 +296,23 @@ function MoneyRequestConfirmationListFooter({
},
{
item: (
<MentionReportContext.Provider value={mentionReportContextValue}>
<MenuItemWithTopDescription
key={translate('common.description')}
shouldShowRightIcon={!isReadOnly}
shouldParseTitle
excludedMarkdownRules={!policy ? ['reportMentions'] : []}
title={iouComment}
description={translate('common.description')}
onPress={() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams(), reportActionID),
);
}}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
disabled={didConfirm}
interactive={!isReadOnly}
numberOfLinesTitle={2}
/>
</MentionReportContext.Provider>
<MenuItemWithTopDescription
key={translate('common.description')}
shouldShowRightIcon={!isReadOnly}
shouldParseTitle
title={iouComment}
description={translate('common.description')}
onPress={() => {
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(action, iouType, transactionID, reportID, Navigation.getActiveRouteWithoutParams(), reportActionID),
);
}}
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
disabled={didConfirm}
interactive={!isReadOnly}
numberOfLinesTitle={2}
/>
),
shouldShow: true,
isSupplementary: false,
Expand Down
3 changes: 1 addition & 2 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function BaseTextInput(
prefixCharacter = '',
inputID,
isMarkdownEnabled = false,
excludedMarkdownStyles = [],
shouldShowClearButton = false,
prefixContainerStyle = [],
prefixStyle = [],
Expand All @@ -75,7 +74,7 @@ function BaseTextInput(
const inputProps = {shouldSaveDraft: false, shouldUseDefaultValue: false, ...props};
const theme = useTheme();
const styles = useThemeStyles();
const markdownStyle = useMarkdownStyle(undefined, excludedMarkdownStyles);
const markdownStyle = useMarkdownStyle();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();

Expand Down
3 changes: 1 addition & 2 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ function BaseTextInput(
suffixCharacter = '',
inputID,
isMarkdownEnabled = false,
excludedMarkdownStyles = [],
shouldShowClearButton = false,
prefixContainerStyle = [],
prefixStyle = [],
Expand All @@ -79,7 +78,7 @@ function BaseTextInput(

const theme = useTheme();
const styles = useThemeStyles();
const markdownStyle = useMarkdownStyle(undefined, excludedMarkdownStyles);
const markdownStyle = useMarkdownStyle();
const {hasError = false} = inputProps;
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
Expand Down
4 changes: 0 additions & 4 deletions src/components/TextInput/BaseTextInput/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type {MarkdownStyle} from '@expensify/react-native-live-markdown';
import type {GestureResponderEvent, StyleProp, TextInputProps, TextStyle, ViewStyle} from 'react-native';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import type IconAsset from '@src/types/utils/IconAsset';
Expand Down Expand Up @@ -116,9 +115,6 @@ type CustomBaseTextInputProps = {
/** Should live markdown be enabled. Changes RNTextInput component to RNMarkdownTextInput */
isMarkdownEnabled?: boolean;

/** List of markdowns that won't be styled as a markdown */
excludedMarkdownStyles?: Array<keyof MarkdownStyle>;

/** Whether the clear button should be displayed */
shouldShowClearButton?: boolean;

Expand Down
3 changes: 0 additions & 3 deletions src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ function IOURequestStepDescription({
const canEditSplitBill = isSplitBill && reportAction && session?.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction);
// eslint-disable-next-line rulesdir/no-negated-variables
const shouldShowNotFoundPage = isEditing && (isSplitBill ? !canEditSplitBill : !ReportActionsUtils.isMoneyRequestAction(reportAction) || !ReportUtils.canEditMoneyRequest(reportAction));
const isReportInGroupPolicy = !!report?.policyID && report.policyID !== CONST.POLICY.ID_FAKE;

return (
<StepScreenWrapper
headerTitle={translate('common.description')}
Expand Down Expand Up @@ -189,7 +187,6 @@ function IOURequestStepDescription({
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
shouldSubmitForm
isMarkdownEnabled
excludedMarkdownStyles={!isReportInGroupPolicy ? ['mentionReport'] : []}
/>
</View>
</FormProvider>
Expand Down

0 comments on commit 451101c

Please sign in to comment.