From ca5cf27957970b94436a47e53276f11dca002ac0 Mon Sep 17 00:00:00 2001 From: Vamsi Krishna <46787868+vamsikrishnamathala@users.noreply.github.com> Date: Thu, 20 Mar 2025 14:02:06 +0530 Subject: [PATCH] [WEB-3262]fix: incomplete activity render for activity in notifications (#6777) * fix: incomplete activity render for activity in notifications * fix: handled content overflow for long notification messages --- .../sidebar/notification-card/content.tsx | 109 ++++++++++++++++++ .../sidebar/notification-card/index.ts | 1 + .../sidebar/notification-card/item.tsx | 66 ++--------- 3 files changed, 122 insertions(+), 54 deletions(-) create mode 100644 web/core/components/workspace-notifications/sidebar/notification-card/content.tsx diff --git a/web/core/components/workspace-notifications/sidebar/notification-card/content.tsx b/web/core/components/workspace-notifications/sidebar/notification-card/content.tsx new file mode 100644 index 000000000..ecdded0cf --- /dev/null +++ b/web/core/components/workspace-notifications/sidebar/notification-card/content.tsx @@ -0,0 +1,109 @@ +import { FC } from "react"; +import { TNotification } from "@plane/types"; +// components +import { LiteTextReadOnlyEditor } from "@/components/editor"; +// helpers +import { renderFormattedDate } from "@/helpers/date-time.helper"; +import { sanitizeCommentForNotification } from "@/helpers/notification.helper"; +import { replaceUnderscoreIfSnakeCase, stripAndTruncateHTML } from "@/helpers/string.helper"; + +export const NotificationContent: FC<{ + notification: TNotification; + workspaceId: string; + workspaceSlug: string; + projectId: string; + renderCommentBox?: boolean; +}> = ({ notification, workspaceId, workspaceSlug, projectId, renderCommentBox = false }) => { + const { data, triggered_by_details: triggeredBy } = notification; + const notificationField = data?.issue_activity.field; + const newValue = data?.issue_activity.new_value; + const oldValue = data?.issue_activity.old_value; + const verb = data?.issue_activity.verb; + + const renderTriggerName = () => ( + + {triggeredBy?.is_bot ? triggeredBy.first_name : triggeredBy?.display_name}{" "} + + ); + + const renderAction = () => { + if (!notificationField) return ""; + if (notificationField === "duplicate") + return verb === "created" + ? "marked that this work item is a duplicate of" + : "marked that this work item is not a duplicate"; + if (notificationField === "assignees") { + return newValue !== "" ? "added assignee" : "removed assignee"; + } + if (notificationField === "start_date") { + return newValue !== "" ? "set start date" : "removed the start date"; + } + if (notificationField === "target_date") { + return newValue !== "" ? "set due date" : "removed the due date"; + } + if (notificationField === "labels") { + return newValue !== "" ? "added label" : "removed label"; + } + if (notificationField === "parent") { + return newValue !== "" ? "added parent" : "removed parent"; + } + if (notificationField === "relates_to") return "marked that this work item is related to"; + if (notificationField === "comment") return "commented"; + if (notificationField === "archived_at") { + return newValue === "restore" ? "restored the work item" : "archived the work item"; + } + if (notificationField === "None") return null; + + const baseAction = !["comment", "archived_at"].includes(notificationField) ? verb : ""; + return `${baseAction} ${replaceUnderscoreIfSnakeCase(notificationField)}`; + }; + + const renderValue = () => { + if (notificationField === "None") return "the work item and assigned it to you."; + if (notificationField === "comment") return renderCommentBox ? null : sanitizeCommentForNotification(newValue); + if (notificationField === "target_date" || notificationField === "start_date") return renderFormattedDate(newValue); + if (notificationField === "attachment") return "the work item"; + if (notificationField === "description") return stripAndTruncateHTML(newValue || "", 55); + if (notificationField === "archived_at") return null; + if (notificationField === "assignees") return newValue !== "" ? newValue : oldValue; + if (notificationField === "labels") return newValue !== "" ? newValue : oldValue; + if (notificationField === "parent") return newValue !== "" ? newValue : oldValue; + return newValue; + }; + + const shouldShowConnector = ![ + "comment", + "archived_at", + "None", + "assignees", + "labels", + "start_date", + "target_date", + "parent", + ].includes(notificationField || ""); + + return ( + <> + {renderTriggerName()} + {renderAction()} + {verb !== "deleted" && ( + <> + {shouldShowConnector && to } + {renderValue()} + {notificationField === "comment" && renderCommentBox && ( +