import { MutableRefObject } from "react"; import { observer } from "mobx-react-lite"; // components import { useCycle, useLabel, useMember, useModule, useProject, useProjectState } from "hooks/store"; import { GroupByColumnTypes, IGroupByColumn, TGroupedIssues, TIssue, IIssueDisplayProperties, IIssueMap, TSubGroupedIssues, TUnGroupedIssues, TIssueKanbanFilters, } from "@plane/types"; import { getGroupByColumns } from "../utils"; import { KanBan } from "./default"; import { HeaderGroupByCard } from "./headers/group-by-card"; import { HeaderSubGroupByCard } from "./headers/sub-group-by-card"; import { KanbanStoreType } from "./base-kanban-root"; // types // constants interface ISubGroupSwimlaneHeader { issueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues; sub_group_by: string | null; group_by: string | null; list: IGroupByColumn[]; kanbanFilters: TIssueKanbanFilters; handleKanbanFilters: (toggle: "group_by" | "sub_group_by", value: string) => void; storeType: KanbanStoreType; showEmptyGroup: boolean; } const getSubGroupHeaderIssuesCount = (issueIds: TSubGroupedIssues, groupById: string) => { let headerCount = 0; Object.keys(issueIds).map((groupState) => { headerCount = headerCount + (issueIds?.[groupState]?.[groupById]?.length || 0); }); return headerCount; }; const visibilitySubGroupByGroupCount = ( issueIds: TSubGroupedIssues, _list: IGroupByColumn, showEmptyGroup: boolean ): boolean => { let subGroupHeaderVisibility = true; if (showEmptyGroup) subGroupHeaderVisibility = true; else { if (getSubGroupHeaderIssuesCount(issueIds, _list.id) > 0) subGroupHeaderVisibility = true; else subGroupHeaderVisibility = false; } return subGroupHeaderVisibility; }; const SubGroupSwimlaneHeader: React.FC = ({ issueIds, sub_group_by, group_by, storeType, list, kanbanFilters, handleKanbanFilters, showEmptyGroup, }) => (
{list && list.length > 0 && list.map((_list: IGroupByColumn) => { const subGroupByVisibilityToggle = visibilitySubGroupByGroupCount( issueIds as TSubGroupedIssues, _list, showEmptyGroup ); if (subGroupByVisibilityToggle === false) return <>; return (
); })}
); interface ISubGroupSwimlane extends ISubGroupSwimlaneHeader { issuesMap: IIssueMap; issueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues; showEmptyGroup: boolean; displayProperties: IIssueDisplayProperties | undefined; updateIssue: ((projectId: string, issueId: string, data: Partial) => Promise) | undefined; quickActions: (issue: TIssue, customActionButton?: React.ReactElement) => React.ReactNode; kanbanFilters: TIssueKanbanFilters; handleKanbanFilters: (toggle: "group_by" | "sub_group_by", value: string) => void; isDragStarted?: boolean; disableIssueCreation?: boolean; storeType: KanbanStoreType; enableQuickIssueCreate: boolean; canEditProperties: (projectId: string | undefined) => boolean; addIssuesToView?: (issueIds: string[]) => Promise; quickAddCallback?: ( workspaceSlug: string, projectId: string, data: TIssue, viewId?: string ) => Promise; viewId?: string; scrollableContainerRef?: MutableRefObject; } const SubGroupSwimlane: React.FC = observer((props) => { const { issuesMap, issueIds, sub_group_by, group_by, list, storeType, updateIssue, quickActions, displayProperties, kanbanFilters, handleKanbanFilters, showEmptyGroup, enableQuickIssueCreate, canEditProperties, addIssuesToView, quickAddCallback, viewId, scrollableContainerRef, isDragStarted, } = props; const calculateIssueCount = (column_id: string) => { let issueCount = 0; const subGroupedIds = issueIds as TSubGroupedIssues; subGroupedIds?.[column_id] && Object.keys(subGroupedIds?.[column_id])?.forEach((_list: any) => { issueCount += subGroupedIds?.[column_id]?.[_list]?.length || 0; }); return issueCount; }; const visibilitySubGroupBy = (_list: IGroupByColumn): { showGroup: boolean; showIssues: boolean } => { const subGroupVisibility = { showGroup: true, showIssues: true, }; if (showEmptyGroup) subGroupVisibility.showGroup = true; else { if (calculateIssueCount(_list.id) > 0) subGroupVisibility.showGroup = true; else subGroupVisibility.showGroup = false; } if (kanbanFilters?.sub_group_by.includes(_list.id)) subGroupVisibility.showIssues = false; return subGroupVisibility; }; return (
{list && list.length > 0 && list.map((_list: any) => { const subGroupByVisibilityToggle = visibilitySubGroupBy(_list); if (subGroupByVisibilityToggle.showGroup === false) return <>; return (
{subGroupByVisibilityToggle.showIssues && (
getSubGroupHeaderIssuesCount(issueIds as TSubGroupedIssues, groupByListId) } />
)}
); })}
); }); export interface IKanBanSwimLanes { issuesMap: IIssueMap; issueIds: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues; displayProperties: IIssueDisplayProperties | undefined; sub_group_by: string | null; group_by: string | null; updateIssue: ((projectId: string, issueId: string, data: Partial) => Promise) | undefined; quickActions: (issue: TIssue, customActionButton?: React.ReactElement) => React.ReactNode; kanbanFilters: TIssueKanbanFilters; handleKanbanFilters: (toggle: "group_by" | "sub_group_by", value: string) => void; showEmptyGroup: boolean; isDragStarted?: boolean; disableIssueCreation?: boolean; storeType: KanbanStoreType; addIssuesToView?: (issueIds: string[]) => Promise; enableQuickIssueCreate: boolean; quickAddCallback?: ( workspaceSlug: string, projectId: string, data: TIssue, viewId?: string ) => Promise; viewId?: string; canEditProperties: (projectId: string | undefined) => boolean; scrollableContainerRef?: MutableRefObject; } export const KanBanSwimLanes: React.FC = observer((props) => { const { issuesMap, issueIds, displayProperties, sub_group_by, group_by, updateIssue, storeType, quickActions, kanbanFilters, handleKanbanFilters, showEmptyGroup, isDragStarted, disableIssueCreation, enableQuickIssueCreate, canEditProperties, addIssuesToView, quickAddCallback, viewId, scrollableContainerRef, } = props; const member = useMember(); const project = useProject(); const label = useLabel(); const cycle = useCycle(); const projectModule = useModule(); const projectState = useProjectState(); const groupByList = getGroupByColumns( group_by as GroupByColumnTypes, project, cycle, projectModule, label, projectState, member ); const subGroupByList = getGroupByColumns( sub_group_by as GroupByColumnTypes, project, cycle, projectModule, label, projectState, member ); if (!groupByList || !subGroupByList) return null; return (
{sub_group_by && ( )}
); });