2022-11-19 14:21:26 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
// next
|
|
|
|
import type { NextPage } from "next";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// swr
|
2022-12-13 15:52:44 +00:00
|
|
|
import useSWR, { mutate } from "swr";
|
2022-11-19 14:21:26 +00:00
|
|
|
// headless ui
|
2022-12-02 11:47:13 +00:00
|
|
|
import { Popover, Transition } from "@headlessui/react";
|
|
|
|
// hoc
|
|
|
|
import withAuth from "lib/hoc/withAuthWrapper";
|
2022-12-13 15:52:44 +00:00
|
|
|
// services
|
|
|
|
import issuesServices from "lib/services/issues.service";
|
2022-11-19 14:21:26 +00:00
|
|
|
// hooks
|
|
|
|
import useUser from "lib/hooks/useUser";
|
|
|
|
import useIssuesProperties from "lib/hooks/useIssuesProperties";
|
2022-12-02 11:47:13 +00:00
|
|
|
// api routes
|
|
|
|
import { PROJECT_MEMBERS } from "constants/api-routes";
|
|
|
|
// services
|
|
|
|
import projectService from "lib/services/project.service";
|
2022-11-19 14:21:26 +00:00
|
|
|
// commons
|
2022-12-02 11:47:13 +00:00
|
|
|
import { classNames, replaceUnderscoreIfSnakeCase } from "constants/common";
|
2022-11-19 14:21:26 +00:00
|
|
|
// layouts
|
2022-12-13 15:52:44 +00:00
|
|
|
import AppLayout from "layouts/app-layout";
|
2022-12-02 11:47:13 +00:00
|
|
|
// hooks
|
|
|
|
import useIssuesFilter from "lib/hooks/useIssuesFilter";
|
2022-11-19 14:21:26 +00:00
|
|
|
// components
|
2022-12-17 20:01:13 +00:00
|
|
|
import ListView from "components/project/issues/list-view";
|
2022-11-19 14:21:26 +00:00
|
|
|
import BoardView from "components/project/issues/BoardView";
|
2022-12-13 15:52:44 +00:00
|
|
|
import ConfirmIssueDeletion from "components/project/issues/confirm-issue-deletion";
|
2022-12-17 20:01:13 +00:00
|
|
|
import CreateUpdateIssuesModal from "components/project/issues/create-update-issue-modal";
|
2022-11-19 14:21:26 +00:00
|
|
|
// ui
|
2022-12-13 15:52:44 +00:00
|
|
|
import {
|
|
|
|
Spinner,
|
|
|
|
CustomMenu,
|
|
|
|
BreadcrumbItem,
|
|
|
|
Breadcrumbs,
|
|
|
|
EmptySpace,
|
|
|
|
EmptySpaceItem,
|
|
|
|
HeaderButton,
|
|
|
|
} from "ui";
|
2022-11-19 14:21:26 +00:00
|
|
|
// icons
|
|
|
|
import { ChevronDownIcon, ListBulletIcon, RectangleStackIcon } from "@heroicons/react/24/outline";
|
2022-12-02 11:47:13 +00:00
|
|
|
import { PlusIcon, Squares2X2Icon } from "@heroicons/react/20/solid";
|
2022-11-19 14:21:26 +00:00
|
|
|
// types
|
2022-12-13 15:52:44 +00:00
|
|
|
import type { IIssue, Properties, NestedKeyOf, IssueResponse } from "types";
|
|
|
|
// fetch-keys
|
|
|
|
import { PROJECT_ISSUES_LIST } from "constants/fetch-keys";
|
2022-11-19 14:21:26 +00:00
|
|
|
|
2022-12-06 04:41:56 +00:00
|
|
|
const groupByOptions: Array<{ name: string; key: NestedKeyOf<IIssue> | null }> = [
|
2022-12-02 11:47:13 +00:00
|
|
|
{ name: "State", key: "state_detail.name" },
|
|
|
|
{ name: "Priority", key: "priority" },
|
2022-12-19 15:00:09 +00:00
|
|
|
// { name: "Cycle", key: "issue_cycle.cycle_detail.name" },
|
2022-12-02 11:47:13 +00:00
|
|
|
{ name: "Created By", key: "created_by" },
|
2022-12-06 04:41:56 +00:00
|
|
|
{ name: "None", key: null },
|
2022-12-02 11:47:13 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const orderByOptions: Array<{ name: string; key: NestedKeyOf<IIssue> }> = [
|
2022-12-06 21:24:40 +00:00
|
|
|
{ name: "Last created", key: "created_at" },
|
|
|
|
{ name: "Last updated", key: "updated_at" },
|
2022-12-06 04:41:56 +00:00
|
|
|
{ name: "Priority", key: "priority" },
|
2022-12-02 11:47:13 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const filterIssueOptions: Array<{
|
|
|
|
name: string;
|
|
|
|
key: "activeIssue" | "backlogIssue" | null;
|
|
|
|
}> = [
|
|
|
|
{
|
|
|
|
name: "All",
|
|
|
|
key: null,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Active Issues",
|
|
|
|
key: "activeIssue",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Backlog Issues",
|
|
|
|
key: "backlogIssue",
|
|
|
|
},
|
|
|
|
];
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
const ProjectIssues: NextPage = () => {
|
|
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
|
|
|
|
const [selectedIssue, setSelectedIssue] = useState<
|
|
|
|
(IIssue & { actionType: "edit" | "delete" }) | undefined
|
|
|
|
>(undefined);
|
|
|
|
const [deleteIssue, setDeleteIssue] = useState<string | undefined>(undefined);
|
|
|
|
|
2022-12-02 11:47:13 +00:00
|
|
|
const { activeWorkspace, activeProject, issues: projectIssues } = useUser();
|
2022-11-19 14:21:26 +00:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
const { projectId } = router.query;
|
|
|
|
|
|
|
|
const [properties, setProperties] = useIssuesProperties(
|
|
|
|
activeWorkspace?.slug,
|
|
|
|
projectId as string
|
|
|
|
);
|
|
|
|
|
2022-12-12 04:49:52 +00:00
|
|
|
const { data: members } = useSWR(
|
2022-12-07 14:35:12 +00:00
|
|
|
activeWorkspace && activeProject
|
|
|
|
? PROJECT_MEMBERS(activeWorkspace.slug, activeProject.id)
|
|
|
|
: null,
|
2022-11-24 13:48:18 +00:00
|
|
|
activeWorkspace && activeProject
|
|
|
|
? () => projectService.projectMembers(activeWorkspace.slug, activeProject.id)
|
2022-12-07 14:35:12 +00:00
|
|
|
: null,
|
|
|
|
{
|
|
|
|
onErrorRetry(err, _, __, revalidate, revalidateOpts) {
|
|
|
|
if (err?.status === 403) return;
|
|
|
|
setTimeout(() => revalidate(revalidateOpts), 5000);
|
|
|
|
},
|
|
|
|
}
|
2022-11-24 13:48:18 +00:00
|
|
|
);
|
|
|
|
|
2022-12-13 15:52:44 +00:00
|
|
|
const partialUpdateIssue = (formData: Partial<IIssue>, issueId: string) => {
|
|
|
|
if (!activeWorkspace || !activeProject) return;
|
|
|
|
issuesServices
|
|
|
|
.patchIssue(activeWorkspace.slug, activeProject.id, issueId, formData)
|
|
|
|
.then((response) => {
|
|
|
|
mutate<IssueResponse>(
|
|
|
|
PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id),
|
|
|
|
(prevData) => ({
|
|
|
|
...(prevData as IssueResponse),
|
|
|
|
results:
|
|
|
|
prevData?.results.map((issue) => (issue.id === response.id ? response : issue)) ?? [],
|
|
|
|
}),
|
|
|
|
false
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-12-02 11:47:13 +00:00
|
|
|
const {
|
|
|
|
issueView,
|
|
|
|
groupByProperty,
|
|
|
|
setGroupByProperty,
|
|
|
|
groupedByIssues,
|
|
|
|
setOrderBy,
|
|
|
|
setFilterIssue,
|
|
|
|
orderBy,
|
|
|
|
filterIssue,
|
2022-12-20 12:27:17 +00:00
|
|
|
resetFilterToDefault,
|
|
|
|
setNewFilterDefaultView,
|
2022-12-20 14:07:58 +00:00
|
|
|
setIssueViewToKanban,
|
|
|
|
setIssueViewToList,
|
2022-12-19 14:43:43 +00:00
|
|
|
} = useIssuesFilter(projectIssues?.results.filter((p) => p.parent === null) ?? []);
|
2022-12-02 11:47:13 +00:00
|
|
|
|
2022-11-19 14:21:26 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!isOpen) {
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
setSelectedIssue(undefined);
|
|
|
|
clearTimeout(timer);
|
|
|
|
}, 500);
|
|
|
|
}
|
|
|
|
}, [isOpen]);
|
|
|
|
|
|
|
|
return (
|
2022-12-13 15:52:44 +00:00
|
|
|
<AppLayout
|
|
|
|
breadcrumbs={
|
|
|
|
<Breadcrumbs>
|
|
|
|
<BreadcrumbItem title="Projects" link="/projects" />
|
|
|
|
<BreadcrumbItem title={`${activeProject?.name ?? "Project"} Issues`} />
|
|
|
|
</Breadcrumbs>
|
|
|
|
}
|
|
|
|
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:07:58 +00:00
|
|
|
onClick={() => setIssueViewToList()}
|
2022-12-13 15:52:44 +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:07:58 +00:00
|
|
|
onClick={() => setIssueViewToKanban()}
|
2022-12-13 15:52:44 +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>
|
|
|
|
|
|
|
|
<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"
|
|
|
|
>
|
|
|
|
<Popover.Panel className="absolute mr-5 right-1/2 z-10 mt-1 w-screen max-w-xs translate-x-1/2 transform p-3 bg-white rounded-lg shadow-lg overflow-hidden">
|
|
|
|
<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-13 15:52:44 +00:00
|
|
|
>
|
|
|
|
{groupByOptions.map((option) => (
|
|
|
|
<CustomMenu.MenuItem
|
|
|
|
key={option.key}
|
|
|
|
onClick={() => setGroupByProperty(option.key)}
|
|
|
|
>
|
|
|
|
{option.name}
|
|
|
|
</CustomMenu.MenuItem>
|
|
|
|
))}
|
|
|
|
</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-13 15:52:44 +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-13 15:52:44 +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>
|
|
|
|
</div>
|
2022-12-20 12:27:17 +00:00
|
|
|
<div className="border-b-2"></div>
|
|
|
|
<div className="relative flex justify-end gap-x-3">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="text-xs"
|
|
|
|
onClick={() => resetFilterToDefault()}
|
|
|
|
>
|
|
|
|
Reset to default
|
|
|
|
</button>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="text-xs font-medium text-theme"
|
|
|
|
onClick={() => setNewFilterDefaultView()}
|
|
|
|
>
|
|
|
|
Set as default
|
|
|
|
</button>
|
|
|
|
</div>
|
2022-12-13 15:52:44 +00:00
|
|
|
</div>
|
|
|
|
</Popover.Panel>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
<HeaderButton
|
|
|
|
Icon={PlusIcon}
|
|
|
|
label="Add Issue"
|
|
|
|
onClick={() => {
|
|
|
|
const e = new KeyboardEvent("keydown", {
|
|
|
|
key: "i",
|
|
|
|
ctrlKey: true,
|
|
|
|
});
|
|
|
|
document.dispatchEvent(e);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
>
|
2022-11-19 14:21:26 +00:00
|
|
|
<CreateUpdateIssuesModal
|
|
|
|
isOpen={isOpen && selectedIssue?.actionType !== "delete"}
|
|
|
|
setIsOpen={setIsOpen}
|
|
|
|
projectId={projectId as string}
|
|
|
|
data={selectedIssue}
|
|
|
|
/>
|
|
|
|
<ConfirmIssueDeletion
|
|
|
|
handleClose={() => setDeleteIssue(undefined)}
|
|
|
|
isOpen={!!deleteIssue}
|
|
|
|
data={projectIssues?.results.find((issue) => issue.id === deleteIssue)}
|
|
|
|
/>
|
2022-11-25 17:24:49 +00:00
|
|
|
{!projectIssues ? (
|
|
|
|
<div className="h-full w-full flex justify-center items-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
) : projectIssues.count > 0 ? (
|
2022-11-29 14:19:39 +00:00
|
|
|
<>
|
2022-11-25 17:24:49 +00:00
|
|
|
{issueView === "list" ? (
|
|
|
|
<ListView
|
|
|
|
properties={properties}
|
|
|
|
groupedByIssues={groupedByIssues}
|
|
|
|
selectedGroup={groupByProperty}
|
|
|
|
setSelectedIssue={setSelectedIssue}
|
|
|
|
handleDeleteIssue={setDeleteIssue}
|
2022-12-13 15:52:44 +00:00
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
2022-11-25 17:24:49 +00:00
|
|
|
/>
|
|
|
|
) : (
|
2022-12-13 15:52:44 +00:00
|
|
|
<div className="h-screen">
|
2022-11-29 14:19:39 +00:00
|
|
|
<BoardView
|
|
|
|
properties={properties}
|
|
|
|
selectedGroup={groupByProperty}
|
|
|
|
groupedByIssues={groupedByIssues}
|
|
|
|
members={members}
|
2022-12-13 15:52:44 +00:00
|
|
|
handleDeleteIssue={setDeleteIssue}
|
|
|
|
partialUpdateIssue={partialUpdateIssue}
|
2022-11-29 14:19:39 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-11-25 17:24:49 +00:00
|
|
|
)}
|
2022-11-29 14:19:39 +00:00
|
|
|
</>
|
2022-11-25 17:24:49 +00:00
|
|
|
) : (
|
|
|
|
<div className="h-full w-full grid place-items-center px-4 sm:px-0">
|
|
|
|
<EmptySpace
|
|
|
|
title="You don't have any issue yet."
|
|
|
|
description="Issues help you track individual pieces of work. With Issues, keep track of what's going on, who is working on it, and what's done."
|
|
|
|
Icon={RectangleStackIcon}
|
|
|
|
>
|
|
|
|
<EmptySpaceItem
|
|
|
|
title="Create a new issue"
|
|
|
|
description={
|
|
|
|
<span>
|
|
|
|
Use <pre className="inline bg-gray-100 px-2 py-1 rounded">Ctrl/Command + I</pre>{" "}
|
|
|
|
shortcut to create a new issue
|
|
|
|
</span>
|
|
|
|
}
|
|
|
|
Icon={PlusIcon}
|
|
|
|
action={() => setIsOpen(true)}
|
|
|
|
/>
|
|
|
|
</EmptySpace>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-12-07 23:27:10 +00:00
|
|
|
</AppLayout>
|
2022-11-19 14:21:26 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-12-02 11:47:13 +00:00
|
|
|
export default withAuth(ProjectIssues);
|