style: redesign issue activity (#579)

* style: redesign the activity feed and refactor the code

* chore: remove console logs

* revert: back to remirror rich text editor

* style: make icons, text smaller and reduce the spacing between logs
This commit is contained in:
Saheb Giri 2023-03-29 19:19:37 +05:30 committed by GitHub
parent b441a2ce20
commit 7337707a4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 250 additions and 206 deletions

View File

@ -24,8 +24,8 @@ import { BlockedIcon, BlockerIcon, CyclesIcon, TagIcon, UserGroupIcon } from "co
import { renderShortNumericDateFormat, timeAgo } from "helpers/date-time.helper"; import { renderShortNumericDateFormat, timeAgo } from "helpers/date-time.helper";
import { addSpaceIfCamelCase } from "helpers/string.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper";
// types // types
import { IIssueComment } from "types"; import { IIssueComment, IIssueLabels } from "types";
import { PROJECT_ISSUES_ACTIVITY } from "constants/fetch-keys"; import { PROJECT_ISSUES_ACTIVITY, PROJECT_ISSUE_LABELS } from "constants/fetch-keys";
const activityDetails: { const activityDetails: {
[key: string]: { [key: string]: {
@ -35,54 +35,54 @@ const activityDetails: {
} = { } = {
assignee: { assignee: {
message: "removed the assignee", message: "removed the assignee",
icon: <UserGroupIcon className="h-4 w-4" />, icon: <UserGroupIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
assignees: { assignees: {
message: "added a new assignee", message: "added a new assignee",
icon: <UserGroupIcon className="h-4 w-4" />, icon: <UserGroupIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
blocks: { blocks: {
message: "marked this issue being blocked by", message: "marked this issue being blocked by",
icon: <BlockedIcon height="16" width="16" />, icon: <BlockedIcon height="12" width="12" className="fill-gray-500" />,
}, },
blocking: { blocking: {
message: "marked this issue is blocking", message: "marked this issue is blocking",
icon: <BlockerIcon height="16" width="16" />, icon: <BlockerIcon height="12" width="12" />,
}, },
cycles: { cycles: {
message: "set the cycle to", message: "set the cycle to",
icon: <CyclesIcon height="16" width="16" />, icon: <CyclesIcon height="12" width="12" />,
}, },
labels: { labels: {
icon: <TagIcon height="16" width="16" />, icon: <TagIcon height="12" width="12" />,
}, },
modules: { modules: {
message: "set the module to", message: "set the module to",
icon: <RectangleGroupIcon className="h-4 w-4" />, icon: <RectangleGroupIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
state: { state: {
message: "set the state to", message: "set the state to",
icon: <Squares2X2Icon className="h-4 w-4" />, icon: <Squares2X2Icon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
priority: { priority: {
message: "set the priority to", message: "set the priority to",
icon: <ChartBarIcon className="h-4 w-4" />, icon: <ChartBarIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
name: { name: {
message: "set the name to", message: "set the name to",
icon: <ChatBubbleBottomCenterTextIcon className="h-4 w-4" />, icon: <ChatBubbleBottomCenterTextIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
description: { description: {
message: "updated the description.", message: "updated the description.",
icon: <ChatBubbleBottomCenterTextIcon className="h-4 w-4" />, icon: <ChatBubbleBottomCenterTextIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
target_date: { target_date: {
message: "set the due date to", message: "set the due date to",
icon: <CalendarDaysIcon className="h-4 w-4" />, icon: <CalendarDaysIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
parent: { parent: {
message: "set the parent to", message: "set the parent to",
icon: <UserIcon className="h-4 w-4" />, icon: <UserIcon className="h-3 w-3 text-gray-500" aria-hidden="true" />,
}, },
}; };
@ -104,6 +104,13 @@ export const IssueActivitySection: React.FC<Props> = () => {
: null : null
); );
const { data: issueLabels } = useSWR<IIssueLabels[]>(
projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null,
workspaceSlug && projectId
? () => issuesService.getIssueLabels(workspaceSlug as string, projectId as string)
: null
);
const handleCommentUpdate = async (comment: IIssueComment) => { const handleCommentUpdate = async (comment: IIssueComment) => {
if (!workspaceSlug || !projectId || !issueId) return; if (!workspaceSlug || !projectId || !issueId) return;
await issuesService await issuesService
@ -134,140 +141,171 @@ export const IssueActivitySection: React.FC<Props> = () => {
}); });
}; };
const getLabelColor = (labelId: string) => {
if (!issueLabels) return;
const label = issueLabels.find((label) => label.id === labelId);
if (typeof label !== "undefined") {
return label.color;
}
return "#64748b";
};
if (!issueActivities) {
return (
<Loader className="space-y-4">
<div className="space-y-2">
<Loader.Item height="30px" width="40%" />
<Loader.Item height="15px" width="60%" />
</div>
<div className="space-y-2">
<Loader.Item height="30px" width="40%" />
<Loader.Item height="15px" width="60%" />
</div>
<div className="space-y-2">
<Loader.Item height="30px" width="40%" />
<Loader.Item height="15px" width="60%" />
</div>
</Loader>
);
}
return ( return (
<> <div className="flow-root">
{issueActivities ? ( <ul role="list" className="-mb-8">
<div className="space-y-4"> {issueActivities.map((activityItem, activityItemIdx) => {
{issueActivities.map((activity, index) => { // determines what type of action is performed
if ("field" in activity && activity.field !== "updated_by") { let action = activityDetails[activityItem.field as keyof typeof activityDetails]?.message;
return ( if (activityItem.field === "labels") {
<div key={activity.id} className="relative flex w-full items-center gap-x-2"> action = activityItem.new_value !== "" ? "added a new label" : "removed the label";
{issueActivities.length > 1 && index !== issueActivities.length - 1 ? ( } else if (activityItem.field === "blocking") {
action =
activityItem.new_value !== ""
? "marked this issue is blocking"
: "removed the issue from blocking";
} else if (activityItem.field === "blocks") {
action =
activityItem.new_value !== ""
? "marked this issue being blocked by"
: "removed blocker";
} else if (activityItem.field === "target_date") {
action =
activityItem.new_value && activityItem.new_value !== ""
? "set the due date to"
: "removed the due date";
}
// for values that are after the action clause
let value: any = activityItem.new_value ? activityItem.new_value : activityItem.old_value;
if (
activityItem.verb === "created" &&
activityItem.field !== "cycles" &&
activityItem.field !== "modules"
) {
value = <span className="text-gray-600">created this issue.</span>;
} else if (activityItem.field === "state") {
value = activityItem.new_value ? addSpaceIfCamelCase(activityItem.new_value) : "None";
} else if (activityItem.field === "labels") {
let name,
id = "#64748b";
if (activityItem.new_value !== "") {
name = activityItem.new_value;
id = activityItem.new_identifier ? activityItem.new_identifier : id;
} else {
name = activityItem.old_value;
id = activityItem.old_identifier ? activityItem.old_identifier : id;
}
value = (
<span className="relative inline-flex items-center rounded-full px-2.5 py-1 text-xs ring-1 ring-inset ring-gray-300 hover:bg-gray-50">
<span className="absolute flex flex-shrink-0 items-center justify-center">
<span
className="h-1.5 w-1.5 rounded-full"
style={{
backgroundColor: getLabelColor(id),
}}
aria-hidden="true"
/>
</span>
<span className="ml-3 font-medium text-gray-900">{name}</span>
</span>
);
} else if (activityItem.field === "assignees") {
value = activityItem.new_value;
} else if (activityItem.field === "target_date") {
value = renderShortNumericDateFormat(activityItem.new_value as string);
} else if (activityItem.field === "description") {
value = "";
}
if ("field" in activityItem && activityItem.field !== "updated_by") {
return (
<li key={activityItem.id}>
<div className="relative pb-3">
{issueActivities.length > 1 && activityItemIdx !== issueActivities.length - 1 ? (
<span <span
className="absolute top-5 left-2.5 h-full w-0.5 bg-gray-200" className="absolute top-5 left-5 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true" aria-hidden="true"
/> />
) : null} ) : null}
{activity.field ? ( <div className="relative flex items-start space-x-2">
<div className="relative z-10 -ml-1 flex-shrink-0"> <>
<div className="grid h-8 w-8 place-items-center bg-white"> <div>
{activityDetails[activity.field as keyof typeof activityDetails]?.icon} <div className="relative px-1.5">
</div> <div className="mt-1.5">
</div> <div className="ring-6 flex h-7 w-7 items-center justify-center rounded-full bg-gray-100 ring-white">
) : ( {activityItem.field ? (
<div className="relative z-10 -ml-4 flex-shrink-0 rounded-full border-2 border-white"> activityDetails[activityItem.field as keyof typeof activityDetails]
<div className="grid h-12 w-12 place-items-center"> ?.icon
{activity.actor_detail.avatar && activity.actor_detail.avatar !== "" ? ( ) : activityItem.actor_detail.avatar &&
<Image activityItem.actor_detail.avatar !== "" ? (
src={activity.actor_detail.avatar} <Image
alt={activity.actor_detail.first_name} src={activityItem.actor_detail.avatar}
height={30} alt={activityItem.actor_detail.first_name}
width={30} height={24}
className="rounded-full" width={24}
/> className="rounded-full"
) : ( />
<div ) : (
className={`grid h-8 w-8 place-items-center rounded-full border-2 border-white bg-gray-700 text-white`} <div
> className={`grid h-7 w-7 place-items-center rounded-full border-2 border-white bg-gray-700 text-xs text-white`}
{activity.actor_detail.first_name.charAt(0)} >
{activityItem.actor_detail.first_name.charAt(0)}
</div>
)}
</div>
</div> </div>
)} </div>
</div> </div>
</div> <div className="min-w-0 flex-1 py-3">
)} <div className="text-xs text-gray-500">
<span className="text-gray font-medium">
<div className={`${activity.field ? "ml-1.5" : ""} w-full text-xs`}> {activityItem.actor_detail.first_name}
<p> {activityItem.actor_detail.is_bot
<span className="font-medium"> ? " Bot"
{activity.actor_detail.first_name} : " " + activityItem.actor_detail.last_name}
{activity.actor_detail.is_bot </span>
? " Bot" <span> {action} </span>
: " " + activity.actor_detail.last_name} <span className="text-xs font-medium text-gray-900"> {value} </span>
</span> <span className="whitespace-nowrap">
<span> {timeAgo(activityItem.created_at)}
{" "} </span>
{activity.field === "labels" </div>
? activity.new_value !== "" </div>
? "added a new label" </>
: "removed the label"
: activity.field === "blocking"
? activity.new_value !== ""
? "marked this issue is blocking"
: "removed the issue from blocking"
: activity.field === "blocks"
? activity.new_value !== ""
? "marked this issue being blocked by"
: "removed blocker"
: activity.field === "target_date"
? activity.new_value && activity.new_value !== ""
? "set the due date to"
: "removed the due date"
: activityDetails[activity.field as keyof typeof activityDetails]
?.message}{" "}
</span>
<span className="font-medium">
{activity.verb === "created" &&
activity.field !== "cycles" &&
activity.field !== "modules" ? (
<span className="text-gray-600">created this issue.</span>
) : activity.field === "description" ? null : activity.field === "state" ? (
activity.new_value ? (
addSpaceIfCamelCase(activity.new_value)
) : (
"None"
)
) : activity.field === "labels" ||
activity.field === "blocking" ||
activity.field === "blocks" ? (
activity.new_value !== "" ? (
activity.new_value
) : (
activity.old_value
)
) : activity.field === "assignee" ? (
activity.old_value
) : activity.field === "target_date" ? (
activity.new_value ? (
renderShortNumericDateFormat(activity.new_value as string)
) : null
) : activity.field === "description" ? (
""
) : (
activity.new_value ?? "None"
)}
</span>
<span className="ml-2 text-gray-500">{timeAgo(activity.created_at)}</span>
</p>
</div> </div>
</div> </div>
); </li>
} else if ("comment_json" in activity) );
return ( } else if ("comment_json" in activityItem)
<CommentCard return (
key={activity.id} <CommentCard
comment={activity as any} key={activityItem.id}
onSubmit={handleCommentUpdate} comment={activityItem as any}
handleCommentDeletion={handleCommentDelete} onSubmit={handleCommentUpdate}
/> handleCommentDeletion={handleCommentDelete}
); />
})} );
</div> })}
) : ( </ul>
<Loader className="space-y-4"> </div>
<div className="space-y-2">
<Loader.Item height="30px" width="40%" />
<Loader.Item height="15px" width="60%" />
</div>
<div className="space-y-2">
<Loader.Item height="30px" width="40%" />
<Loader.Item height="15px" width="60%" />
</div>
<div className="space-y-2">
<Loader.Item height="30px" width="40%" />
<Loader.Item height="15px" width="60%" />
</div>
</Loader>
)}
</>
); );
}; };

View File

@ -6,7 +6,7 @@ import dynamic from "next/dynamic";
// react-hook-form // react-hook-form
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
// icons // icons
import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ChatBubbleLeftEllipsisIcon, CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
// hooks // hooks
import useUser from "hooks/use-user"; import useUser from "hooks/use-user";
// ui // ui
@ -49,71 +49,77 @@ export const CommentCard: React.FC<Props> = ({ comment, onSubmit, handleCommentD
}, [isEditing, setFocus]); }, [isEditing, setFocus]);
return ( return (
<div className="-ml-1 flex h-full w-full justify-between"> <div className="relative flex items-start space-x-3">
<div className="flex w-full gap-x-4"> <div className="relative px-1">
<div className="flex-shrink-0"> {comment.actor_detail.avatar && comment.actor_detail.avatar !== "" ? (
{comment.actor_detail.avatar && comment.actor_detail.avatar !== "" ? ( <Image
<Image src={comment.actor_detail.avatar}
src={comment.actor_detail.avatar} alt={comment.actor_detail.first_name}
alt={comment.actor_detail.first_name} height={30}
height={30} width={30}
width={30} className="grid h-7 w-7 place-items-center rounded-full border-2 border-white bg-gray-500 text-white"
className="rounded-full" />
/> ) : (
) : ( <div
<div className={`grid h-7 w-7 place-items-center rounded-full border-2 border-white bg-gray-500 text-white`}
className={`grid h-8 w-8 place-items-center rounded-full border-2 border-white bg-gray-500 text-white`} >
> {comment.actor_detail.first_name.charAt(0)}
{comment.actor_detail.first_name.charAt(0)}
</div>
)}
</div>
<div className="w-full space-y-1">
<p className="flex items-center gap-2 text-xs text-gray-500">
<span>
{comment.actor_detail.first_name}
{comment.actor_detail.is_bot ? "Bot" : " " + comment.actor_detail.last_name}
</span>
<span>{timeAgo(comment.created_at)}</span>
</p>
<div className="issue-comments-section">
{isEditing ? (
<form className="flex flex-col gap-2" onSubmit={handleSubmit(onEnter)}>
<RemirrorRichTextEditor
value={comment.comment_html}
onBlur={(jsonValue, htmlValue) => {
setValue("comment_json", jsonValue);
setValue("comment_html", htmlValue);
}}
placeholder="Enter Your comment..."
/>
<div className="flex gap-1 self-end">
<button
type="submit"
disabled={isSubmitting}
className="group rounded border border-green-500 bg-green-100 p-2 shadow-md duration-300 hover:bg-green-500"
>
<CheckIcon className="h-3 w-3 text-green-500 duration-300 group-hover:text-white" />
</button>
<button
type="button"
className="group rounded border border-red-500 bg-red-100 p-2 shadow-md duration-300 hover:bg-red-500"
onClick={() => setIsEditing(false)}
>
<XMarkIcon className="h-3 w-3 text-red-500 duration-300 group-hover:text-white" />
</button>
</div>
</form>
) : (
<>
<RemirrorRichTextEditor
value={comment.comment_html}
editable={false}
onBlur={() => ({})}
/>
</>
)}
</div> </div>
)}
<span className="absolute -bottom-0.5 -right-1 rounded-tl bg-white px-0.5 py-px">
<ChatBubbleLeftEllipsisIcon className="h-3.5 w-3.5 text-gray-400" aria-hidden="true" />
</span>
</div>
<div className="min-w-0 flex-1">
<div>
<div className="text-xs">
{comment.actor_detail.first_name}
{comment.actor_detail.is_bot ? "Bot" : " " + comment.actor_detail.last_name}
</div>
<p className="mt-0.5 text-xs text-gray-500">Commented {timeAgo(comment.created_at)}</p>
</div>
<div className="issue-comments-section p-0">
{isEditing ? (
<form className="flex flex-col gap-2" onSubmit={handleSubmit(onEnter)}>
<RemirrorRichTextEditor
value={comment.comment_html}
onBlur={(jsonValue, htmlValue) => {
setValue("comment_json", jsonValue);
setValue("comment_html", htmlValue);
}}
placeholder="Enter Your comment..."
/>
<div className="flex gap-1 self-end">
<button
type="submit"
disabled={isSubmitting}
className="group rounded border border-green-500 bg-green-100 p-2 shadow-md duration-300 hover:bg-green-500"
>
<CheckIcon className="h-3 w-3 text-green-500 duration-300 group-hover:text-white" />
</button>
<button
type="button"
className="group rounded border border-red-500 bg-red-100 p-2 shadow-md duration-300 hover:bg-red-500"
onClick={() => setIsEditing(false)}
>
<XMarkIcon className="h-3 w-3 text-red-500 duration-300 group-hover:text-white" />
</button>
</div>
</form>
) : (
// <div
// className="mt-2 mb-6 text-sm text-gray-700"
// dangerouslySetInnerHTML={{ __html: comment.comment_html }}
// />
<RemirrorRichTextEditor
value={comment.comment_html}
editable={false}
onBlur={() => ({})}
noBorder
customClassName="text-xs bg-gray-100"
/>
)}
</div> </div>
</div> </div>
{user?.id === comment.actor && ( {user?.id === comment.actor && (