From ad8a011bb9ff7938e787c3024ac5d93b5f4bd446 Mon Sep 17 00:00:00 2001
From: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com>
Date: Mon, 11 Sep 2023 11:44:16 +0530
Subject: [PATCH] fix: issue activity (#2127)
---
web/components/web-view/activity-message.tsx | 419 ++++++++++++++++++
web/components/web-view/index.ts | 1 +
web/components/web-view/issue-activity.tsx | 21 +-
.../web-view/issue-web-view-form.tsx | 2 +-
web/components/web-view/web-view-modal.tsx | 2 +-
web/layouts/web-view-layout/index.tsx | 5 +-
6 files changed, 435 insertions(+), 15 deletions(-)
create mode 100644 web/components/web-view/activity-message.tsx
diff --git a/web/components/web-view/activity-message.tsx b/web/components/web-view/activity-message.tsx
new file mode 100644
index 000000000..956dfb904
--- /dev/null
+++ b/web/components/web-view/activity-message.tsx
@@ -0,0 +1,419 @@
+import { useRouter } from "next/router";
+
+// icons
+import { Icon, Tooltip } from "components/ui";
+import { Squares2X2Icon } from "@heroicons/react/24/outline";
+import { BlockedIcon, BlockerIcon } from "components/icons";
+// helpers
+import { renderShortDateWithYearFormat } from "helpers/date-time.helper";
+import { capitalizeFirstLetter } from "helpers/string.helper";
+// types
+import { IIssueActivity } from "types";
+
+const IssueLink = ({ activity }: { activity: IIssueActivity }) => (
+
+
+
+);
+
+const UserLink = ({ activity }: { activity: IIssueActivity }) => (
+
+);
+
+const activityDetails: {
+ [key: string]: {
+ message: (
+ activity: IIssueActivity,
+ showIssue: boolean,
+ workspaceSlug: string
+ ) => React.ReactNode;
+ icon: React.ReactNode;
+ };
+} = {
+ assignees: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.old_value === "" ? "added a new assignee " : "removed the assignee "}
+
+ {showIssue && (
+ <>
+ {" "}
+ to
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ archived_at: {
+ message: (activity) => {
+ if (activity.new_value === "restore") return "restored the issue.";
+ else return "archived the issue.";
+ },
+ icon: ,
+ },
+
+ attachment: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.verb === "created" ? "uploaded a new " : "removed an "}
+ {activity.new_value && activity.new_value !== "" ? (
+
+ ) : (
+ "attachment"
+ )}
+ {showIssue && activity.verb === "created" ? " to " : " from "}
+ {showIssue && }
+ >
+ ),
+ icon: ,
+ },
+
+ blocking: {
+ message: (activity) => (
+ <>
+ {activity.old_value === ""
+ ? "marked this issue is blocking issue "
+ : "removed the blocking issue "}
+
+ {activity.old_value === "" ? activity.new_value : activity.old_value}
+
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ blocks: {
+ message: (activity) => (
+ <>
+ {activity.old_value === ""
+ ? "marked this issue is being blocked by issue "
+ : "removed this issue being blocked by issue "}
+
+ {activity.old_value === "" ? activity.new_value : activity.old_value}
+
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ cycles: {
+ message: (activity) => (
+ <>
+ {activity.verb === "created" && "added this issue to the cycle "}
+ {activity.verb === "updated" && "set the cycle to "}
+ {activity.verb === "deleted" && "removed the issue from the cycle "}
+
+ >
+ ),
+ icon: ,
+ },
+
+ description: {
+ message: (activity, showIssue) => (
+ <>
+ updated the description
+ {showIssue && (
+ <>
+ {" "}
+ of
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ estimate_point: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.new_value ? "set the estimate point to " : "removed the estimate point "}
+ {activity.new_value && (
+ {activity.new_value}
+ )}
+ {showIssue && (
+ <>
+ {" "}
+ for
+ >
+ )}
+ >
+ ),
+ icon: ,
+ },
+
+ issue: {
+ message: (activity) => {
+ if (activity.verb === "created") return "created the issue.";
+ else return "deleted an issue.";
+ },
+ icon: ,
+ },
+
+ labels: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.old_value === "" ? "added a new label " : "removed the label "}
+
+
+
+ {activity.old_value === "" ? activity.new_value : activity.old_value}
+
+
+ {showIssue && (
+ <>
+ {" "}
+ to
+ >
+ )}
+ >
+ ),
+ icon: ,
+ },
+
+ link: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.verb === "created" && "added this "}
+ {activity.verb === "updated" && "updated this "}
+ {activity.verb === "deleted" && "removed this "}
+
+ {showIssue && (
+ <>
+ {" "}
+ to
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ modules: {
+ message: (activity) => (
+ <>
+ {activity.verb === "created" && "added this "}
+ {activity.verb === "updated" && "updated this "}
+ {activity.verb === "deleted" && "removed this "}
+
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ name: {
+ message: (activity, showIssue) => (
+ <>
+ set the name to {activity.new_value}
+ {showIssue && (
+ <>
+ {" "}
+ of
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ parent: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.new_value ? "set the parent to " : "removed the parent "}
+
+ {activity.new_value ? activity.new_value : activity.old_value}
+
+ {showIssue && (
+ <>
+ {" "}
+ for
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ priority: {
+ message: (activity, showIssue) => (
+ <>
+ set the priority to{" "}
+
+ {activity.new_value ? capitalizeFirstLetter(activity.new_value) : "None"}
+
+ {showIssue && (
+ <>
+ {" "}
+ for
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ start_date: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.new_value ? "set the start date to " : "removed the start date "}
+
+ {activity.new_value ? renderShortDateWithYearFormat(activity.new_value) : "None"}
+
+ {showIssue && (
+ <>
+ {" "}
+ for
+ >
+ )}
+ >
+ ),
+ icon: ,
+ },
+
+ state: {
+ message: (activity, showIssue) => (
+ <>
+ set the state to{" "}
+ {activity.new_value}
+ {showIssue && (
+ <>
+ {" "}
+ for
+ >
+ )}
+ .
+ >
+ ),
+ icon: ,
+ },
+
+ target_date: {
+ message: (activity, showIssue) => (
+ <>
+ {activity.new_value ? "set the target date to " : "removed the target date "}
+ {activity.new_value && (
+
+ {renderShortDateWithYearFormat(activity.new_value)}
+
+ )}
+
+ {showIssue && (
+ <>
+ {" "}
+ for
+ >
+ )}
+ >
+ ),
+ icon: ,
+ },
+};
+
+export const ActivityIcon = ({ activity }: { activity: IIssueActivity }) => (
+ <>{activityDetails[activity.field as keyof typeof activityDetails]?.icon}>
+);
+
+export const ActivityMessage = ({
+ activity,
+ showIssue = false,
+}: {
+ activity: IIssueActivity;
+ showIssue?: boolean;
+}) => {
+ const router = useRouter();
+ const { workspaceSlug } = router.query;
+
+ return (
+ <>
+ {activityDetails[activity.field as keyof typeof activityDetails]?.message(
+ activity,
+ showIssue,
+ workspaceSlug?.toString() ?? ""
+ )}
+ >
+ );
+};
diff --git a/web/components/web-view/index.ts b/web/components/web-view/index.ts
index 342bc4838..915c891a9 100644
--- a/web/components/web-view/index.ts
+++ b/web/components/web-view/index.ts
@@ -15,3 +15,4 @@ export * from "./add-comment";
export * from "./select-parent";
export * from "./select-blocker";
export * from "./select-blocked";
+export * from "./activity-message";
diff --git a/web/components/web-view/issue-activity.tsx b/web/components/web-view/issue-activity.tsx
index 55089d60d..4bd13eb5c 100644
--- a/web/components/web-view/issue-activity.tsx
+++ b/web/components/web-view/issue-activity.tsx
@@ -2,7 +2,6 @@
import React from "react";
// next
-import Link from "next/link";
import { useRouter } from "next/router";
// swr
@@ -16,12 +15,10 @@ import issuesService from "services/issues.service";
// hooks
import useUser from "hooks/use-user";
-import useToast from "hooks/use-toast";
// components
-import { Label, AddComment } from "components/web-view";
import { CommentCard } from "components/issues/comment";
-import { ActivityIcon, ActivityMessage } from "components/core";
+import { Label, AddComment, ActivityMessage, ActivityIcon } from "components/web-view";
// helpers
import { timeAgo } from "helpers/date-time.helper";
@@ -183,15 +180,15 @@ export const IssueActivity: React.FC = (props) => {
{activityItem.actor_detail.first_name} Bot
) : (
- console.log("user", activityItem.actor)}
>
-
- {activityItem.actor_detail.is_bot
- ? activityItem.actor_detail.first_name
- : activityItem.actor_detail.display_name}
-
-
+ {activityItem.actor_detail.is_bot
+ ? activityItem.actor_detail.first_name
+ : activityItem.actor_detail.display_name}
+
)}{" "}
{message}{" "}
diff --git a/web/components/web-view/issue-web-view-form.tsx b/web/components/web-view/issue-web-view-form.tsx
index 863464764..ff9383fd0 100644
--- a/web/components/web-view/issue-web-view-form.tsx
+++ b/web/components/web-view/issue-web-view-form.tsx
@@ -90,7 +90,7 @@ export const IssueWebViewForm: React.FC = (props) => {
debouncedTitleSave();
}}
required={true}
- className="min-h-10 block w-full resize-none overflow-hidden rounded border-none bg-transparent px-3 py-2 text-xl outline-none ring-0 focus:ring-1 focus:ring-custom-primary"
+ className="min-h-10 block w-full resize-none overflow-hidden rounded border bg-transparent px-3 py-2 text-xl outline-none ring-0 focus:ring-1 focus:ring-custom-primary"
role="textbox"
disabled={!isAllowed}
/>
diff --git a/web/components/web-view/web-view-modal.tsx b/web/components/web-view/web-view-modal.tsx
index 2be28a01c..39769dfcd 100644
--- a/web/components/web-view/web-view-modal.tsx
+++ b/web/components/web-view/web-view-modal.tsx
@@ -63,7 +63,7 @@ export const WebViewModal = (props: Props) => {
- {children}
+ {children}
diff --git a/web/layouts/web-view-layout/index.tsx b/web/layouts/web-view-layout/index.tsx
index c5afdcc3d..2fb46b9df 100644
--- a/web/layouts/web-view-layout/index.tsx
+++ b/web/layouts/web-view-layout/index.tsx
@@ -18,7 +18,10 @@ type Props = {
};
const getIfInWebview = (userAgent: NavigatorID["userAgent"]) => {
- if (/iphone|ipod|ipad/.test(userAgent) || userAgent.includes("wv")) return true;
+ const safari = /safari/.test(userAgent);
+
+ if (safari) return false;
+ else if (/iphone|ipod|ipad/.test(userAgent) || userAgent.includes("wv")) return true;
else return false;
};