2022-12-13 15:52:44 +00:00
|
|
|
// react
|
2022-12-15 04:17:56 +00:00
|
|
|
import React, { useState } from "react";
|
2022-12-13 15:52:44 +00:00
|
|
|
// next
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// swr
|
|
|
|
import useSWR, { mutate } from "swr";
|
|
|
|
// react-beautiful-dnd
|
|
|
|
import { DropResult } from "react-beautiful-dnd";
|
|
|
|
// layouots
|
|
|
|
import AppLayout from "layouts/app-layout";
|
|
|
|
// components
|
2022-12-15 04:17:56 +00:00
|
|
|
import CyclesListView from "components/project/cycles/list-view";
|
|
|
|
import CyclesBoardView from "components/project/cycles/board-view";
|
2022-12-19 15:00:09 +00:00
|
|
|
import CreateUpdateIssuesModal from "components/project/issues/create-update-issue-modal";
|
|
|
|
import CycleIssuesListModal from "components/project/cycles/cycle-issues-list-modal";
|
|
|
|
import ConfirmIssueDeletion from "components/project/issues/confirm-issue-deletion";
|
2022-12-13 15:52:44 +00:00
|
|
|
// services
|
|
|
|
import issuesServices from "lib/services/issues.service";
|
|
|
|
import cycleServices from "lib/services/cycles.service";
|
|
|
|
import projectService from "lib/services/project.service";
|
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
|
|
|
import useIssuesFilter from "lib/hooks/useIssuesFilter";
|
|
|
|
import useIssuesProperties from "lib/hooks/useIssuesProperties";
|
|
|
|
// headless ui
|
2022-12-16 16:20:09 +00:00
|
|
|
import { Popover, Transition } from "@headlessui/react";
|
2022-12-13 15:52:44 +00:00
|
|
|
// ui
|
|
|
|
import { BreadcrumbItem, Breadcrumbs, CustomMenu } from "ui";
|
|
|
|
// icons
|
|
|
|
import { Squares2X2Icon } from "@heroicons/react/20/solid";
|
2022-12-15 04:17:56 +00:00
|
|
|
import { ArrowPathIcon, ChevronDownIcon, ListBulletIcon } from "@heroicons/react/24/outline";
|
2022-12-13 15:52:44 +00:00
|
|
|
// types
|
2022-12-19 15:00:09 +00:00
|
|
|
import { CycleIssueResponse, IIssue, NestedKeyOf, Properties, SelectIssue } from "types";
|
2022-12-13 15:52:44 +00:00
|
|
|
// fetch-keys
|
2022-12-19 15:00:09 +00:00
|
|
|
import { CYCLE_ISSUES, PROJECT_MEMBERS } from "constants/fetch-keys";
|
|
|
|
// common
|
2022-12-13 15:52:44 +00:00
|
|
|
import { classNames, replaceUnderscoreIfSnakeCase } from "constants/common";
|
|
|
|
|
|
|
|
const groupByOptions: Array<{ name: string; key: NestedKeyOf<IIssue> | null }> = [
|
|
|
|
{ name: "State", key: "state_detail.name" },
|
|
|
|
{ name: "Priority", key: "priority" },
|
|
|
|
{ name: "Created By", key: "created_by" },
|
|
|
|
{ name: "None", key: null },
|
|
|
|
];
|
|
|
|
|
|
|
|
const orderByOptions: Array<{ name: string; key: NestedKeyOf<IIssue> }> = [
|
|
|
|
{ name: "Last created", key: "created_at" },
|
|
|
|
{ name: "Last updated", key: "updated_at" },
|
|
|
|
{ name: "Priority", key: "priority" },
|
|
|
|
];
|
|
|
|
|
|
|
|
const filterIssueOptions: Array<{
|
|
|
|
name: string;
|
|
|
|
key: "activeIssue" | "backlogIssue" | null;
|
|
|
|
}> = [
|
|
|
|
{
|
|
|
|
name: "All",
|
|
|
|
key: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Active Issues",
|
|
|
|
key: "activeIssue",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Backlog Issues",
|
|
|
|
key: "backlogIssue",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2022-12-19 15:00:09 +00:00
|
|
|
const SingleCycle: React.FC = () => {
|
2022-12-15 04:17:56 +00:00
|
|
|
const [isIssueModalOpen, setIsIssueModalOpen] = useState(false);
|
|
|
|
const [selectedIssues, setSelectedIssues] = useState<SelectIssue>();
|
2022-12-16 16:20:09 +00:00
|
|
|
const [cycleIssuesListModal, setCycleIssuesListModal] = useState(false);
|
2022-12-18 11:43:43 +00:00
|
|
|
const [deleteIssue, setDeleteIssue] = useState<string | undefined>(undefined);
|
2022-12-15 04:17:56 +00:00
|
|
|
|
2022-12-19 15:00:09 +00:00
|
|
|
const [preloadedData, setPreloadedData] = useState<
|
|
|
|
(Partial<IIssue> & { actionType: "createIssue" | "edit" | "delete" }) | undefined
|
|
|
|
>(undefined);
|
|
|
|
|
2022-12-16 16:20:09 +00:00
|
|
|
const { activeWorkspace, activeProject, cycles, issues } = useUser();
|
2022-12-13 15:52:44 +00:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const { cycleId } = router.query;
|
|
|
|
|
|
|
|
const [properties, setProperties] = useIssuesProperties(
|
|
|
|
activeWorkspace?.slug,
|
|
|
|
activeProject?.id as string
|
|
|
|
);
|
|
|
|
|
|
|
|
const { data: cycleIssues } = useSWR<CycleIssueResponse[]>(
|
|
|
|
activeWorkspace && activeProject && cycleId ? CYCLE_ISSUES(cycleId as string) : null,
|
|
|
|
activeWorkspace && activeProject && cycleId
|
|
|
|
? () =>
|
|
|
|
cycleServices.getCycleIssues(activeWorkspace?.slug, activeProject?.id, cycleId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
const cycleIssuesArray = cycleIssues?.map((issue) => {
|
2022-12-16 16:20:09 +00:00
|
|
|
return { bridge: issue.id, ...issue.issue_details };
|
2022-12-13 15:52:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const { data: members } = useSWR(
|
|
|
|
activeWorkspace && activeProject ? PROJECT_MEMBERS(activeProject.id) : null,
|
|
|
|
activeWorkspace && activeProject
|
|
|
|
? () => projectService.projectMembers(activeWorkspace.slug, activeProject.id)
|
|
|
|
: null,
|
|
|
|
{
|
|
|
|
onErrorRetry(err, _, __, revalidate, revalidateOpts) {
|
|
|
|
if (err?.status === 403) return;
|
|
|
|
setTimeout(() => revalidate(revalidateOpts), 5000);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-12-18 11:43:43 +00:00
|
|
|
const partialUpdateIssue = (formData: Partial<IIssue>, issueId: string) => {
|
|
|
|
if (!activeWorkspace || !activeProject) return;
|
|
|
|
issuesServices
|
|
|
|
.patchIssue(activeWorkspace.slug, activeProject.id, issueId, formData)
|
|
|
|
.then((response) => {
|
|
|
|
mutate(CYCLE_ISSUES(cycleId as string));
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
const {
|
|
|
|
issueView,
|
|
|
|
groupByProperty,
|
|
|
|
setGroupByProperty,
|
|
|
|
groupedByIssues,
|
|
|
|
setOrderBy,
|
|
|
|
setFilterIssue,
|
|
|
|
orderBy,
|
|
|
|
filterIssue,
|
2022-12-20 14:10:40 +00:00
|
|
|
setIssueViewToKanban,
|
|
|
|
setIssueViewToList,
|
2022-12-13 15:52:44 +00:00
|
|
|
} = useIssuesFilter(cycleIssuesArray ?? []);
|
|
|
|
|
2022-12-15 04:17:56 +00:00
|
|
|
const openCreateIssueModal = (
|
|
|
|
issue?: IIssue,
|
|
|
|
actionType: "create" | "edit" | "delete" = "create"
|
|
|
|
) => {
|
2022-12-19 15:00:09 +00:00
|
|
|
if (issue) setSelectedIssues({ ...issue, actionType });
|
|
|
|
setIsIssueModalOpen(true);
|
2022-12-15 04:17:56 +00:00
|
|
|
};
|
|
|
|
|
2022-12-16 16:20:09 +00:00
|
|
|
const openIssuesListModal = () => {
|
|
|
|
setCycleIssuesListModal(true);
|
|
|
|
};
|
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
const handleDragEnd = (result: DropResult) => {
|
|
|
|
if (!result.destination) return;
|
|
|
|
const { source, destination } = result;
|
|
|
|
|
|
|
|
if (source.droppableId === destination.droppableId) return;
|
|
|
|
|
|
|
|
if (activeWorkspace && activeProject) {
|
|
|
|
// remove issue from the source cycle
|
|
|
|
mutate<CycleIssueResponse[]>(
|
|
|
|
CYCLE_ISSUES(source.droppableId),
|
|
|
|
(prevData) => prevData?.filter((p) => p.id !== result.draggableId.split(",")[0]),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
// add issue to the destination cycle
|
|
|
|
mutate(CYCLE_ISSUES(destination.droppableId));
|
|
|
|
|
|
|
|
issuesServices
|
|
|
|
.removeIssueFromCycle(
|
|
|
|
activeWorkspace.slug,
|
|
|
|
activeProject.id,
|
|
|
|
source.droppableId,
|
|
|
|
result.draggableId.split(",")[0]
|
|
|
|
)
|
|
|
|
.then((res) => {
|
|
|
|
issuesServices
|
|
|
|
.addIssueToCycle(activeWorkspace.slug, activeProject.id, destination.droppableId, {
|
2022-12-20 14:50:45 +00:00
|
|
|
issues: [result.draggableId.split(",")[1]],
|
2022-12-13 15:52:44 +00:00
|
|
|
})
|
|
|
|
.then((res) => {
|
|
|
|
console.log(res);
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// console.log(result);
|
|
|
|
};
|
|
|
|
|
2022-12-16 16:20:09 +00:00
|
|
|
const removeIssueFromCycle = (bridgeId: string) => {
|
2022-12-13 15:52:44 +00:00
|
|
|
if (activeWorkspace && activeProject) {
|
|
|
|
mutate<CycleIssueResponse[]>(
|
2022-12-16 16:20:09 +00:00
|
|
|
CYCLE_ISSUES(cycleId as string),
|
2022-12-13 15:52:44 +00:00
|
|
|
(prevData) => prevData?.filter((p) => p.id !== bridgeId),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
|
|
|
issuesServices
|
2022-12-16 16:20:09 +00:00
|
|
|
.removeIssueFromCycle(activeWorkspace.slug, activeProject.id, cycleId as string, bridgeId)
|
2022-12-13 15:52:44 +00:00
|
|
|
.then((res) => {
|
|
|
|
console.log(res);
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
console.log(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2022-12-15 04:17:56 +00:00
|
|
|
<>
|
|
|
|
<CreateUpdateIssuesModal
|
2022-12-19 15:00:09 +00:00
|
|
|
isOpen={isIssueModalOpen && selectedIssues?.actionType !== "delete"}
|
2022-12-15 04:17:56 +00:00
|
|
|
data={selectedIssues}
|
2022-12-19 15:00:09 +00:00
|
|
|
prePopulateData={{ sprints: cycleId as string, ...preloadedData }}
|
2022-12-15 04:17:56 +00:00
|
|
|
setIsOpen={setIsIssueModalOpen}
|
|
|
|
projectId={activeProject?.id}
|
|
|
|
/>
|
2022-12-16 16:20:09 +00:00
|
|
|
<CycleIssuesListModal
|
|
|
|
isOpen={cycleIssuesListModal}
|
|
|
|
handleClose={() => setCycleIssuesListModal(false)}
|
|
|
|
issues={issues}
|
|
|
|
cycleId={cycleId as string}
|
|
|
|
/>
|
2022-12-18 11:43:43 +00:00
|
|
|
<ConfirmIssueDeletion
|
|
|
|
handleClose={() => setDeleteIssue(undefined)}
|
|
|
|
isOpen={!!deleteIssue}
|
|
|
|
data={issues?.results.find((issue) => issue.id === deleteIssue)}
|
|
|
|
/>
|
2022-12-15 04:17:56 +00:00
|
|
|
<AppLayout
|
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem
|
|
|
|
title={`${activeProject?.name ?? "Project"} Cycles`}
|
|
|
|
link={`/projects/${activeProject?.id}/cycles`}
|
|
|
|
/>
|
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
left={
|
2022-12-16 16:20:09 +00:00
|
|
|
<CustomMenu
|
|
|
|
label={
|
|
|
|
<>
|
|
|
|
<ArrowPathIcon className="h-3 w-3" />
|
|
|
|
{cycles?.find((c) => c.id === cycleId)?.name}
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
className="ml-1.5"
|
2022-12-17 20:01:13 +00:00
|
|
|
width="auto"
|
2022-12-16 16:20:09 +00:00
|
|
|
>
|
|
|
|
{cycles?.map((cycle) => (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={cycle.id}
|
|
|
|
renderAs="a"
|
|
|
|
href={`/projects/${activeProject?.id}/cycles/${cycle.id}`}
|
|
|
|
>
|
|
|
|
{cycle.name}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
|
|
|
</CustomMenu>
|
2022-12-15 04:17:56 +00:00
|
|
|
}
|
|
|
|
right={
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
<div className="flex items-center gap-x-1">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
|
|
|
|
issueView === "list" ? "bg-gray-200" : ""
|
|
|
|
}`}
|
2022-12-20 14:10:40 +00:00
|
|
|
onClick={() => setIssueViewToList()}
|
2022-12-15 04:17:56 +00:00
|
|
|
>
|
|
|
|
<ListBulletIcon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className={`h-7 w-7 p-1 grid place-items-center rounded hover:bg-gray-200 duration-300 outline-none ${
|
|
|
|
issueView === "kanban" ? "bg-gray-200" : ""
|
|
|
|
}`}
|
2022-12-20 14:10:40 +00:00
|
|
|
onClick={() => setIssueViewToKanban()}
|
2022-12-15 04:17:56 +00:00
|
|
|
>
|
|
|
|
<Squares2X2Icon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<Popover className="relative">
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<Popover.Button
|
|
|
|
className={classNames(
|
|
|
|
open ? "bg-gray-100 text-gray-900" : "text-gray-500",
|
|
|
|
"group flex gap-2 items-center rounded-md bg-transparent text-xs font-medium hover:bg-gray-100 hover:text-gray-900 focus:outline-none border p-2"
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<span>View</span>
|
|
|
|
<ChevronDownIcon className="h-4 w-4" aria-hidden="true" />
|
|
|
|
</Popover.Button>
|
2022-12-13 15:52:44 +00:00
|
|
|
|
2022-12-15 04:17:56 +00:00
|
|
|
<Transition
|
|
|
|
as={React.Fragment}
|
|
|
|
enter="transition ease-out duration-200"
|
|
|
|
enterFrom="opacity-0 translate-y-1"
|
|
|
|
enterTo="opacity-100 translate-y-0"
|
|
|
|
leave="transition ease-in duration-150"
|
|
|
|
leaveFrom="opacity-100 translate-y-0"
|
|
|
|
leaveTo="opacity-0 translate-y-1"
|
|
|
|
>
|
2022-12-16 16:20:09 +00:00
|
|
|
<Popover.Panel className="absolute right-0 z-10 mt-1 w-screen max-w-xs transform p-3 bg-white rounded-lg shadow-lg overflow-hidden">
|
2022-12-15 04:17:56 +00:00
|
|
|
<div className="relative flex flex-col gap-1 gap-y-4">
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<h4 className="text-sm text-gray-600">Group by</h4>
|
|
|
|
<CustomMenu
|
|
|
|
label={
|
|
|
|
groupByOptions.find((option) => option.key === groupByProperty)
|
|
|
|
?.name ?? "Select"
|
|
|
|
}
|
2022-12-16 16:20:09 +00:00
|
|
|
width="auto"
|
2022-12-15 04:17:56 +00:00
|
|
|
>
|
|
|
|
{groupByOptions.map((option) => (
|
2022-12-13 15:52:44 +00:00
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={option.key}
|
2022-12-15 04:17:56 +00:00
|
|
|
onClick={() => setGroupByProperty(option.key)}
|
2022-12-13 15:52:44 +00:00
|
|
|
>
|
|
|
|
{option.name}
|
|
|
|
</CustomMenu.MenuItem>
|
2022-12-15 04:17:56 +00:00
|
|
|
))}
|
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<h4 className="text-sm text-gray-600">Order by</h4>
|
|
|
|
<CustomMenu
|
|
|
|
label={
|
|
|
|
orderByOptions.find((option) => option.key === orderBy)?.name ??
|
|
|
|
"Select"
|
|
|
|
}
|
2022-12-16 16:20:09 +00:00
|
|
|
width="auto"
|
2022-12-15 04:17:56 +00:00
|
|
|
>
|
|
|
|
{orderByOptions.map((option) =>
|
|
|
|
groupByProperty === "priority" && option.key === "priority" ? null : (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={option.key}
|
|
|
|
onClick={() => setOrderBy(option.key)}
|
|
|
|
>
|
|
|
|
{option.name}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
)
|
|
|
|
)}
|
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
<div className="flex justify-between items-center">
|
|
|
|
<h4 className="text-sm text-gray-600">Issue type</h4>
|
|
|
|
<CustomMenu
|
|
|
|
label={
|
|
|
|
filterIssueOptions.find((option) => option.key === filterIssue)
|
|
|
|
?.name ?? "Select"
|
|
|
|
}
|
2022-12-16 16:20:09 +00:00
|
|
|
width="auto"
|
2022-12-15 04:17:56 +00:00
|
|
|
>
|
|
|
|
{filterIssueOptions.map((option) => (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={option.key}
|
|
|
|
onClick={() => setFilterIssue(option.key)}
|
|
|
|
>
|
|
|
|
{option.name}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
|
|
|
</CustomMenu>
|
|
|
|
</div>
|
|
|
|
<div className="border-b-2"></div>
|
|
|
|
<div className="relative flex flex-col gap-1">
|
|
|
|
<h4 className="text-base text-gray-600">Properties</h4>
|
|
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
|
|
{Object.keys(properties).map((key) => (
|
|
|
|
<button
|
|
|
|
key={key}
|
|
|
|
type="button"
|
|
|
|
className={`px-2 py-1 capitalize rounded border border-theme text-xs ${
|
|
|
|
properties[key as keyof Properties]
|
|
|
|
? "border-theme bg-theme text-white"
|
|
|
|
: ""
|
|
|
|
}`}
|
|
|
|
onClick={() => setProperties(key as keyof Properties)}
|
|
|
|
>
|
|
|
|
{replaceUnderscoreIfSnakeCase(key)}
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-12-15 04:17:56 +00:00
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{issueView === "list" ? (
|
|
|
|
<CyclesListView
|
2022-12-13 15:52:44 +00:00
|
|
|
groupedByIssues={groupedByIssues}
|
|
|
|
selectedGroup={groupByProperty}
|
2022-12-15 04:17:56 +00:00
|
|
|
properties={properties}
|
|
|
|
openCreateIssueModal={openCreateIssueModal}
|
2022-12-16 16:20:09 +00:00
|
|
|
openIssuesListModal={openIssuesListModal}
|
2022-12-15 04:17:56 +00:00
|
|
|
removeIssueFromCycle={removeIssueFromCycle}
|
2022-12-19 15:00:09 +00:00
|
|
|
setPreloadedData={setPreloadedData}
|
2022-12-13 15:52:44 +00:00
|
|
|
/>
|
2022-12-15 04:17:56 +00:00
|
|
|
) : (
|
|
|
|
<div className="h-screen">
|
|
|
|
<CyclesBoardView
|
|
|
|
groupedByIssues={groupedByIssues}
|
|
|
|
properties={properties}
|
|
|
|
removeIssueFromCycle={removeIssueFromCycle}
|
|
|
|
selectedGroup={groupByProperty}
|
|
|
|
members={members}
|
|
|
|
openCreateIssueModal={openCreateIssueModal}
|
2022-12-16 16:20:09 +00:00
|
|
|
openIssuesListModal={openIssuesListModal}
|
2022-12-18 11:43:43 +00:00
|
|
|
handleDeleteIssue={setDeleteIssue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
2022-12-19 15:00:09 +00:00
|
|
|
setPreloadedData={setPreloadedData}
|
2022-12-15 04:17:56 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</AppLayout>
|
|
|
|
</>
|
2022-12-13 15:52:44 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SingleCycle;
|