π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-2348] fix: allow updating comments with just mentions in them (#5471)
Aaryan Khandelwalbac5b53ffbcb
diff --git a/space/core/components/editor/lite-text-editor.tsx b/space/core/components/editor/lite-text-editor.tsxindex 3cc8347a17..186f44a101 100644--- a/space/core/components/editor/lite-text-editor.tsx+++ b/space/core/components/editor/lite-text-editor.tsx@@ -5,7 +5,7 @@ import { EditorRefApi, ILiteTextEditor, LiteTextEditorWithRef } from "@plane/ediimport { IssueCommentToolbar } from "@/components/editor";// helpersimport { cn } from "@/helpers/common.helper";-import { isEmptyHtmlString } from "@/helpers/string.helper";+import { isCommentEmpty } from "@/helpers/string.helper";// hooksimport { useMention } from "@/hooks/use-mention";// services@@ -33,10 +33,7 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrappfunction isMutableRefObject<T>(ref: React.ForwardedRef<T>): ref is React.MutableRefObject<T | null> {return !!ref && typeof ref === "object" && "current" in ref;}- const isEmpty =- props.initialValue?.trim() === "" ||- props.initialValue === "<p></p>" ||- (isEmptyHtmlString(props.initialValue ?? "") && !props.initialValue?.includes("mention-component"));+ const isEmpty = isCommentEmpty(props.initialValue);return (<div className="border border-custom-border-200 rounded p-3 space-y-3">diff --git a/space/helpers/string.helper.ts b/space/helpers/string.helper.tsindex fe7df96dae..6c60e4bb9f 100644--- a/space/helpers/string.helper.ts+++ b/space/helpers/string.helper.ts@@ -50,13 +50,29 @@ export const checkEmailValidity = (email: string): boolean => {return isEmailValid;};-export const isEmptyHtmlString = (htmlString: string) => {+export const isEmptyHtmlString = (htmlString: string, allowedHTMLTags: string[] = []) => {// Remove HTML tags using regex- const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: ["img"] });+ const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: allowedHTMLTags });// Trim the string and check if it's emptyreturn cleanText.trim() === "";};+/**+ * @description this function returns whether a comment is empty or not by checking for the following conditions-+ * 1. If comment is undefined+ * 2. If comment is an empty string+ * 3. If comment is "<p></p>"+ * @param {string | undefined} comment+ * @returns {boolean}+ */+export const isCommentEmpty = (comment: string | undefined): boolean => {+ // return true if comment is undefined+ if (!comment) return true;+ return (+ comment?.trim() === "" || comment === "<p></p>" || isEmptyHtmlString(comment ?? "", ["img", "mention-component"])+ );+};+export const replaceUnderscoreIfSnakeCase = (str: string) => str.replace(/_/g, " ");-export const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);\ No newline at end of file+export const capitalizeFirstLetter = (str: string) => str.charAt(0).toUpperCase() + str.slice(1);diff --git a/web/core/components/editor/lite-text-editor/lite-text-editor.tsx b/web/core/components/editor/lite-text-editor/lite-text-editor.tsxindex 4ded0e84c9..8036e4c8d4 100644--- a/web/core/components/editor/lite-text-editor/lite-text-editor.tsx+++ b/web/core/components/editor/lite-text-editor/lite-text-editor.tsx@@ -9,7 +9,7 @@ import { IssueCommentToolbar } from "@/components/editor";import { EIssueCommentAccessSpecifier } from "@/constants/issue";// helpersimport { cn } from "@/helpers/common.helper";-import { isEmptyHtmlString } from "@/helpers/string.helper";+import { isCommentEmpty } from "@/helpers/string.helper";// hooksimport { useMember, useMention, useUser } from "@/hooks/store";// services@@ -59,10 +59,7 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrappuser: currentUser ?? undefined,});- const isEmpty =- props.initialValue?.trim() === "" ||- props.initialValue === "<p></p>" ||- (isEmptyHtmlString(props.initialValue ?? "") && !props.initialValue?.includes("mention-component"));+ const isEmpty = isCommentEmpty(props.initialValue);function isMutableRefObject<T>(ref: React.ForwardedRef<T>): ref is React.MutableRefObject<T | null> {return !!ref && typeof ref === "object" && "current" in ref;diff --git a/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx b/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsxindex 798964365e..d9b77430ce 100644--- a/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx+++ b/web/core/components/issues/issue-detail/issue-activity/comments/comment-card.tsx@@ -13,7 +13,7 @@ import { LiteTextEditor, LiteTextReadOnlyEditor } from "@/components/editor";// constantsimport { EIssueCommentAccessSpecifier } from "@/constants/issue";// helpers-import { isEmptyHtmlString } from "@/helpers/string.helper";+import { isCommentEmpty } from "@/helpers/string.helper";// hooksimport { useIssueDetail, useUser, useWorkspace } from "@/hooks/store";// components@@ -80,10 +80,8 @@ export const IssueCommentCard: FC<TIssueCommentCard> = observer((props) => {isEditing && setFocus("comment_html");}, [isEditing, setFocus]);- const isEmpty =- watch("comment_html")?.trim() === "" ||- watch("comment_html") === "<p></p>" ||- isEmptyHtmlString(watch("comment_html") ?? "");+ const commentHTML = watch("comment_html");+ const isEmpty = isCommentEmpty(commentHTML);if (!comment || !currentUser) return <></>;return (@@ -148,7 +146,7 @@ export const IssueCommentCard: FC<TIssueCommentCard> = observer((props) => {workspaceSlug={workspaceSlug}ref={editorRef}id={comment.id}- initialValue={watch("comment_html") ?? ""}+ initialValue={commentHTML ?? ""}value={null}onChange={(comment_json, comment_html) => setValue("comment_html", comment_html)}onEnterKeyPress={(e) => {diff --git a/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx b/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsxindex d8c86ec182..c5013442f6 100644--- a/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx+++ b/web/core/components/issues/issue-detail/issue-activity/comments/comment-create.tsx@@ -8,7 +8,7 @@ import { LiteTextEditor } from "@/components/editor/lite-text-editor/lite-text-eimport { EIssueCommentAccessSpecifier } from "@/constants/issue";// helpersimport { cn } from "@/helpers/common.helper";-import { isEmptyHtmlString } from "@/helpers/string.helper";+import { isCommentEmpty } from "@/helpers/string.helper";// hooksimport { useIssueDetail, useWorkspace } from "@/hooks/store";// editor@@ -53,10 +53,7 @@ export const IssueCommentCreate: FC<TIssueCommentCreate> = (props) => {});const commentHTML = watch("comment_html");- const isEmpty =- commentHTML?.trim() === "" ||- commentHTML === "<p></p>" ||- (isEmptyHtmlString(commentHTML ?? "") && !commentHTML?.includes("mention-component"));+ const isEmpty = isCommentEmpty(commentHTML);return (<divdiff --git a/web/core/components/issues/issue-modal/draft-issue-layout.tsx b/web/core/components/issues/issue-modal/draft-issue-layout.tsxindex da8622dc8d..49bb1734de 100644--- a/web/core/components/issues/issue-modal/draft-issue-layout.tsx+++ b/web/core/components/issues/issue-modal/draft-issue-layout.tsx@@ -74,7 +74,7 @@ export const DraftIssueLayout: React.FC<DraftIssueProps> = observer((props) => {if (issueKey === "description_html" &&changesMade.description_html &&- isEmptyHtmlString(changesMade.description_html)+ isEmptyHtmlString(changesMade.description_html, ["img"]))delete changesMade.description_html;});diff --git a/web/helpers/string.helper.ts b/web/helpers/string.helper.tsindex 048c83ecd6..de0d8ac9d4 100644--- a/web/helpers/string.helper.ts+++ b/web/helpers/string.helper.ts@@ -230,9 +230,23 @@ export const checkEmailValidity = (email: string): boolean => {return isEmailValid;};-export const isEmptyHtmlString = (htmlString: string) => {+export const isEmptyHtmlString = (htmlString: string, allowedHTMLTags: string[] = []) => {// Remove HTML tags using regex- const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: ["img"] });+ const cleanText = DOMPurify.sanitize(htmlString, { ALLOWED_TAGS: allowedHTMLTags });// Trim the string and check if it's emptyreturn cleanText.trim() === "";};++/**+ * @description this function returns whether a comment is empty or not by checking for the following conditions-+ * 1. If comment is undefined+ * 2. If comment is an empty string+ * 3. If comment is "<p></p>"+ * @param {string | undefined} comment+ * @returns {boolean}+ */+export const isCommentEmpty = (comment: string | undefined): boolean => {+ // return true if comment is undefined+ if (!comment) return true;+ return comment?.trim() === "" || comment === "<p></p>" || isEmptyHtmlString(comment ?? "", ["mention-component"]);+};