2023-02-10 12:32:18 +00:00
|
|
|
import React from "react";
|
|
|
|
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import { mutate } from "swr";
|
|
|
|
|
|
|
|
// headless ui
|
|
|
|
import { Disclosure, Transition } from "@headlessui/react";
|
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
// ui
|
|
|
|
import { CustomMenu } from "components/ui";
|
|
|
|
// icons
|
2023-03-31 13:01:44 +00:00
|
|
|
import {
|
|
|
|
ChevronDownIcon,
|
|
|
|
XMarkIcon,
|
|
|
|
PlusIcon,
|
|
|
|
PencilIcon,
|
|
|
|
TrashIcon,
|
|
|
|
} from "@heroicons/react/24/outline";
|
2023-09-13 17:39:55 +00:00
|
|
|
import { Component, X } from "lucide-react";
|
2023-02-10 12:32:18 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IIssueLabels } from "types";
|
2023-02-10 12:32:18 +00:00
|
|
|
// fetch-keys
|
|
|
|
import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
label: IIssueLabels;
|
|
|
|
labelChildren: IIssueLabels[];
|
|
|
|
addLabelToGroup: (parentLabel: IIssueLabels) => void;
|
|
|
|
editLabel: (label: IIssueLabels) => void;
|
2023-05-17 10:34:56 +00:00
|
|
|
handleLabelDelete: () => void;
|
2023-06-06 16:06:00 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
2023-02-10 12:32:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const SingleLabelGroup: React.FC<Props> = ({
|
|
|
|
label,
|
|
|
|
labelChildren,
|
|
|
|
addLabelToGroup,
|
|
|
|
editLabel,
|
|
|
|
handleLabelDelete,
|
2023-06-06 16:06:00 +00:00
|
|
|
user,
|
2023-02-10 12:32:18 +00:00
|
|
|
}) => {
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const removeFromGroup = (label: IIssueLabels) => {
|
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
|
|
|
mutate<IIssueLabels[]>(
|
|
|
|
PROJECT_ISSUE_LABELS(projectId as string),
|
|
|
|
(prevData) =>
|
|
|
|
prevData?.map((l) => {
|
|
|
|
if (l.id === label.id) return { ...l, parent: null };
|
|
|
|
|
|
|
|
return l;
|
|
|
|
}),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
issuesService
|
2023-06-06 16:06:00 +00:00
|
|
|
.patchIssueLabel(
|
|
|
|
workspaceSlug as string,
|
|
|
|
projectId as string,
|
|
|
|
label.id,
|
|
|
|
{
|
|
|
|
parent: null,
|
|
|
|
},
|
|
|
|
user
|
|
|
|
)
|
2023-03-27 20:20:55 +00:00
|
|
|
.then(() => {
|
2023-02-10 12:32:18 +00:00
|
|
|
mutate(PROJECT_ISSUE_LABELS(projectId as string));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-04-22 18:16:19 +00:00
|
|
|
<Disclosure
|
|
|
|
as="div"
|
2023-09-13 17:39:55 +00:00
|
|
|
className="rounded border border-custom-border-200 bg-custom-background-100 px-3.5 py-3 text-custom-text-100"
|
2023-04-22 18:16:19 +00:00
|
|
|
defaultOpen
|
|
|
|
>
|
2023-02-10 12:32:18 +00:00
|
|
|
{({ open }) => (
|
|
|
|
<>
|
2023-03-04 12:17:03 +00:00
|
|
|
<div className="flex cursor-pointer items-center justify-between gap-2">
|
|
|
|
<div className="flex items-center gap-2">
|
2023-09-13 17:39:55 +00:00
|
|
|
<Component className="h-4 w-4 text-custom-text-100 flex-shrink-0" />
|
2023-04-22 18:16:19 +00:00
|
|
|
<h6>{label.name}</h6>
|
2023-03-04 12:17:03 +00:00
|
|
|
</div>
|
|
|
|
<div className="flex items-center gap-2">
|
2023-09-13 17:39:55 +00:00
|
|
|
<CustomMenu ellipsis buttonClassName="!text-custom-sidebar-text-400">
|
2023-03-04 12:17:03 +00:00
|
|
|
<CustomMenu.MenuItem onClick={() => addLabelToGroup(label)}>
|
2023-03-31 13:01:44 +00:00
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<PlusIcon className="h-4 w-4" />
|
|
|
|
<span>Add more labels</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem onClick={() => editLabel(label)}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<PencilIcon className="h-4 w-4" />
|
|
|
|
<span>Edit label</span>
|
|
|
|
</span>
|
2023-03-04 12:17:03 +00:00
|
|
|
</CustomMenu.MenuItem>
|
2023-05-17 10:34:56 +00:00
|
|
|
<CustomMenu.MenuItem onClick={handleLabelDelete}>
|
2023-03-31 13:01:44 +00:00
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<TrashIcon className="h-4 w-4" />
|
|
|
|
<span>Delete label</span>
|
|
|
|
</span>
|
2023-03-04 12:17:03 +00:00
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
</CustomMenu>
|
|
|
|
<Disclosure.Button>
|
2023-02-10 12:32:18 +00:00
|
|
|
<span>
|
|
|
|
<ChevronDownIcon
|
2023-09-13 17:39:55 +00:00
|
|
|
className={`h-4 w-4 text-custom-sidebar-text-400 ${
|
|
|
|
!open ? "rotate-90 transform" : ""
|
|
|
|
}`}
|
2023-02-10 12:32:18 +00:00
|
|
|
/>
|
|
|
|
</span>
|
2023-03-04 12:17:03 +00:00
|
|
|
</Disclosure.Button>
|
|
|
|
</div>
|
2023-02-10 12:32:18 +00:00
|
|
|
</div>
|
|
|
|
<Transition
|
|
|
|
show={open}
|
|
|
|
enter="transition duration-100 ease-out"
|
|
|
|
enterFrom="transform opacity-0"
|
|
|
|
enterTo="transform opacity-100"
|
|
|
|
leave="transition duration-75 ease-out"
|
|
|
|
leaveFrom="transform opacity-100"
|
|
|
|
leaveTo="transform opacity-0"
|
|
|
|
>
|
|
|
|
<Disclosure.Panel>
|
2023-09-13 17:39:55 +00:00
|
|
|
<div className="mt-2.5 ml-6">
|
2023-02-10 12:32:18 +00:00
|
|
|
{labelChildren.map((child) => (
|
|
|
|
<div
|
|
|
|
key={child.id}
|
2023-09-13 17:39:55 +00:00
|
|
|
className="group flex items-center justify-between border-b border-custom-border-200 px-4 py-2.5 text-sm last:border-0"
|
2023-02-10 12:32:18 +00:00
|
|
|
>
|
2023-04-22 18:16:19 +00:00
|
|
|
<h5 className="flex items-center gap-3">
|
2023-02-10 12:32:18 +00:00
|
|
|
<span
|
2023-09-13 17:39:55 +00:00
|
|
|
className="h-3.5 w-3.5 flex-shrink-0 rounded-full"
|
2023-02-10 12:32:18 +00:00
|
|
|
style={{
|
2023-03-27 20:20:55 +00:00
|
|
|
backgroundColor:
|
|
|
|
child.color && child.color !== "" ? child.color : "#000000",
|
2023-02-10 12:32:18 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{child.name}
|
|
|
|
</h5>
|
2023-09-13 17:39:55 +00:00
|
|
|
<div className="flex items-center gap-3.5 pointer-events-none opacity-0 group-hover:pointer-events-auto group-hover:opacity-100">
|
|
|
|
<div className="h-4 w-4">
|
|
|
|
<CustomMenu
|
|
|
|
customButton={
|
|
|
|
<div className="h-4 w-4">
|
|
|
|
<Component className="h-4 w-4 leading-4 text-custom-sidebar-text-400 flex-shrink-0" />
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<CustomMenu.MenuItem onClick={() => removeFromGroup(child)}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<XMarkIcon className="h-4 w-4" />
|
|
|
|
<span>Remove from group</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
<CustomMenu.MenuItem onClick={() => editLabel(child)}>
|
|
|
|
<span className="flex items-center justify-start gap-2">
|
|
|
|
<PencilIcon className="h-4 w-4" />
|
|
|
|
<span>Edit label</span>
|
|
|
|
</span>
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="flex items-center">
|
|
|
|
<button
|
|
|
|
className="flex items-center justify-start gap-2"
|
|
|
|
onClick={handleLabelDelete}
|
|
|
|
>
|
|
|
|
<X className="h-[18px] w-[18px] text-custom-sidebar-text-400 flex-shrink-0" />
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-02-10 12:32:18 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</Disclosure.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Disclosure>
|
|
|
|
);
|
|
|
|
};
|