forked from github/plane
9075f9441c
* style: added cta at the bottom of sidebar, added missing icons as well, showing dynamic workspace member count on workspace dropdown * refractor: running parallel request, made create/edit label function to async function * fix: sidebar dropdown content going below kanban items outside click detection in need help dropdown * refractor: making parallel api calls fix: create state input comes at bottom, create state input gets on focus automatically, form is getting submitted on enter click * refactoring file structure and signin page * style: changed text and added spinner for signing in loading * refractor: removed unused type * fix: my issue cta in profile page sending to 404 page * fix: added new s3 bucket url in next.config.js file increased image modal height * packaging UI components * eslint config * eslint fixes * refactoring changes * build fixes * minor fixes * adding todo comments for reference * refactor: cleared unused imports and re ordered imports * refactor: removed unused imports * fix: added workspace argument to useissues hook * refactor: removed api-routes file, unnecessary constants * refactor: created helpers folder, removed unnecessary constants * refactor: new context for issue view * refactoring issues page * build fixes * refactoring * refactor: create issue modal * refactor: module ui * fix: sub-issues mutation * fix: create more option in create issue modal * description form debounce issue * refactor: global component for assignees list * fix: link module interface * fix: priority icons and sub-issues count added * fix: cycle mutation in issue details page * fix: remove issue from cycle mutation * fix: create issue modal in home page * fix: removed unnecessary props * fix: updated create issue form status * fix: settings auth breaking * refactor: issue details page Co-authored-by: Dakshesh Jain <dakshesh.jain14@gmail.com> Co-authored-by: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Co-authored-by: venkatesh-soulpage <venkatesh.marreboyina@soulpageit.com> Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com> Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia1001@gmail.com>
412 lines
14 KiB
TypeScript
412 lines
14 KiB
TypeScript
import React, { useCallback, useEffect, useState } from "react";
|
|
import Link from "next/link";
|
|
import { useRouter } from "next/router";
|
|
import useSWR, { mutate } from "swr";
|
|
import { useForm } from "react-hook-form";
|
|
import { ChevronLeftIcon, ChevronRightIcon, PlusIcon } from "@heroicons/react/24/outline";
|
|
// services
|
|
import issuesService from "services/issues.service";
|
|
import projectService from "services/project.service";
|
|
// lib
|
|
import { requiredAuth } from "lib/auth";
|
|
// layouts
|
|
import AppLayout from "layouts/app-layout";
|
|
// components
|
|
import AddAsSubIssue from "components/project/issues/issue-detail/add-as-sub-issue";
|
|
import IssueDetailSidebar from "components/project/issues/issue-detail/issue-detail-sidebar";
|
|
import AddIssueComment from "components/project/issues/issue-detail/comment/issue-comment-section";
|
|
import IssueActivitySection from "components/project/issues/issue-detail/activity";
|
|
import {
|
|
IssueDescriptionForm,
|
|
IssueDescriptionFormValues,
|
|
SubIssueList,
|
|
CreateUpdateIssueModal,
|
|
} from "components/issues";
|
|
// ui
|
|
import { Loader, HeaderButton, CustomMenu } from "components/ui";
|
|
import { Breadcrumbs } from "components/breadcrumbs";
|
|
// types
|
|
import { IIssue } from "types";
|
|
import type { NextPage, NextPageContext } from "next";
|
|
// fetch-keys
|
|
import {
|
|
PROJECT_DETAILS,
|
|
PROJECT_ISSUES_LIST,
|
|
PROJECT_ISSUES_ACTIVITY,
|
|
ISSUE_DETAILS,
|
|
SUB_ISSUES,
|
|
} from "constants/fetch-keys";
|
|
|
|
const defaultValues = {
|
|
name: "",
|
|
description: "",
|
|
description_html: "",
|
|
state: "",
|
|
assignees_list: [],
|
|
priority: "low",
|
|
blockers_list: [],
|
|
blocked_list: [],
|
|
target_date: new Date().toString(),
|
|
issue_cycle: null,
|
|
labels_list: [],
|
|
};
|
|
|
|
const IssueDetailsPage: NextPage = () => {
|
|
const router = useRouter();
|
|
const { workspaceSlug, projectId, issueId } = router.query;
|
|
// states
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
const [isAddAsSubIssueOpen, setIsAddAsSubIssueOpen] = useState(false);
|
|
const [preloadedData, setPreloadedData] = useState<
|
|
(Partial<IIssue> & { actionType: "createIssue" | "edit" | "delete" }) | undefined
|
|
>(undefined);
|
|
|
|
const { data: issueDetails, mutate: mutateIssueDetails } = useSWR<IIssue | undefined>(
|
|
issueId && workspaceSlug && projectId ? ISSUE_DETAILS(issueId as string) : null,
|
|
issueId && workspaceSlug && projectId
|
|
? () =>
|
|
issuesService.retrieve(
|
|
workspaceSlug?.toString(),
|
|
projectId?.toString(),
|
|
issueId?.toString()
|
|
)
|
|
: null
|
|
);
|
|
|
|
const { data: subIssues } = useSWR(
|
|
issueId && workspaceSlug && projectId ? SUB_ISSUES(issueId as string) : null,
|
|
issueId && workspaceSlug && projectId
|
|
? () =>
|
|
issuesService.subIssues(workspaceSlug as string, projectId as string, issueId as string)
|
|
: null
|
|
);
|
|
|
|
const { data: activeProject } = useSWR(
|
|
workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
|
|
workspaceSlug && projectId
|
|
? () => projectService.getProject(workspaceSlug as string, projectId as string)
|
|
: null
|
|
);
|
|
|
|
const { data: issues } = useSWR(
|
|
workspaceSlug && projectId
|
|
? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
|
|
: null,
|
|
workspaceSlug && projectId
|
|
? () => issuesService.getIssues(workspaceSlug as string, projectId as string)
|
|
: null
|
|
);
|
|
|
|
const { data: issueActivities, mutate: mutateIssueActivities } = useSWR(
|
|
workspaceSlug && projectId && issueId ? PROJECT_ISSUES_ACTIVITY : null,
|
|
workspaceSlug && projectId && issueId
|
|
? () =>
|
|
issuesService.getIssueActivities(
|
|
workspaceSlug as string,
|
|
projectId as string,
|
|
issueId as string
|
|
)
|
|
: null
|
|
);
|
|
|
|
const { reset, control, watch } = useForm<IIssue>({
|
|
defaultValues,
|
|
});
|
|
|
|
const prevIssue = issues?.results[issues?.results.findIndex((issue) => issue.id === issueId) - 1];
|
|
const nextIssue = issues?.results[issues?.results.findIndex((issue) => issue.id === issueId) + 1];
|
|
|
|
const siblingIssues =
|
|
issueDetails &&
|
|
issues?.results.filter((i) => i.parent === issueDetails.parent && i.id !== issueId);
|
|
|
|
useEffect(() => {
|
|
if (issueDetails) {
|
|
mutateIssueActivities();
|
|
reset({
|
|
...issueDetails,
|
|
blockers_list:
|
|
issueDetails.blockers_list ??
|
|
issueDetails.blocker_issues?.map((issue) => issue.blocker_issue_detail?.id),
|
|
blocked_list:
|
|
issueDetails.blocked_list ??
|
|
issueDetails.blocked_issues?.map((issue) => issue.blocked_issue_detail?.id),
|
|
assignees_list:
|
|
issueDetails.assignees_list ?? issueDetails.assignee_details?.map((user) => user.id),
|
|
labels_list: issueDetails.labels_list ?? issueDetails.labels,
|
|
labels: issueDetails.labels_list ?? issueDetails.labels,
|
|
});
|
|
}
|
|
}, [issueDetails, reset, mutateIssueActivities]);
|
|
|
|
const submitChanges = useCallback(
|
|
(formData: Partial<IIssue>) => {
|
|
if (!workspaceSlug || !activeProject || !issueId) return;
|
|
|
|
const payload = { ...formData };
|
|
issuesService
|
|
.patchIssue(workspaceSlug as string, projectId as string, issueId as string, payload)
|
|
.then((res) => {
|
|
mutateIssueDetails();
|
|
mutateIssueActivities();
|
|
})
|
|
.catch((e) => {
|
|
console.error(e);
|
|
});
|
|
},
|
|
[activeProject, workspaceSlug, issueId, projectId, mutateIssueDetails, mutateIssueActivities]
|
|
);
|
|
|
|
const handleSubIssueRemove = (issueId: string) => {
|
|
if (workspaceSlug && activeProject) {
|
|
issuesService
|
|
.patchIssue(workspaceSlug as string, activeProject.id, issueId, { parent: null })
|
|
.then((res) => {
|
|
mutate(SUB_ISSUES(issueDetails?.id ?? ""));
|
|
mutateIssueActivities();
|
|
})
|
|
.catch((e) => {
|
|
console.error(e);
|
|
});
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Handling the debounce submit by updating the issue with name, description and description_html
|
|
* @param values IssueDescriptionFormValues
|
|
*/
|
|
const handleDescriptionFormSubmit = useCallback(
|
|
(values: IssueDescriptionFormValues) => {
|
|
if (workspaceSlug && projectId && issueId) {
|
|
issuesService
|
|
.updateIssue(workspaceSlug?.toString(), projectId.toString(), issueId.toString(), values)
|
|
.then((res) => {
|
|
console.log(res);
|
|
mutateIssueActivities();
|
|
});
|
|
}
|
|
},
|
|
[workspaceSlug, projectId, issueId, mutateIssueActivities]
|
|
);
|
|
|
|
return (
|
|
<AppLayout
|
|
noPadding={true}
|
|
bg="secondary"
|
|
breadcrumbs={
|
|
<Breadcrumbs>
|
|
<Breadcrumbs.BreadcrumbItem
|
|
title={`${activeProject?.name ?? "Project"} Issues`}
|
|
link={`/${workspaceSlug}/projects/${activeProject?.id}/issues`}
|
|
/>
|
|
<Breadcrumbs.BreadcrumbItem
|
|
title={`Issue ${activeProject?.identifier ?? "Project"}-${
|
|
issueDetails?.sequence_id ?? "..."
|
|
} Details`}
|
|
/>
|
|
</Breadcrumbs>
|
|
}
|
|
right={
|
|
<div className="flex items-center gap-2">
|
|
<HeaderButton
|
|
Icon={ChevronLeftIcon}
|
|
label="Previous"
|
|
className={!prevIssue ? "cursor-not-allowed opacity-70" : ""}
|
|
onClick={() => {
|
|
if (!prevIssue) return;
|
|
router.push(`/${workspaceSlug}/projects/${prevIssue.project}/issues/${prevIssue.id}`);
|
|
}}
|
|
/>
|
|
<HeaderButton
|
|
Icon={ChevronRightIcon}
|
|
disabled={!nextIssue}
|
|
label="Next"
|
|
className={!nextIssue ? "cursor-not-allowed opacity-70" : ""}
|
|
onClick={() => {
|
|
if (!nextIssue) return;
|
|
router.push(
|
|
`/${workspaceSlug}/projects/${nextIssue.project}/issues/${nextIssue?.id}`
|
|
);
|
|
}}
|
|
position="reverse"
|
|
/>
|
|
</div>
|
|
}
|
|
>
|
|
{isOpen && (
|
|
<CreateUpdateIssueModal
|
|
isOpen={isOpen}
|
|
handleClose={() => setIsOpen(false)}
|
|
prePopulateData={{
|
|
...preloadedData,
|
|
}}
|
|
/>
|
|
)}
|
|
{isAddAsSubIssueOpen && (
|
|
<AddAsSubIssue
|
|
isOpen={isAddAsSubIssueOpen}
|
|
setIsOpen={setIsAddAsSubIssueOpen}
|
|
parent={issueDetails}
|
|
/>
|
|
)}
|
|
{issueDetails && activeProject ? (
|
|
<div className="flex h-full">
|
|
<div className="basis-2/3 space-y-5 divide-y-2 p-5">
|
|
<div className="rounded-lg">
|
|
{issueDetails?.parent && issueDetails.parent !== "" ? (
|
|
<div className="mb-5 flex w-min items-center gap-2 whitespace-nowrap rounded bg-gray-100 p-2 text-xs">
|
|
<Link
|
|
href={`/${workspaceSlug}/projects/${activeProject.id}/issues/${issueDetails.parent}`}
|
|
>
|
|
<a className="flex items-center gap-2">
|
|
<span
|
|
className="block h-1.5 w-1.5 rounded-full"
|
|
style={{
|
|
backgroundColor: issueDetails?.state_detail?.color,
|
|
}}
|
|
/>
|
|
<span className="flex-shrink-0 text-gray-600">
|
|
{activeProject.identifier}-
|
|
{issues?.results.find((i) => i.id === issueDetails.parent)?.sequence_id}
|
|
</span>
|
|
<span className="truncate font-medium">
|
|
{issues?.results
|
|
.find((i) => i.id === issueDetails.parent)
|
|
?.name.substring(0, 50)}
|
|
</span>
|
|
</a>
|
|
</Link>
|
|
|
|
<CustomMenu ellipsis optionsPosition="left">
|
|
{siblingIssues && siblingIssues.length > 0 ? (
|
|
siblingIssues.map((issue) => (
|
|
<CustomMenu.MenuItem key={issue.id}>
|
|
<Link
|
|
href={`/${workspaceSlug}/projects/${activeProject.id}/issues/${issue.id}`}
|
|
>
|
|
<a>
|
|
{activeProject.identifier}-{issue.sequence_id}
|
|
</a>
|
|
</Link>
|
|
</CustomMenu.MenuItem>
|
|
))
|
|
) : (
|
|
<CustomMenu.MenuItem className="flex items-center gap-2 whitespace-nowrap p-2 text-left text-xs text-gray-900">
|
|
No other sibling issues
|
|
</CustomMenu.MenuItem>
|
|
)}
|
|
</CustomMenu>
|
|
</div>
|
|
) : null}
|
|
<IssueDescriptionForm
|
|
issue={issueDetails}
|
|
handleSubmit={handleDescriptionFormSubmit}
|
|
/>
|
|
<div className="mt-2">
|
|
{issueId && workspaceSlug && projectId && subIssues?.length > 0 ? (
|
|
<SubIssueList
|
|
issues={subIssues}
|
|
parentIssue={issueDetails}
|
|
projectId={projectId?.toString()}
|
|
workspaceSlug={workspaceSlug?.toString()}
|
|
handleSubIssueRemove={handleSubIssueRemove}
|
|
/>
|
|
) : (
|
|
<CustomMenu
|
|
label={
|
|
<>
|
|
<PlusIcon className="h-3 w-3" />
|
|
Add sub-issue
|
|
</>
|
|
}
|
|
optionsPosition="left"
|
|
noBorder
|
|
>
|
|
<CustomMenu.MenuItem
|
|
onClick={() => {
|
|
setIsOpen(true);
|
|
setPreloadedData({
|
|
parent: issueDetails.id,
|
|
actionType: "createIssue",
|
|
});
|
|
}}
|
|
>
|
|
Create new
|
|
</CustomMenu.MenuItem>
|
|
<CustomMenu.MenuItem
|
|
onClick={() => {
|
|
setIsAddAsSubIssueOpen(true);
|
|
setPreloadedData({
|
|
parent: issueDetails.id,
|
|
actionType: "createIssue",
|
|
});
|
|
}}
|
|
>
|
|
Add an existing issue
|
|
</CustomMenu.MenuItem>
|
|
</CustomMenu>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="space-y-5 bg-secondary pt-3">
|
|
<h3 className="text-lg">Comments/Activity</h3>
|
|
<IssueActivitySection
|
|
issueActivities={issueActivities || []}
|
|
mutate={mutateIssueActivities}
|
|
/>
|
|
<AddIssueComment mutate={mutateIssueActivities} />
|
|
</div>
|
|
</div>
|
|
<div className="basis-1/3 space-y-5 border-l p-5">
|
|
{/* TODO add flex-grow, if needed */}
|
|
<IssueDetailSidebar
|
|
control={control}
|
|
issueDetail={issueDetails}
|
|
submitChanges={submitChanges}
|
|
watch={watch}
|
|
/>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<Loader className="flex h-full gap-5 p-5">
|
|
<div className="basis-2/3 space-y-2">
|
|
<Loader.Item height="30px" width="40%" />
|
|
<Loader.Item height="15px" width="60%" light />
|
|
<Loader.Item height="15px" width="60%" light />
|
|
<Loader.Item height="15px" width="40%" light />
|
|
</div>
|
|
<div className="basis-1/3 space-y-3">
|
|
<Loader.Item height="30px" />
|
|
<Loader.Item height="30px" />
|
|
<Loader.Item height="30px" />
|
|
<Loader.Item height="30px" />
|
|
</div>
|
|
</Loader>
|
|
)}
|
|
</AppLayout>
|
|
);
|
|
};
|
|
|
|
export const getServerSideProps = async (ctx: NextPageContext) => {
|
|
const user = await requiredAuth(ctx.req?.headers.cookie);
|
|
|
|
const redirectAfterSignIn = ctx.req?.url;
|
|
|
|
if (!user) {
|
|
return {
|
|
redirect: {
|
|
destination: `/signin?next=${redirectAfterSignIn}`,
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
return {
|
|
props: {
|
|
user,
|
|
},
|
|
};
|
|
};
|
|
|
|
export default IssueDetailsPage;
|