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

Truncation fix for Lack of maximum height for the description field #38890

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
b65f652
fix by truncation
brandonhenry Mar 23, 2024
203401a
Move code to expensify-common
brandonhenry Apr 2, 2024
8add74a
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Apr 9, 2024
c2fcf52
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Apr 12, 2024
3a0ce57
Update MenuItem.tsx
brandonhenry Apr 12, 2024
b5a0b82
Merge branch 'Expensify:main' into add-markdown-trunctation-function
brandonhenry Apr 19, 2024
698fa7c
Merge branch 'Expensify:main' into add-markdown-trunctation-function
brandonhenry Apr 19, 2024
8c64ad6
add example
brandonhenry Apr 19, 2024
e92e301
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Apr 26, 2024
d6df6da
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Apr 28, 2024
f331bb0
fixed truncation
brandonhenry Apr 30, 2024
dcd26a0
ran prettier
brandonhenry Apr 30, 2024
c2bce3e
added more comments
brandonhenry Apr 30, 2024
de55c62
prettier
brandonhenry Apr 30, 2024
2977b28
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Apr 30, 2024
2818795
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry May 6, 2024
25faab7
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry May 8, 2024
74dadb1
changed truncate function to html only
brandonhenry May 8, 2024
6cf6c14
updated regex, removed redundant code
brandonhenry May 15, 2024
8fa8ef3
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry May 15, 2024
47820fc
Update MenuItem.tsx
brandonhenry May 15, 2024
1120be7
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry May 31, 2024
d9d2551
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jun 2, 2024
1dd2e6c
Update src/components/MenuItem.tsx
brandonhenry Jun 2, 2024
1755964
Update src/components/MenuItem.tsx
brandonhenry Jun 2, 2024
1543cf9
Update src/components/MenuItem.tsx
brandonhenry Jun 2, 2024
50da8d9
Update src/components/MenuItem.tsx
brandonhenry Jun 2, 2024
d12a415
Update src/components/MenuItem.tsx
brandonhenry Jun 2, 2024
8129613
Update src/components/MenuItem.tsx
brandonhenry Jun 2, 2024
5b8b151
reworked naming
brandonhenry Jun 2, 2024
f0b7b0d
Update MenuItem.tsx
brandonhenry Jun 2, 2024
3fd5d4e
Update MenuItem.tsx
brandonhenry Jun 2, 2024
1066565
reworked wordbreak section
brandonhenry Jun 2, 2024
5e11266
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jun 4, 2024
3c1b144
Update src/components/MenuItem.tsx
brandonhenry Jun 7, 2024
cd91561
Update src/components/MenuItem.tsx
brandonhenry Jun 7, 2024
7992c53
Update src/components/MenuItem.tsx
brandonhenry Jun 7, 2024
3d7302c
Removed reviewed implementation
brandonhenry Jun 7, 2024
0fb28ca
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jun 7, 2024
5ed6237
ran prettier
brandonhenry Jun 7, 2024
c48a33e
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jun 21, 2024
0f84e6f
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jun 25, 2024
9ed9938
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 15, 2024
7c195bf
Update MenuItem.tsx
brandonhenry Jul 15, 2024
d50e29a
Update Parser.ts
brandonhenry Jul 15, 2024
d6c261e
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 17, 2024
87630b9
updated expensify-common version
brandonhenry Jul 17, 2024
51414c9
revert package change...
brandonhenry Jul 17, 2024
fd98fcb
reset package.json to main
brandonhenry Jul 17, 2024
727e764
Update package.json
brandonhenry Jul 17, 2024
9adefcb
Update package.json
brandonhenry Jul 17, 2024
daf0185
Update MenuItem.tsx
brandonhenry Jul 17, 2024
b4c677a
Update MenuItem.tsx
brandonhenry Jul 17, 2024
a2a2f21
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 17, 2024
94fdf0a
Update package.json
brandonhenry Jul 17, 2024
91cb9d1
update expenify common
brandonhenry Jul 17, 2024
da86d95
update options
brandonhenry Jul 18, 2024
619d82f
Update MenuItem.tsx
brandonhenry Jul 18, 2024
d1a7b9e
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 18, 2024
c35ce60
Update package.json
brandonhenry Jul 19, 2024
69341a3
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 19, 2024
54ffba0
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 28, 2024
7693678
Update MenuItem.tsx
brandonhenry Jul 28, 2024
d959a13
Update MenuItem.tsx
brandonhenry Jul 28, 2024
c1ce0fe
Update MenuItem.tsx
brandonhenry Jul 28, 2024
2f9b0a2
Update MenuItem.tsx
brandonhenry Jul 28, 2024
a76309c
Remove limiting all MenuItems and only limit MenuItemWithDescription
brandonhenry Jul 28, 2024
e17968e
added shouldTruncateDescription
brandonhenry Jul 30, 2024
85570da
Update src/components/MenuItem.tsx
brandonhenry Jul 30, 2024
93def06
Update src/components/MenuItem.tsx
brandonhenry Jul 30, 2024
2d1d8ad
Update src/components/MenuItemWithTopDescription.tsx
brandonhenry Jul 30, 2024
32ab203
Update src/components/MenuItem.tsx
brandonhenry Jul 30, 2024
a21c00c
update limit to 200
brandonhenry Jul 30, 2024
82d470a
Update src/components/MenuItem.tsx
brandonhenry Jul 30, 2024
2a9ad8d
Update src/components/MenuItem.tsx
brandonhenry Jul 30, 2024
6e9d92c
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Jul 30, 2024
dd3222f
Update MenuItem.tsx
brandonhenry Jul 30, 2024
c161d84
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 1, 2024
13bde07
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 4, 2024
998e0fa
Added truncation toggle
brandonhenry Aug 5, 2024
c95efb1
Logic adjust
brandonhenry Aug 5, 2024
0c5ccf3
updated report description page
brandonhenry Aug 9, 2024
f4aa3f7
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 9, 2024
f292a65
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 11, 2024
ab6323a
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 13, 2024
0524ef2
Update ReportDetailsPage.tsx
brandonhenry Aug 13, 2024
abbd948
Update ReportDetailsPage.tsx
brandonhenry Aug 13, 2024
57bab01
updated to add description for those not editing
brandonhenry Aug 13, 2024
40f208d
prettier
brandonhenry Aug 13, 2024
db5771a
revert..
brandonhenry Aug 13, 2024
5735fb9
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 18, 2024
22c87da
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 21, 2024
8109827
Update src/pages/RoomDescriptionPage.tsx
brandonhenry Aug 23, 2024
8b64470
Update src/pages/RoomDescriptionPage.tsx
brandonhenry Aug 23, 2024
c59ff4f
Update src/pages/RoomDescriptionPage.tsx
brandonhenry Aug 23, 2024
8cba44b
Update src/pages/RoomDescriptionPage.tsx
brandonhenry Aug 23, 2024
6857d0d
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 23, 2024
3ab8cd8
Update RoomDescriptionPage.tsx
brandonhenry Aug 23, 2024
5ce3ef5
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 26, 2024
77b6b37
Update src/components/MenuItem.tsx
brandonhenry Aug 26, 2024
6e80b27
Update src/components/MenuItem.tsx
brandonhenry Aug 26, 2024
bce1cd5
update param name
brandonhenry Aug 26, 2024
a30023e
Update MenuItem.tsx
brandonhenry Aug 26, 2024
4eb703b
Merge remote-tracking branch 'upstream/main' into add-markdown-trunct…
brandonhenry Aug 26, 2024
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
15 changes: 13 additions & 2 deletions src/components/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ type MenuItemBaseProps = {
/** Text that appears above the title */
label?: string;

/** Character limit after which the menu item text will be truncated */
characterLimit?: number;

isLabelHoverable?: boolean;

/** Label to be displayed on the right */
Expand All @@ -201,6 +204,9 @@ type MenuItemBaseProps = {
/** Should we make this selectable with a checkbox */
shouldShowSelectedState?: boolean;

/** Should we truncate the title */
shouldTruncateTitle?: boolean;

/** Whether this item is selected */
isSelected?: boolean;

Expand Down Expand Up @@ -325,7 +331,6 @@ type MenuItemBaseProps = {
};

type MenuItemProps = (IconProps | AvatarProps | NoIcon) & MenuItemBaseProps;

function MenuItem(
{
interactive = true,
Expand Down Expand Up @@ -376,6 +381,8 @@ function MenuItem(
subtitle,
shouldShowBasicTitle,
label,
shouldTruncateTitle = false,
characterLimit = 200,
isLabelHoverable = true,
rightLabel,
shouldShowSelectedState = false,
Expand Down Expand Up @@ -477,8 +484,12 @@ function MenuItem(
titleToWrap = html;
}

if (shouldTruncateTitle) {
titleToWrap = Parser.truncateHTML(titleToWrap, characterLimit, {ellipsis: '...'});
Copy link
Contributor

Choose a reason for hiding this comment

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

We forgot to wrap the content in comment tag, which broke this truncation for plain text. The issue is here

}

return titleToWrap ? `<comment>${titleToWrap}</comment>` : '';
}, [title, shouldRenderAsHTML, shouldParseTitle, html]);
}, [title, shouldRenderAsHTML, shouldParseTitle, characterLimit, shouldTruncateTitle, html]);

const processedHelperText = useMemo(() => {
let textToWrap = '';
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class ExpensiMarkWithContext extends ExpensiMark {
cacheVideoAttributes: extras?.cacheVideoAttributes,
});
}

truncateHTML(htmlString: string, limit: number, extras?: {ellipsis: string | undefined}): string {
return super.truncateHTML(htmlString, limit, extras);
}
}

