2024-01-10 14:39:45 +00:00
|
|
|
import { FC } from "react";
|
2024-05-27 10:34:05 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-01-10 14:39:45 +00:00
|
|
|
import useSWR from "swr";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { TIssue } from "@plane/types";
|
2024-01-10 14:39:45 +00:00
|
|
|
// components
|
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useIssueDetail } from "@/hooks/store";
|
2024-01-10 14:39:45 +00:00
|
|
|
// types
|
2024-03-06 13:09:14 +00:00
|
|
|
import { IssueParentSiblingItem } from "./sibling-item";
|
2024-01-10 14:39:45 +00:00
|
|
|
|
|
|
|
export type TIssueParentSiblings = {
|
2024-05-27 10:34:05 +00:00
|
|
|
workspaceSlug: string;
|
2024-01-10 14:39:45 +00:00
|
|
|
currentIssue: TIssue;
|
|
|
|
parentIssue: TIssue;
|
|
|
|
};
|
|
|
|
|
2024-05-27 10:34:05 +00:00
|
|
|
export const IssueParentSiblings: FC<TIssueParentSiblings> = observer((props) => {
|
|
|
|
const { workspaceSlug, currentIssue, parentIssue } = props;
|
2024-01-10 14:39:45 +00:00
|
|
|
// hooks
|
|
|
|
const {
|
|
|
|
fetchSubIssues,
|
|
|
|
subIssues: { subIssuesByIssueId },
|
|
|
|
} = useIssueDetail();
|
|
|
|
|
|
|
|
const { isLoading } = useSWR(
|
2024-05-27 10:34:05 +00:00
|
|
|
parentIssue && parentIssue.project_id
|
|
|
|
? `ISSUE_PARENT_CHILD_ISSUES_${workspaceSlug}_${parentIssue.project_id}_${parentIssue.id}`
|
2024-01-10 14:39:45 +00:00
|
|
|
: null,
|
2024-05-27 10:34:05 +00:00
|
|
|
parentIssue && parentIssue.project_id
|
|
|
|
? () => fetchSubIssues(workspaceSlug, parentIssue.project_id, parentIssue.id)
|
2024-01-10 14:39:45 +00:00
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const subIssueIds = (parentIssue && subIssuesByIssueId(parentIssue.id)) || undefined;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{isLoading ? (
|
|
|
|
<div className="flex items-center gap-2 whitespace-nowrap px-1 py-1 text-left text-xs text-custom-text-200">
|
|
|
|
Loading
|
|
|
|
</div>
|
|
|
|
) : subIssueIds && subIssueIds.length > 0 ? (
|
2024-03-06 13:09:14 +00:00
|
|
|
subIssueIds.map(
|
2024-05-27 10:34:05 +00:00
|
|
|
(issueId) =>
|
|
|
|
currentIssue.id != issueId && (
|
|
|
|
<IssueParentSiblingItem key={issueId} workspaceSlug={workspaceSlug} issueId={issueId} />
|
|
|
|
)
|
2024-03-06 13:09:14 +00:00
|
|
|
)
|
2024-01-10 14:39:45 +00:00
|
|
|
) : (
|
|
|
|
<div className="flex items-center gap-2 whitespace-nowrap px-1 py-1 text-left text-xs text-custom-text-200">
|
|
|
|
No sibling issues
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2024-05-27 10:34:05 +00:00
|
|
|
});
|