2023-06-27 10:19:19 +00:00
|
|
|
import React, { useCallback, useState } from "react";
|
2023-06-23 11:50:05 +00:00
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import { mutate } from "swr";
|
|
|
|
|
|
|
|
// components
|
|
|
|
import {
|
|
|
|
ViewAssigneeSelect,
|
|
|
|
ViewDueDateSelect,
|
|
|
|
ViewEstimateSelect,
|
2023-07-25 06:37:16 +00:00
|
|
|
ViewIssueLabel,
|
2023-06-23 11:50:05 +00:00
|
|
|
ViewPrioritySelect,
|
|
|
|
ViewStateSelect,
|
|
|
|
} from "components/issues";
|
2023-06-27 10:19:19 +00:00
|
|
|
import { Popover2 } from "@blueprintjs/popover2";
|
2023-06-23 11:50:05 +00:00
|
|
|
// icons
|
2023-06-27 10:19:19 +00:00
|
|
|
import { Icon } from "components/ui";
|
|
|
|
import {
|
|
|
|
EllipsisHorizontalIcon,
|
|
|
|
LinkIcon,
|
|
|
|
PencilIcon,
|
|
|
|
TrashIcon,
|
|
|
|
} from "@heroicons/react/24/outline";
|
2023-06-23 11:50:05 +00:00
|
|
|
// hooks
|
|
|
|
import useSpreadsheetIssuesView from "hooks/use-spreadsheet-issues-view";
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
// constant
|
|
|
|
import {
|
2023-06-28 13:38:33 +00:00
|
|
|
CYCLE_DETAILS,
|
2023-06-23 11:50:05 +00:00
|
|
|
CYCLE_ISSUES_WITH_PARAMS,
|
2023-06-28 13:38:33 +00:00
|
|
|
MODULE_DETAILS,
|
2023-06-23 11:50:05 +00:00
|
|
|
MODULE_ISSUES_WITH_PARAMS,
|
|
|
|
PROJECT_ISSUES_LIST_WITH_PARAMS,
|
2023-06-24 12:39:06 +00:00
|
|
|
SUB_ISSUES,
|
2023-06-23 11:50:05 +00:00
|
|
|
VIEW_ISSUES,
|
|
|
|
} from "constants/fetch-keys";
|
|
|
|
// types
|
2023-06-24 12:39:06 +00:00
|
|
|
import { ICurrentUserResponse, IIssue, ISubIssueResponse, Properties, UserAuth } from "types";
|
2023-06-23 11:50:05 +00:00
|
|
|
// helper
|
|
|
|
import { copyTextToClipboard } from "helpers/string.helper";
|
2023-07-07 08:41:07 +00:00
|
|
|
import { renderLongDetailDateFormat } from "helpers/date-time.helper";
|
2023-06-23 11:50:05 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-06-28 11:57:43 +00:00
|
|
|
index: number;
|
2023-06-23 11:50:05 +00:00
|
|
|
expanded: boolean;
|
|
|
|
handleToggleExpand: (issueId: string) => void;
|
|
|
|
properties: Properties;
|
2023-06-23 19:05:43 +00:00
|
|
|
handleEditIssue: (issue: IIssue) => void;
|
2023-06-23 11:50:05 +00:00
|
|
|
handleDeleteIssue: (issue: IIssue) => void;
|
|
|
|
gridTemplateColumns: string;
|
2023-06-27 11:42:21 +00:00
|
|
|
isCompleted?: boolean;
|
2023-06-23 11:50:05 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
|
|
|
userAuth: UserAuth;
|
|
|
|
nestingLevel: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SingleSpreadsheetIssue: React.FC<Props> = ({
|
|
|
|
issue,
|
2023-06-28 11:57:43 +00:00
|
|
|
index,
|
2023-06-23 11:50:05 +00:00
|
|
|
expanded,
|
|
|
|
handleToggleExpand,
|
|
|
|
properties,
|
|
|
|
handleEditIssue,
|
|
|
|
handleDeleteIssue,
|
|
|
|
gridTemplateColumns,
|
2023-06-27 11:42:21 +00:00
|
|
|
isCompleted = false,
|
2023-06-23 11:50:05 +00:00
|
|
|
user,
|
|
|
|
userAuth,
|
|
|
|
nestingLevel,
|
|
|
|
}) => {
|
2023-06-27 10:19:19 +00:00
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
2023-06-23 11:50:05 +00:00
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const { workspaceSlug, projectId, cycleId, moduleId, viewId } = router.query;
|
|
|
|
|
|
|
|
const { params } = useSpreadsheetIssuesView();
|
|
|
|
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
const partialUpdateIssue = useCallback(
|
2023-06-24 12:39:06 +00:00
|
|
|
(formData: Partial<IIssue>, issue: IIssue) => {
|
2023-06-23 11:50:05 +00:00
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
|
|
|
const fetchKey = cycleId
|
|
|
|
? CYCLE_ISSUES_WITH_PARAMS(cycleId.toString(), params)
|
|
|
|
: moduleId
|
|
|
|
? MODULE_ISSUES_WITH_PARAMS(moduleId.toString(), params)
|
|
|
|
: viewId
|
|
|
|
? VIEW_ISSUES(viewId.toString(), params)
|
|
|
|
: PROJECT_ISSUES_LIST_WITH_PARAMS(projectId.toString(), params);
|
|
|
|
|
2023-06-24 12:39:06 +00:00
|
|
|
if (issue.parent) {
|
|
|
|
mutate<ISubIssueResponse>(
|
|
|
|
SUB_ISSUES(issue.parent.toString()),
|
|
|
|
(prevData) => {
|
|
|
|
if (!prevData) return prevData;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...prevData,
|
|
|
|
sub_issues: (prevData.sub_issues ?? []).map((i) => {
|
|
|
|
if (i.id === issue.id) {
|
|
|
|
return {
|
|
|
|
...i,
|
|
|
|
...formData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
mutate<IIssue[]>(
|
|
|
|
fetchKey,
|
|
|
|
(prevData) =>
|
|
|
|
(prevData ?? []).map((p) => {
|
|
|
|
if (p.id === issue.id) {
|
|
|
|
return {
|
|
|
|
...p,
|
|
|
|
...formData,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
2023-06-23 11:50:05 +00:00
|
|
|
|
|
|
|
issuesService
|
2023-06-24 12:39:06 +00:00
|
|
|
.patchIssue(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
issue.id as string,
|
|
|
|
formData,
|
|
|
|
user
|
|
|
|
)
|
2023-06-23 11:50:05 +00:00
|
|
|
.then(() => {
|
2023-06-26 08:54:52 +00:00
|
|
|
if (issue.parent) {
|
|
|
|
mutate(SUB_ISSUES(issue.parent as string));
|
|
|
|
} else {
|
|
|
|
mutate(fetchKey);
|
2023-06-28 13:38:33 +00:00
|
|
|
|
|
|
|
if (cycleId) mutate(CYCLE_DETAILS(cycleId as string));
|
|
|
|
if (moduleId) mutate(MODULE_DETAILS(moduleId as string));
|
2023-06-26 08:54:52 +00:00
|
|
|
}
|
2023-06-23 11:50:05 +00:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[workspaceSlug, projectId, cycleId, moduleId, viewId, params, user]
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleCopyText = () => {
|
|
|
|
const originURL =
|
|
|
|
typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
|
|
|
|
copyTextToClipboard(
|
|
|
|
`${originURL}/${workspaceSlug}/projects/${projectId}/issues/${issue.id}`
|
|
|
|
).then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
type: "success",
|
|
|
|
title: "Link Copied!",
|
|
|
|
message: "Issue link copied to clipboard.",
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const paddingLeft = `${nestingLevel * 68}px`;
|
|
|
|
|
2023-06-28 11:57:43 +00:00
|
|
|
const tooltipPosition = index === 0 ? "bottom" : "top";
|
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
const isNotAllowed = userAuth.isGuest || userAuth.isViewer;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2023-07-17 10:58:23 +00:00
|
|
|
className="relative group grid auto-rows-[minmax(44px,1fr)] hover:rounded-sm hover:bg-custom-background-80 border-b border-custom-border-200 w-full min-w-max"
|
2023-06-23 11:50:05 +00:00
|
|
|
style={{ gridTemplateColumns }}
|
|
|
|
>
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex gap-1.5 items-center px-4 sticky z-[1] left-0 text-custom-text-200 bg-custom-background-100 group-hover:text-custom-text-100 group-hover:bg-custom-background-80 border-custom-border-200 w-full">
|
2023-06-27 10:19:19 +00:00
|
|
|
<div className="flex gap-1.5 items-center" style={issue.parent ? { paddingLeft } : {}}>
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="relative flex items-center cursor-pointer text-xs text-center hover:text-custom-text-100 w-14">
|
2023-06-23 16:03:24 +00:00
|
|
|
{properties.key && (
|
2023-06-27 10:19:19 +00:00
|
|
|
<span className="flex items-center justify-center opacity-100 group-hover:opacity-0">
|
2023-06-23 11:50:05 +00:00
|
|
|
{issue.project_detail?.identifier}-{issue.sequence_id}
|
2023-06-23 16:03:24 +00:00
|
|
|
</span>
|
|
|
|
)}
|
2023-06-27 11:42:21 +00:00
|
|
|
{!isNotAllowed && !isCompleted && (
|
2023-06-27 10:19:19 +00:00
|
|
|
<div className="absolute top-0 left-2.5 opacity-0 group-hover:opacity-100">
|
|
|
|
<Popover2
|
|
|
|
isOpen={isOpen}
|
|
|
|
canEscapeKeyClose
|
|
|
|
onInteraction={(nextOpenState) => setIsOpen(nextOpenState)}
|
|
|
|
content={
|
|
|
|
<div
|
2023-07-17 10:58:23 +00:00
|
|
|
className={`flex flex-col gap-1.5 overflow-y-scroll whitespace-nowrap rounded-md border p-1 text-xs shadow-lg focus:outline-none max-h-44 min-w-full border-custom-border-200 bg-custom-background-90`}
|
2023-06-27 10:19:19 +00:00
|
|
|
>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-07-10 07:17:00 +00:00
|
|
|
className="hover:text-custom-text-200 w-full select-none gap-2 truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80"
|
2023-06-27 10:19:19 +00:00
|
|
|
onClick={() => {
|
|
|
|
handleEditIssue(issue);
|
|
|
|
setIsOpen(false);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-start gap-2">
|
|
|
|
<PencilIcon className="h-4 w-4" />
|
|
|
|
<span>Edit issue</span>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-07-10 07:17:00 +00:00
|
|
|
className="hover:text-custom-text-200 w-full select-none gap-2 truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80"
|
2023-06-27 10:19:19 +00:00
|
|
|
onClick={() => {
|
|
|
|
handleDeleteIssue(issue);
|
|
|
|
setIsOpen(false);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-start gap-2">
|
|
|
|
<TrashIcon className="h-4 w-4" />
|
|
|
|
<span>Delete issue</span>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-07-10 07:17:00 +00:00
|
|
|
className="hover:text-custom-text-200 w-full select-none gap-2 truncate rounded px-1 py-1.5 text-left text-custom-text-200 hover:bg-custom-background-80"
|
2023-06-27 10:19:19 +00:00
|
|
|
onClick={() => {
|
|
|
|
handleCopyText();
|
|
|
|
setIsOpen(false);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-start gap-2">
|
|
|
|
<LinkIcon className="h-4 w-4" />
|
|
|
|
<span>Copy issue link</span>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
placement="bottom-start"
|
|
|
|
>
|
2023-07-10 07:17:00 +00:00
|
|
|
<EllipsisHorizontalIcon className="h-5 w-5 text-custom-text-200" />
|
2023-06-27 10:19:19 +00:00
|
|
|
</Popover2>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-23 16:03:24 +00:00
|
|
|
</div>
|
2023-06-23 11:50:05 +00:00
|
|
|
|
2023-06-28 11:57:43 +00:00
|
|
|
{issue.sub_issues_count > 0 && (
|
|
|
|
<div className="h-6 w-6 flex justify-center items-center">
|
2023-06-23 11:50:05 +00:00
|
|
|
<button
|
2023-07-10 07:17:00 +00:00
|
|
|
className="h-5 w-5 hover:bg-custom-background-90 hover:text-custom-text-100 rounded-sm cursor-pointer"
|
2023-06-23 11:50:05 +00:00
|
|
|
onClick={() => handleToggleExpand(issue.id)}
|
|
|
|
>
|
|
|
|
<Icon iconName="chevron_right" className={`${expanded ? "rotate-90" : ""}`} />
|
|
|
|
</button>
|
2023-06-28 11:57:43 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2023-06-27 10:19:19 +00:00
|
|
|
</div>
|
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
<Link href={`/${workspaceSlug}/projects/${issue?.project_detail?.id}/issues/${issue.id}`}>
|
2023-07-10 07:17:00 +00:00
|
|
|
<a className="truncate text-custom-text-100 cursor-pointer w-full text-[0.825rem]">
|
2023-06-23 11:50:05 +00:00
|
|
|
{issue.name}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</div>
|
|
|
|
{properties.state && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-06-23 11:50:05 +00:00
|
|
|
<ViewStateSelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
position="left"
|
2023-07-07 08:41:33 +00:00
|
|
|
className="max-w-full"
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton
|
|
|
|
user={user}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{properties.priority && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-06-23 11:50:05 +00:00
|
|
|
<ViewPrioritySelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
position="left"
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
noBorder
|
|
|
|
user={user}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{properties.assignee && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-06-23 11:50:05 +00:00
|
|
|
<ViewAssigneeSelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
position="left"
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
customButton
|
|
|
|
user={user}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-24 12:39:06 +00:00
|
|
|
{properties.labels && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-07-25 06:37:16 +00:00
|
|
|
<ViewIssueLabel issue={issue} maxRender={1} />
|
2023-06-24 12:39:06 +00:00
|
|
|
</div>
|
2023-06-23 11:50:05 +00:00
|
|
|
)}
|
2023-06-24 12:39:06 +00:00
|
|
|
|
2023-06-23 11:50:05 +00:00
|
|
|
{properties.due_date && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-06-23 11:50:05 +00:00
|
|
|
<ViewDueDateSelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
noBorder
|
|
|
|
user={user}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{properties.estimate && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-06-23 11:50:05 +00:00
|
|
|
<ViewEstimateSelect
|
|
|
|
issue={issue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
|
|
|
position="left"
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition={tooltipPosition}
|
2023-06-23 11:50:05 +00:00
|
|
|
user={user}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-07-07 08:41:07 +00:00
|
|
|
{properties.created_on && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs cursor-default text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-07-07 08:41:07 +00:00
|
|
|
{renderLongDetailDateFormat(issue.created_at)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{properties.updated_on && (
|
2023-07-17 10:58:23 +00:00
|
|
|
<div className="flex items-center text-xs cursor-default text-custom-text-200 text-center p-2 group-hover:bg-custom-background-80 border-custom-border-200">
|
2023-07-07 08:41:07 +00:00
|
|
|
{renderLongDetailDateFormat(issue.updated_at)}
|
|
|
|
</div>
|
|
|
|
)}
|
2023-06-23 11:50:05 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|