ExpensiMarkWithContext.setLogger(Log);
Expand Down
7 changes: 4 additions & 3 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
const isExpenseReport = isMoneyRequestReport || isInvoiceReport || isMoneyRequest;
const isSingleTransactionView = isMoneyRequest || isTrackExpenseReport;
const isSelfDMTrackExpenseReport = isTrackExpenseReport && ReportUtils.isSelfDM(parentReport);

const shouldDisableRename = useMemo(() => ReportUtils.shouldDisableRename(report), [report]);
const parentNavigationSubtitleData = ReportUtils.getParentNavigationSubtitle(report);
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps -- policy is a dependency because `getChatRoomSubtitle` calls `getPolicyName` which in turn retrieves the value from the `policy` value stored in Onyx
Expand Down Expand Up @@ -720,10 +719,12 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
{shouldShowReportDescription && (
<OfflineWithFeedback pendingAction={report.pendingFields?.description}>
<MenuItemWithTopDescription
shouldShowRightIcon={canEditReportDescription}
interactive={canEditReportDescription}
shouldShowRightIcon
interactive
title={report.description}
shouldRenderAsHTML
shouldTruncateTitle
characterLimit={100}
shouldCheckActionAllowedOnPress={false}
description={translate('reportDescriptionPage.roomDescription')}
onPress={() => Navigation.navigate(ROUTES.REPORT_DESCRIPTION.getRoute(report.reportID))}
Expand Down
15 changes: 11 additions & 4 deletions src/pages/RoomDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import {useFocusEffect} from '@react-navigation/native';
import React, {useCallback, useRef, useState} from 'react';
import {View} from 'react-native';
import type {OnyxCollection} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import RenderHTML from '@components/RenderHTML';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import TextInput from '@components/TextInput';
import type {BaseTextInputRef} from '@components/TextInput/BaseTextInput/types';
Expand Down Expand Up @@ -60,14 +61,15 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
}, []),
);

const canEdit = ReportUtils.canEditReportDescription(report, policy);
return (
<ScreenWrapper
shouldEnableMaxHeight
includeSafeAreaPaddingBottom={false}
testID={RoomDescriptionPage.displayName}
>
<FullPageNotFoundView shouldShow={!ReportUtils.canEditReportDescription(report, policy)}>
<HeaderWithBackButton title={translate('reportDescriptionPage.roomDescription')} />
<HeaderWithBackButton title={translate('reportDescriptionPage.roomDescription')} />
{canEdit && (
<FormProvider
brandonhenry marked this conversation as resolved.
Show resolved Hide resolved
brandonhenry marked this conversation as resolved.
Show resolved Hide resolved
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.REPORT_DESCRIPTION_FORM}
Expand Down Expand Up @@ -102,7 +104,12 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
/>
</View>
</FormProvider>
brandonhenry marked this conversation as resolved.
Show resolved Hide resolved
</FullPageNotFoundView>
)}
{!canEdit && (
<ScrollView style={[styles.flexGrow1, styles.ph5, styles.mb5]}>
<RenderHTML html={Parser.replace(description)} />
</ScrollView>
)}
</ScreenWrapper>
);
}
Expand Down
Loading