2023-09-21 10:09:45 +00:00
|
|
|
import React from "react";
|
|
|
|
// swr
|
|
|
|
import useSWR from "swr";
|
|
|
|
// components
|
|
|
|
import { SubIssues } from "./issue";
|
|
|
|
// types
|
|
|
|
import { ICurrentUserResponse, IIssue } from "types";
|
2023-09-21 13:42:20 +00:00
|
|
|
import { ISubIssuesRootLoaders, ISubIssuesRootLoadersHandler } from "./root";
|
2023-09-21 10:09:45 +00:00
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
// fetch keys
|
|
|
|
import { SUB_ISSUES } from "constants/fetch-keys";
|
|
|
|
|
|
|
|
export interface ISubIssuesRootList {
|
|
|
|
workspaceSlug: string;
|
|
|
|
projectId: string;
|
|
|
|
parentIssue: IIssue;
|
|
|
|
spacingLeft?: number;
|
|
|
|
user: ICurrentUserResponse | undefined;
|
|
|
|
editable: boolean;
|
|
|
|
removeIssueFromSubIssues: (parentIssueId: string, issue: IIssue) => void;
|
2023-09-21 13:42:20 +00:00
|
|
|
issuesLoader: ISubIssuesRootLoaders;
|
|
|
|
handleIssuesLoader: ({ key, issueId }: ISubIssuesRootLoadersHandler) => void;
|
2023-09-21 10:09:45 +00:00
|
|
|
copyText: (text: string) => void;
|
|
|
|
handleIssueCrudOperation: (
|
|
|
|
key: "create" | "existing" | "edit" | "delete",
|
|
|
|
issueId: string,
|
|
|
|
issue?: IIssue | null
|
|
|
|
) => void;
|
2023-09-26 07:39:08 +00:00
|
|
|
setPeekParentId: (id: string) => void;
|
2023-09-21 10:09:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const SubIssuesRootList: React.FC<ISubIssuesRootList> = ({
|
|
|
|
workspaceSlug,
|
|
|
|
projectId,
|
|
|
|
parentIssue,
|
|
|
|
spacingLeft = 10,
|
|
|
|
user,
|
|
|
|
editable,
|
|
|
|
removeIssueFromSubIssues,
|
2023-09-21 13:42:20 +00:00
|
|
|
issuesLoader,
|
|
|
|
handleIssuesLoader,
|
2023-09-21 10:09:45 +00:00
|
|
|
copyText,
|
|
|
|
handleIssueCrudOperation,
|
2023-09-26 07:39:08 +00:00
|
|
|
setPeekParentId,
|
2023-09-21 10:09:45 +00:00
|
|
|
}) => {
|
|
|
|
const { data: issues, isLoading } = useSWR(
|
|
|
|
workspaceSlug && projectId && parentIssue && parentIssue?.id
|
|
|
|
? SUB_ISSUES(parentIssue?.id)
|
|
|
|
: null,
|
|
|
|
workspaceSlug && projectId && parentIssue && parentIssue?.id
|
|
|
|
? () => issuesService.subIssues(workspaceSlug, projectId, parentIssue.id)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-09-21 13:42:20 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
if (isLoading) {
|
|
|
|
handleIssuesLoader({ key: "sub_issues", issueId: parentIssue?.id });
|
|
|
|
} else {
|
|
|
|
if (issuesLoader.sub_issues.includes(parentIssue?.id)) {
|
|
|
|
handleIssuesLoader({ key: "sub_issues", issueId: parentIssue?.id });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [isLoading]);
|
|
|
|
|
2023-09-21 10:09:45 +00:00
|
|
|
return (
|
|
|
|
<div className="relative">
|
|
|
|
{issues &&
|
|
|
|
issues.sub_issues &&
|
|
|
|
issues.sub_issues.length > 0 &&
|
|
|
|
issues.sub_issues.map((issue: IIssue) => (
|
|
|
|
<SubIssues
|
|
|
|
key={`${issue?.id}`}
|
|
|
|
workspaceSlug={workspaceSlug}
|
|
|
|
projectId={projectId}
|
|
|
|
parentIssue={parentIssue}
|
|
|
|
issue={issue}
|
|
|
|
spacingLeft={spacingLeft}
|
|
|
|
user={user}
|
|
|
|
editable={editable}
|
|
|
|
removeIssueFromSubIssues={removeIssueFromSubIssues}
|
2023-09-21 13:42:20 +00:00
|
|
|
issuesLoader={issuesLoader}
|
|
|
|
handleIssuesLoader={handleIssuesLoader}
|
2023-09-21 10:09:45 +00:00
|
|
|
copyText={copyText}
|
|
|
|
handleIssueCrudOperation={handleIssueCrudOperation}
|
2023-09-26 07:39:08 +00:00
|
|
|
setPeekParentId={setPeekParentId}
|
2023-09-21 10:09:45 +00:00
|
|
|
/>
|
|
|
|
))}
|
|
|
|
|
|
|
|
<div
|
|
|
|
className={`absolute top-0 bottom-0 ${
|
|
|
|
spacingLeft > 10 ? `border-l border-custom-border-100` : ``
|
|
|
|
}`}
|
|
|
|
style={{ left: `${spacingLeft - 12}px` }}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|