import React, { FC } from "react"; import { observer } from "mobx-react"; import { useParams, usePathname } from "next/navigation"; // lucide icons import { Minimize2, Maximize2, Circle, Plus } from "lucide-react"; import { TIssue, ISearchIssueResponse, TIssueKanbanFilters, TIssueGroupByOptions } from "@plane/types"; // ui import { CustomMenu, TOAST_TYPE, setToast } from "@plane/ui"; // components import { ExistingIssuesListModal } from "@/components/core"; import { CreateUpdateIssueModal } from "@/components/issues"; // constants // hooks import { useEventTracker } from "@/hooks/store"; // types import { KanbanStoreType } from "../base-kanban-root"; interface IHeaderGroupByCard { sub_group_by: TIssueGroupByOptions | undefined; group_by: TIssueGroupByOptions | undefined; column_id: string; icon?: React.ReactNode; title: string; count: number; kanbanFilters: TIssueKanbanFilters; handleKanbanFilters: any; issuePayload: Partial; disableIssueCreation?: boolean; storeType: KanbanStoreType; addIssuesToView?: (issueIds: string[]) => Promise; } export const HeaderGroupByCard: FC = observer((props) => { const { sub_group_by, column_id, icon, title, count, kanbanFilters, handleKanbanFilters, issuePayload, disableIssueCreation, storeType, addIssuesToView, } = props; const verticalAlignPosition = sub_group_by ? false : kanbanFilters?.group_by.includes(column_id); // states const [isOpen, setIsOpen] = React.useState(false); const [openExistingIssueListModal, setOpenExistingIssueListModal] = React.useState(false); // hooks const { setTrackElement } = useEventTracker(); // router const { workspaceSlug, projectId, moduleId, cycleId } = useParams(); const pathname = usePathname(); const isDraftIssue = pathname.includes("draft-issue"); const renderExistingIssueModal = moduleId || cycleId; const ExistingIssuesListModalPayload = moduleId ? { module: moduleId.toString() } : { cycle: true }; const handleAddIssuesToView = async (data: ISearchIssueResponse[]) => { if (!workspaceSlug || !projectId) return; const issues = data.map((i) => i.id); try { await addIssuesToView?.(issues); setToast({ type: TOAST_TYPE.SUCCESS, title: "Success!", message: "Issues added to the cycle successfully.", }); } catch (error) { setToast({ type: TOAST_TYPE.ERROR, title: "Error!", message: "Selected issues could not be added to the cycle. Please try again.", }); } }; return ( <> setIsOpen(false)} data={issuePayload} storeType={storeType} isDraft={isDraftIssue} /> {renderExistingIssueModal && ( setOpenExistingIssueListModal(false)} searchParams={ExistingIssuesListModalPayload} handleOnSubmit={handleAddIssuesToView} /> )}
{icon ? icon : }
{title}
{count || 0}
{sub_group_by === null && (
handleKanbanFilters("group_by", column_id)} > {verticalAlignPosition ? ( ) : ( )}
)} {!disableIssueCreation && (renderExistingIssueModal ? ( } placement="bottom-end" > { setTrackElement("Kanban layout"); setIsOpen(true); }} > Create issue { setTrackElement("Kanban layout"); setOpenExistingIssueListModal(true); }} > Add an existing issue ) : (
{ setTrackElement("Kanban layout"); setIsOpen(true); }} >
))}
); });