From 9da12c42f15050a60b7b4cb15f28a97dd7f69d42 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 22 Apr 2024 13:06:38 +0200 Subject: [PATCH 1/6] mvp --- package-lock.json | 6 ++--- package.json | 2 +- src/libs/ReportUtils.ts | 27 ++++++++++++++++---- src/libs/actions/Policy.ts | 2 +- src/libs/actions/Report.ts | 8 +++--- src/pages/workspace/WorkspaceNewRoomPage.tsx | 2 +- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8caa0401d28f..8cab4c43db4f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,7 +56,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#c0f7f3b6558fbeda0527c80d68460d418afef219", + "expensify-common": "git+ssh://git@github.com:software-mansion-labs/expensify-common.git#7596ae07c9cd5a6b5265897034898b4526d681dc", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -20209,8 +20209,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#c0f7f3b6558fbeda0527c80d68460d418afef219", - "integrity": "sha512-zz0/y0apISP1orxXEQOgn+Uod45O4wVypwwtaqcDPV4dH1tC3i4L98NoLSZvLn7Y17EcceSkfN6QCEsscgFTDQ==", + "resolved": "git+ssh://git@github.com/software-mansion-labs/expensify-common.git#7596ae07c9cd5a6b5265897034898b4526d681dc", + "integrity": "sha512-Ns7qkMuJ4SeLj0lrj3i+KqHBzjlym8baDlS7CUIqq2tuNXkgxwO4D+5d6U3ooLOf0CyWb56KaGy5TOTFqpJDZA==", "license": "MIT", "dependencies": { "classnames": "2.5.0", diff --git a/package.json b/package.json index 1461f0bfb77f..590bc1c9af79 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#c0f7f3b6558fbeda0527c80d68460d418afef219", + "expensify-common": "git+ssh://git@github.com:software-mansion-labs/expensify-common.git#7596ae07c9cd5a6b5265897034898b4526d681dc", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fc677dedc96e..0d0937c09bc3 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -3161,7 +3161,17 @@ function addDomainToShortMention(mention: string): string | undefined { * For comments shorter than or equal to 10k chars, convert the comment from MD into HTML because that's how it is stored in the database * For longer comments, skip parsing, but still escape the text, and display plaintext for performance reasons. It takes over 40s to parse a 100k long string!! */ -function getParsedComment(text: string, shouldEscapeText?: boolean): string { +function getParsedComment(text: string, shouldEscapeText?: boolean, currentReportID?: string, policyID?: string): string { + let isGroupPolicyReport = false; + if (currentReportID) { + const currentReport = getReport(currentReportID); + isGroupPolicyReport = currentReport && !isEmptyObject(currentReport) ? isGroupPolicy(currentReport) : false; + } + if (policyID) { + const policyType = getPolicy(policyID).type; + isGroupPolicyReport = policyType === CONST.POLICY.TYPE.CORPORATE || policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.FREE; + } + const parser = new ExpensiMark(); const textWithMention = text.replace(CONST.REGEX.SHORT_MENTION, (match) => { const mention = match.substring(1); @@ -3169,7 +3179,7 @@ function getParsedComment(text: string, shouldEscapeText?: boolean): string { return mentionWithDomain ? `@${mentionWithDomain}` : match; }); - return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(textWithMention, {shouldEscapeText}) : lodashEscape(text); + return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(textWithMention, {shouldEscapeText, disabledRules: isGroupPolicyReport ? [] : ['reportMentions']}) : lodashEscape(text); } function getReportDescriptionText(report: Report): string { @@ -3190,9 +3200,16 @@ function getPolicyDescriptionText(policy: OnyxEntry): string { return parser.htmlToText(policy.description); } -function buildOptimisticAddCommentReportAction(text?: string, file?: FileObject, actorAccountID?: number, createdOffset = 0, shouldEscapeText?: boolean): OptimisticReportAction { +function buildOptimisticAddCommentReportAction( + text?: string, + file?: FileObject, + actorAccountID?: number, + createdOffset = 0, + shouldEscapeText?: boolean, + reportID?: string, +): OptimisticReportAction { const parser = new ExpensiMark(); - const commentText = getParsedComment(text ?? '', shouldEscapeText); + const commentText = getParsedComment(text ?? '', shouldEscapeText, reportID); const isAttachmentOnly = file && !text; const isTextOnly = text && !file; @@ -3314,7 +3331,7 @@ function buildOptimisticTaskCommentReportAction( childOldestFourAccountIDs?: string; }, ): OptimisticReportAction { - const reportAction = buildOptimisticAddCommentReportAction(text, undefined, undefined, createdOffset); + const reportAction = buildOptimisticAddCommentReportAction(text, undefined, undefined, createdOffset, undefined, taskReportID); if (reportAction.reportAction.message?.[0]) { reportAction.reportAction.message[0].taskReportID = taskReportID; } diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index cd375b580d85..f2ba65bf0717 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1722,7 +1722,7 @@ function updateWorkspaceDescription(policyID: string, description: string, curre if (description === currentDescription) { return; } - const parsedDescription = ReportUtils.getParsedComment(description); + const parsedDescription = ReportUtils.getParsedComment(description, undefined, undefined, policyID); const optimisticData: OnyxUpdate[] = [ { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 8b0dbf8a37a9..f062a4d78c68 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -446,7 +446,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { let commandName: typeof WRITE_COMMANDS.ADD_COMMENT | typeof WRITE_COMMANDS.ADD_ATTACHMENT | typeof WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT = WRITE_COMMANDS.ADD_COMMENT; if (text && !file) { - const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(text); + const reportComment = ReportUtils.buildOptimisticAddCommentReportAction(text, undefined, undefined, undefined, undefined, reportID); reportCommentAction = reportComment.reportAction; reportCommentText = reportComment.commentText; } @@ -455,13 +455,13 @@ function addActions(reportID: string, text = '', file?: FileObject) { // When we are adding an attachment we will call AddAttachment. // It supports sending an attachment with an optional comment and AddComment supports adding a single text comment only. commandName = WRITE_COMMANDS.ADD_ATTACHMENT; - const attachment = ReportUtils.buildOptimisticAddCommentReportAction(text, file); + const attachment = ReportUtils.buildOptimisticAddCommentReportAction(text, file, undefined, undefined, undefined, reportID); attachmentAction = attachment.reportAction; } if (text && file) { // When there is both text and a file, the text for the report comment needs to be parsed) - reportCommentText = ReportUtils.getParsedComment(text ?? ''); + reportCommentText = ReportUtils.getParsedComment(text ?? '', undefined, reportID); // And the API command needs to go to the new API which supports combining both text and attachments in a single report action commandName = WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT; @@ -1848,7 +1848,7 @@ function updateDescription(reportID: string, previousValue: string, newValue: st return; } - const parsedDescription = ReportUtils.getParsedComment(newValue); + const parsedDescription = ReportUtils.getParsedComment(newValue, undefined, reportID); const optimisticData: OnyxUpdate[] = [ { diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index 46a5b533372a..b2f9085502eb 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -105,7 +105,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli */ const submit = (values: FormOnyxValues) => { const participants = [session?.accountID ?? 0]; - const parsedDescription = ReportUtils.getParsedComment(values.reportDescription ?? ''); + const parsedDescription = ReportUtils.getParsedComment(values.reportDescription ?? '', undefined, undefined, policyID); const policyReport = ReportUtils.buildOptimisticChatReport( participants, values.roomName, From 9db429655d129027e4a1defba2dc01cb95a5b307 Mon Sep 17 00:00:00 2001 From: war-in Date: Mon, 22 Apr 2024 13:16:47 +0200 Subject: [PATCH 2/6] update getCommentLength --- src/libs/ReportUtils.ts | 4 ++-- .../ComposerWithSuggestions/ComposerWithSuggestions.tsx | 2 +- src/pages/home/report/ReportActionItemMessageEdit.tsx | 2 +- src/pages/workspace/WorkspaceNewRoomPage.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 0d0937c09bc3..3df0194f6e5a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4931,8 +4931,8 @@ function getNewMarkerReportActionID(report: OnyxEntry, sortedAndFiltered * Used for compatibility with the backend auth validator for AddComment, and to account for MD in comments * @returns The comment's total length as seen from the backend */ -function getCommentLength(textComment: string): number { - return getParsedComment(textComment) +function getCommentLength(textComment: string, reportID?: string, policyID?: string): number { + return getParsedComment(textComment, undefined, reportID, policyID) .replace(/[^ -~]/g, '\\u????') .trim().length; } diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 8f42da5a1575..4be8db304b92 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -474,7 +474,7 @@ function ComposerWithSuggestions( const prepareCommentAndResetComposer = useCallback((): string => { const trimmedComment = commentRef.current.trim(); - const commentLength = ReportUtils.getCommentLength(trimmedComment); + const commentLength = ReportUtils.getCommentLength(trimmedComment, reportID); // Don't submit empty comments or comments that exceed the character limit if (!commentLength || commentLength > CONST.MAX_COMMENT_LENGTH) { diff --git a/src/pages/home/report/ReportActionItemMessageEdit.tsx b/src/pages/home/report/ReportActionItemMessageEdit.tsx index fc3c92434fc4..79a22f61e17b 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.tsx +++ b/src/pages/home/report/ReportActionItemMessageEdit.tsx @@ -318,7 +318,7 @@ function ReportActionItemMessageEdit( */ const publishDraft = useCallback(() => { // Do nothing if draft exceed the character limit - if (ReportUtils.getCommentLength(draft) > CONST.MAX_COMMENT_LENGTH) { + if (ReportUtils.getCommentLength(draft, reportID) > CONST.MAX_COMMENT_LENGTH) { return; } diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index b2f9085502eb..ffd8cc478ef4 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -183,7 +183,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli ErrorUtils.addErrorMessage(errors, 'roomName', ['common.error.characterLimitExceedCounter', {length: values.roomName.length, limit: CONST.TITLE_CHARACTER_LIMIT}]); } - const descriptionLength = ReportUtils.getCommentLength(values.reportDescription); + const descriptionLength = ReportUtils.getCommentLength(values.reportDescription, policyID); if (descriptionLength > CONST.REPORT_DESCRIPTION.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'reportDescription', [ 'common.error.characterLimitExceedCounter', From ff600c740ba8956865a69d81ba96857d437845ad Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 23 Apr 2024 13:09:25 +0200 Subject: [PATCH 3/6] update expensify-common --- package-lock.json | 6 +++--- package.json | 2 +- src/pages/workspace/WorkspaceNewRoomPage.tsx | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cab4c43db4f..cbaede5c0a48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,7 +56,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com:software-mansion-labs/expensify-common.git#7596ae07c9cd5a6b5265897034898b4526d681dc", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#9a68635cdcef4c81593c0f816a007bc9c707d46a", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", @@ -20209,8 +20209,8 @@ }, "node_modules/expensify-common": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/software-mansion-labs/expensify-common.git#7596ae07c9cd5a6b5265897034898b4526d681dc", - "integrity": "sha512-Ns7qkMuJ4SeLj0lrj3i+KqHBzjlym8baDlS7CUIqq2tuNXkgxwO4D+5d6U3ooLOf0CyWb56KaGy5TOTFqpJDZA==", + "resolved": "git+ssh://git@github.com/Expensify/expensify-common.git#9a68635cdcef4c81593c0f816a007bc9c707d46a", + "integrity": "sha512-9BHjM3kZs7/dil0oykEQFkEhXjVD5liTttmO7ZYtPZkl4j6g97mubY2p9lYpWwpkWckUfvU7nGuZQjahw9xSFA==", "license": "MIT", "dependencies": { "classnames": "2.5.0", diff --git a/package.json b/package.json index 590bc1c9af79..2d09680fb69c 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,7 @@ "date-fns-tz": "^2.0.0", "dom-serializer": "^0.2.2", "domhandler": "^4.3.0", - "expensify-common": "git+ssh://git@github.com:software-mansion-labs/expensify-common.git#7596ae07c9cd5a6b5265897034898b4526d681dc", + "expensify-common": "git+ssh://git@github.com/Expensify/expensify-common.git#9a68635cdcef4c81593c0f816a007bc9c707d46a", "expo": "^50.0.3", "expo-av": "~13.10.4", "expo-image": "1.11.0", diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index ffd8cc478ef4..9a204755a1e5 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -197,7 +197,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli return errors; }, - [reports], + [reports, policyID], ); const writeCapabilityOptions = useMemo( From 3af842806d1dcf6c96af9b7d81b88960d575886f Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 23 Apr 2024 13:27:35 +0200 Subject: [PATCH 4/6] introduce ParsingDetails object --- src/libs/ReportUtils.ts | 26 ++++++++++++------- src/libs/actions/Policy.ts | 2 +- src/libs/actions/Report.ts | 4 +-- .../ComposerWithSuggestions.tsx | 2 +- .../report/ReportActionItemMessageEdit.tsx | 2 +- src/pages/workspace/WorkspaceNewRoomPage.tsx | 4 +-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3df0194f6e5a..ac259863489b 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -467,6 +467,12 @@ type OutstandingChildRequest = { hasOutstandingChildRequest?: boolean; }; +type ParsingDetails = { + shouldEscapeText?: boolean; + reportID?: string; + policyID?: string; +}; + let currentUserEmail: string | undefined; let currentUserPrivateDomain: string | undefined; let currentUserAccountID: number | undefined; @@ -3161,14 +3167,14 @@ function addDomainToShortMention(mention: string): string | undefined { * For comments shorter than or equal to 10k chars, convert the comment from MD into HTML because that's how it is stored in the database * For longer comments, skip parsing, but still escape the text, and display plaintext for performance reasons. It takes over 40s to parse a 100k long string!! */ -function getParsedComment(text: string, shouldEscapeText?: boolean, currentReportID?: string, policyID?: string): string { +function getParsedComment(text: string, parsingDetails?: ParsingDetails): string { let isGroupPolicyReport = false; - if (currentReportID) { - const currentReport = getReport(currentReportID); + if (parsingDetails?.reportID) { + const currentReport = getReport(parsingDetails?.reportID); isGroupPolicyReport = currentReport && !isEmptyObject(currentReport) ? isGroupPolicy(currentReport) : false; } - if (policyID) { - const policyType = getPolicy(policyID).type; + if (parsingDetails?.policyID) { + const policyType = getPolicy(parsingDetails?.policyID).type; isGroupPolicyReport = policyType === CONST.POLICY.TYPE.CORPORATE || policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.FREE; } @@ -3179,7 +3185,9 @@ function getParsedComment(text: string, shouldEscapeText?: boolean, currentRepor return mentionWithDomain ? `@${mentionWithDomain}` : match; }); - return text.length <= CONST.MAX_MARKUP_LENGTH ? parser.replace(textWithMention, {shouldEscapeText, disabledRules: isGroupPolicyReport ? [] : ['reportMentions']}) : lodashEscape(text); + return text.length <= CONST.MAX_MARKUP_LENGTH + ? parser.replace(textWithMention, {shouldEscapeText: parsingDetails?.shouldEscapeText, disabledRules: isGroupPolicyReport ? [] : ['reportMentions']}) + : lodashEscape(text); } function getReportDescriptionText(report: Report): string { @@ -3209,7 +3217,7 @@ function buildOptimisticAddCommentReportAction( reportID?: string, ): OptimisticReportAction { const parser = new ExpensiMark(); - const commentText = getParsedComment(text ?? '', shouldEscapeText, reportID); + const commentText = getParsedComment(text ?? '', {shouldEscapeText, reportID}); const isAttachmentOnly = file && !text; const isTextOnly = text && !file; @@ -4931,8 +4939,8 @@ function getNewMarkerReportActionID(report: OnyxEntry, sortedAndFiltered * Used for compatibility with the backend auth validator for AddComment, and to account for MD in comments * @returns The comment's total length as seen from the backend */ -function getCommentLength(textComment: string, reportID?: string, policyID?: string): number { - return getParsedComment(textComment, undefined, reportID, policyID) +function getCommentLength(textComment: string, parsingDetails?: ParsingDetails): number { + return getParsedComment(textComment, parsingDetails) .replace(/[^ -~]/g, '\\u????') .trim().length; } diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index f2ba65bf0717..39648814b143 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1722,7 +1722,7 @@ function updateWorkspaceDescription(policyID: string, description: string, curre if (description === currentDescription) { return; } - const parsedDescription = ReportUtils.getParsedComment(description, undefined, undefined, policyID); + const parsedDescription = ReportUtils.getParsedComment(description, {policyID}); const optimisticData: OnyxUpdate[] = [ { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index f062a4d78c68..e946a1264a7d 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -461,7 +461,7 @@ function addActions(reportID: string, text = '', file?: FileObject) { if (text && file) { // When there is both text and a file, the text for the report comment needs to be parsed) - reportCommentText = ReportUtils.getParsedComment(text ?? '', undefined, reportID); + reportCommentText = ReportUtils.getParsedComment(text ?? '', {reportID}); // And the API command needs to go to the new API which supports combining both text and attachments in a single report action commandName = WRITE_COMMANDS.ADD_TEXT_AND_ATTACHMENT; @@ -1848,7 +1848,7 @@ function updateDescription(reportID: string, previousValue: string, newValue: st return; } - const parsedDescription = ReportUtils.getParsedComment(newValue, undefined, reportID); + const parsedDescription = ReportUtils.getParsedComment(newValue, {reportID}); const optimisticData: OnyxUpdate[] = [ { diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx index 4be8db304b92..f33e9a1a9de4 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx @@ -474,7 +474,7 @@ function ComposerWithSuggestions( const prepareCommentAndResetComposer = useCallback((): string => { const trimmedComment = commentRef.current.trim(); - const commentLength = ReportUtils.getCommentLength(trimmedComment, reportID); + const commentLength = ReportUtils.getCommentLength(trimmedComment, {reportID}); // Don't submit empty comments or comments that exceed the character limit if (!commentLength || commentLength > CONST.MAX_COMMENT_LENGTH) { diff --git a/src/pages/home/report/ReportActionItemMessageEdit.tsx b/src/pages/home/report/ReportActionItemMessageEdit.tsx index 79a22f61e17b..bfd2c8b5ca7f 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.tsx +++ b/src/pages/home/report/ReportActionItemMessageEdit.tsx @@ -318,7 +318,7 @@ function ReportActionItemMessageEdit( */ const publishDraft = useCallback(() => { // Do nothing if draft exceed the character limit - if (ReportUtils.getCommentLength(draft, reportID) > CONST.MAX_COMMENT_LENGTH) { + if (ReportUtils.getCommentLength(draft, {reportID}) > CONST.MAX_COMMENT_LENGTH) { return; } diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index 9a204755a1e5..c66506d4a9b1 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -105,7 +105,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli */ const submit = (values: FormOnyxValues) => { const participants = [session?.accountID ?? 0]; - const parsedDescription = ReportUtils.getParsedComment(values.reportDescription ?? '', undefined, undefined, policyID); + const parsedDescription = ReportUtils.getParsedComment(values.reportDescription ?? '', {policyID}); const policyReport = ReportUtils.buildOptimisticChatReport( participants, values.roomName, @@ -183,7 +183,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli ErrorUtils.addErrorMessage(errors, 'roomName', ['common.error.characterLimitExceedCounter', {length: values.roomName.length, limit: CONST.TITLE_CHARACTER_LIMIT}]); } - const descriptionLength = ReportUtils.getCommentLength(values.reportDescription, policyID); + const descriptionLength = ReportUtils.getCommentLength(values.reportDescription, {policyID}); if (descriptionLength > CONST.REPORT_DESCRIPTION.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'reportDescription', [ 'common.error.characterLimitExceedCounter', From 84a54db10fdc3b11c287186a61d43e90d7c1f1a5 Mon Sep 17 00:00:00 2001 From: war-in Date: Fri, 26 Apr 2024 10:03:37 +0200 Subject: [PATCH 5/6] review suggestions --- .../ReportActionItem/MoneyRequestView.tsx | 2 +- src/hooks/useHandleExceedMaxCommentLength.ts | 5 ++-- src/libs/ReportUtils.ts | 24 ++++++++++++------- .../ReportActionCompose.tsx | 2 +- .../report/ReportActionItemMessageEdit.tsx | 4 ++-- .../request/step/IOURequestStepCategory.tsx | 2 +- .../request/step/IOURequestStepMerchant.tsx | 2 +- .../iou/request/step/IOURequestStepTag.tsx | 2 +- 8 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 08bcc16cbbee..bfa34efb4f05 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -156,7 +156,7 @@ function MoneyRequestView({ // A flag for verifying that the current report is a sub-report of a workspace chat // if the policy of the report is either Collect or Control, then this report must be tied to workspace chat - const isPolicyExpenseChat = ReportUtils.isGroupPolicy(report); + const isPolicyExpenseChat = ReportUtils.isReportInGroupPolicy(report); const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTagList), [policyTagList]); diff --git a/src/hooks/useHandleExceedMaxCommentLength.ts b/src/hooks/useHandleExceedMaxCommentLength.ts index fea0793c9854..69c1d7597164 100644 --- a/src/hooks/useHandleExceedMaxCommentLength.ts +++ b/src/hooks/useHandleExceedMaxCommentLength.ts @@ -1,14 +1,15 @@ import _ from 'lodash'; import {useCallback, useMemo, useState} from 'react'; import * as ReportUtils from '@libs/ReportUtils'; +import type {ParsingDetails} from '@libs/ReportUtils'; import CONST from '@src/CONST'; const useHandleExceedMaxCommentLength = () => { const [hasExceededMaxCommentLength, setHasExceededMaxCommentLength] = useState(false); const handleValueChange = useCallback( - (value: string) => { - if (ReportUtils.getCommentLength(value) <= CONST.MAX_COMMENT_LENGTH) { + (value: string, parsingDetails?: ParsingDetails) => { + if (ReportUtils.getCommentLength(value, parsingDetails) <= CONST.MAX_COMMENT_LENGTH) { if (hasExceededMaxCommentLength) { setHasExceededMaxCommentLength(false); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 8ee14d07f856..4713444d0088 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -874,12 +874,19 @@ function isControlPolicyExpenseChat(report: OnyxEntry): boolean { return isPolicyExpenseChat(report) && getPolicyType(report, allPolicies) === CONST.POLICY.TYPE.CORPORATE; } +/** + * Whether the provided policyType is a Free, Collect or Control policy type + */ +function isGroupPolicy(policyType: string): boolean { + return policyType === CONST.POLICY.TYPE.CORPORATE || policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.FREE; +} + /** * Whether the provided report belongs to a Free, Collect or Control policy */ -function isGroupPolicy(report: OnyxEntry): boolean { +function isReportInGroupPolicy(report: OnyxEntry): boolean { const policyType = getPolicyType(report, allPolicies); - return policyType === CONST.POLICY.TYPE.CORPORATE || policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.FREE; + return isGroupPolicy(policyType); } /** @@ -1421,7 +1428,7 @@ function canAddOrDeleteTransactions(moneyRequestReport: OnyxEntry): bool return false; } - if (isGroupPolicy(moneyRequestReport) && isProcessingReport(moneyRequestReport) && !PolicyUtils.isInstantSubmitEnabled(getPolicy(moneyRequestReport?.policyID))) { + if (isReportInGroupPolicy(moneyRequestReport) && isProcessingReport(moneyRequestReport) && !PolicyUtils.isInstantSubmitEnabled(getPolicy(moneyRequestReport?.policyID))) { return false; } @@ -3186,11 +3193,11 @@ function getParsedComment(text: string, parsingDetails?: ParsingDetails): string let isGroupPolicyReport = false; if (parsingDetails?.reportID) { const currentReport = getReport(parsingDetails?.reportID); - isGroupPolicyReport = currentReport && !isEmptyObject(currentReport) ? isGroupPolicy(currentReport) : false; + isGroupPolicyReport = isReportInGroupPolicy(currentReport); } if (parsingDetails?.policyID) { const policyType = getPolicy(parsingDetails?.policyID).type; - isGroupPolicyReport = policyType === CONST.POLICY.TYPE.CORPORATE || policyType === CONST.POLICY.TYPE.TEAM || policyType === CONST.POLICY.TYPE.FREE; + isGroupPolicyReport = isGroupPolicy(policyType); } const parser = new ExpensiMark(); @@ -5161,7 +5168,7 @@ function canRequestMoney(report: OnyxEntry, policy: OnyxEntry, o // which is tied to their workspace chat. if (isMoneyRequestReport(report)) { const canAddTransactions = canAddOrDeleteTransactions(report); - return isGroupPolicy(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions; + return isReportInGroupPolicy(report) ? isOwnPolicyExpenseChat && canAddTransactions : canAddTransactions; } // In the case of policy expense chat, users can only submit expenses from their own policy expense chat @@ -6027,7 +6034,7 @@ function canBeAutoReimbursed(report: OnyxEntry, policy: OnyxEntry= reimbursableTotal && reimbursableTotal > 0 && @@ -6385,7 +6392,7 @@ export { isExpensifyOnlyParticipantInReport, isGroupChat, isGroupChatAdmin, - isGroupPolicy, + isReportInGroupPolicy, isHoldCreator, isIOUOwnedByCurrentUser, isIOUReport, @@ -6463,4 +6470,5 @@ export type { OptimisticTaskReportAction, OptionData, TransactionDetails, + ParsingDetails, }; diff --git a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx index 75d0c703b5b1..5bfa2475ee23 100644 --- a/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx +++ b/src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx @@ -461,7 +461,7 @@ function ReportActionCompose({ if (value.length === 0 && isComposerFullSize) { Report.setIsComposerFullSize(reportID, false); } - validateCommentMaxLength(value); + validateCommentMaxLength(value, {reportID}); }} /> { - validateCommentMaxLength(draft); - }, [draft, validateCommentMaxLength]); + validateCommentMaxLength(draft, {reportID}); + }, [draft, reportID, validateCommentMaxLength]); return ( <> diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index a571192f7a47..4b34a6a19600 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -73,7 +73,7 @@ function IOURequestStepCategory({ // The transactionCategory can be an empty string, so to maintain the logic we'd like to keep it in this shape until utils refactor // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const shouldShowCategory = ReportUtils.isGroupPolicy(report) && (!!transactionCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {}))); + const shouldShowCategory = ReportUtils.isReportInGroupPolicy(report) && (!!transactionCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {}))); const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; const canEditSplitBill = isSplitBill && reportAction && session?.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction); diff --git a/src/pages/iou/request/step/IOURequestStepMerchant.tsx b/src/pages/iou/request/step/IOURequestStepMerchant.tsx index b50495ac47bd..bc6f71b23228 100644 --- a/src/pages/iou/request/step/IOURequestStepMerchant.tsx +++ b/src/pages/iou/request/step/IOURequestStepMerchant.tsx @@ -63,7 +63,7 @@ function IOURequestStepMerchant({ const merchant = ReportUtils.getTransactionDetails(isEditingSplitBill && !isEmptyObject(splitDraftTransaction) ? splitDraftTransaction : transaction)?.merchant; const isEmptyMerchant = merchant === '' || merchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; - const isMerchantRequired = ReportUtils.isGroupPolicy(report) || transaction?.participants?.some((participant) => Boolean(participant.isPolicyExpenseChat)); + const isMerchantRequired = ReportUtils.isReportInGroupPolicy(report) || transaction?.participants?.some((participant) => Boolean(participant.isPolicyExpenseChat)); const navigateBack = () => { Navigation.goBack(backTo); }; diff --git a/src/pages/iou/request/step/IOURequestStepTag.tsx b/src/pages/iou/request/step/IOURequestStepTag.tsx index a62720cbd13a..ff1a1c01600d 100644 --- a/src/pages/iou/request/step/IOURequestStepTag.tsx +++ b/src/pages/iou/request/step/IOURequestStepTag.tsx @@ -77,7 +77,7 @@ function IOURequestStepTag({ const canEditSplitBill = isSplitBill && reportAction && session?.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction); const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); - const shouldShowTag = ReportUtils.isGroupPolicy(report) && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)); + const shouldShowTag = ReportUtils.isReportInGroupPolicy(report) && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)); // eslint-disable-next-line rulesdir/no-negated-variables const shouldShowNotFoundPage = !shouldShowTag || (isEditing && (isSplitBill ? !canEditSplitBill : reportAction && !canEditMoneyRequest(reportAction))); From 9114d95f4261594679f40a58ea653e5067121f24 Mon Sep 17 00:00:00 2001 From: war-in Date: Tue, 30 Apr 2024 10:49:31 +0200 Subject: [PATCH 6/6] remove sending from room/workspace descriptions --- src/libs/ReportUtils.ts | 14 ++++++++------ src/libs/actions/Policy.ts | 2 +- src/pages/iou/HoldReasonPage.tsx | 2 +- src/pages/workspace/WorkspaceNewRoomPage.tsx | 6 +++--- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 257e1a4478f6..7141cad8c245 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -477,7 +477,6 @@ type OutstandingChildRequest = { type ParsingDetails = { shouldEscapeText?: boolean; reportID?: string; - policyID?: string; }; let currentUserEmail: string | undefined; @@ -3307,10 +3306,6 @@ function getParsedComment(text: string, parsingDetails?: ParsingDetails): string const currentReport = getReport(parsingDetails?.reportID); isGroupPolicyReport = isReportInGroupPolicy(currentReport); } - if (parsingDetails?.policyID) { - const policyType = getPolicy(parsingDetails?.policyID).type; - isGroupPolicyReport = isGroupPolicy(policyType); - } const parser = new ExpensiMark(); const textWithMention = text.replace(CONST.REGEX.SHORT_MENTION, (match) => { @@ -3380,7 +3375,14 @@ function buildOptimisticInviteReportAction(invitedUserDisplayName: string, invit }; } -function buildOptimisticAddCommentReportAction(text?: string, file?: FileObject, actorAccountID?: number, createdOffset = 0, shouldEscapeText?: boolean, reportID?: string): OptimisticReportAction { +function buildOptimisticAddCommentReportAction( + text?: string, + file?: FileObject, + actorAccountID?: number, + createdOffset = 0, + shouldEscapeText?: boolean, + reportID?: string, +): OptimisticReportAction { const parser = new ExpensiMark(); const commentText = getParsedComment(text ?? '', {shouldEscapeText, reportID}); const isAttachmentOnly = file && !text; diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index f02091cbfd6d..8ae0e2257705 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1736,7 +1736,7 @@ function updateWorkspaceDescription(policyID: string, description: string, curre if (description === currentDescription) { return; } - const parsedDescription = ReportUtils.getParsedComment(description, {policyID}); + const parsedDescription = ReportUtils.getParsedComment(description); const optimisticData: OnyxUpdate[] = [ { diff --git a/src/pages/iou/HoldReasonPage.tsx b/src/pages/iou/HoldReasonPage.tsx index 93018fe34e5e..18b290a81ea4 100644 --- a/src/pages/iou/HoldReasonPage.tsx +++ b/src/pages/iou/HoldReasonPage.tsx @@ -49,7 +49,7 @@ function HoldReasonPage({route}: HoldReasonPageProps) { // We first check if the report is part of a policy - if not, then it's a personal request (1:1 request) // For personal requests, we need to allow both users to put the request on hold - const isWorkspaceRequest = ReportUtils.isGroupPolicy(report); + const isWorkspaceRequest = ReportUtils.isReportInGroupPolicy(report); const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? ''); const navigateBack = () => { diff --git a/src/pages/workspace/WorkspaceNewRoomPage.tsx b/src/pages/workspace/WorkspaceNewRoomPage.tsx index 6034b3b9fffc..5716812ced16 100644 --- a/src/pages/workspace/WorkspaceNewRoomPage.tsx +++ b/src/pages/workspace/WorkspaceNewRoomPage.tsx @@ -105,7 +105,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli */ const submit = (values: FormOnyxValues) => { const participants = [session?.accountID ?? 0]; - const parsedDescription = ReportUtils.getParsedComment(values.reportDescription ?? '', {policyID}); + const parsedDescription = ReportUtils.getParsedComment(values.reportDescription ?? ''); const policyReport = ReportUtils.buildOptimisticChatReport( participants, values.roomName, @@ -183,7 +183,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli ErrorUtils.addErrorMessage(errors, 'roomName', ['common.error.characterLimitExceedCounter', {length: values.roomName.length, limit: CONST.TITLE_CHARACTER_LIMIT}]); } - const descriptionLength = ReportUtils.getCommentLength(values.reportDescription, {policyID}); + const descriptionLength = ReportUtils.getCommentLength(values.reportDescription); if (descriptionLength > CONST.REPORT_DESCRIPTION.MAX_LENGTH) { ErrorUtils.addErrorMessage(errors, 'reportDescription', [ 'common.error.characterLimitExceedCounter', @@ -197,7 +197,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli return errors; }, - [reports, policyID], + [reports], ); const writeCapabilityOptions = useMemo(