import { useEffect, useRef } from "react"; import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine"; import { autoScrollForElements } from "@atlaskit/pragmatic-drag-and-drop-auto-scroll/element"; import { observer } from "mobx-react"; // types import { GroupByColumnTypes, TGroupedIssues, TIssue, IIssueDisplayProperties, TIssueMap, TIssueGroupByOptions, TIssueOrderByOptions, IGroupByColumn, } from "@plane/types"; // components import { MultipleSelectGroup } from "@/components/core"; import { IssueBulkOperationsRoot } from "@/components/issues"; // constants import { ALL_ISSUES } from "@/constants/issue"; // hooks import { useCycle, useLabel, useMember, useModule, useProject, useProjectState } from "@/hooks/store"; import { useIssueStoreType } from "@/hooks/use-issue-layout-store"; // utils import { getGroupByColumns, isWorkspaceLevel, GroupDropLocation } from "../utils"; import { ListGroup } from "./list-group"; import { TRenderQuickActions } from "./list-view-types"; export interface IList { groupedIssueIds: TGroupedIssues; issuesMap: TIssueMap; group_by: TIssueGroupByOptions | null; orderBy: TIssueOrderByOptions | undefined; updateIssue: ((projectId: string | null, issueId: string, data: Partial) => Promise) | undefined; quickActions: TRenderQuickActions; displayProperties: IIssueDisplayProperties | undefined; enableIssueQuickAdd: boolean; showEmptyGroup?: boolean; canEditProperties: (projectId: string | undefined) => boolean; quickAddCallback?: (projectId: string | null | undefined, data: TIssue) => Promise; disableIssueCreation?: boolean; handleOnDrop: (source: GroupDropLocation, destination: GroupDropLocation) => Promise; addIssuesToView?: (issueIds: string[]) => Promise; isCompletedCycle?: boolean; loadMoreIssues: (groupId?: string) => void; } export const List: React.FC = observer((props) => { const { groupedIssueIds, issuesMap, group_by, orderBy, updateIssue, quickActions, displayProperties, enableIssueQuickAdd, showEmptyGroup, canEditProperties, quickAddCallback, disableIssueCreation, handleOnDrop, addIssuesToView, isCompletedCycle = false, loadMoreIssues, } = props; const storeType = useIssueStoreType(); // store hooks const member = useMember(); const project = useProject(); const label = useLabel(); const projectState = useProjectState(); const cycle = useCycle(); const projectModule = useModule(); const containerRef = useRef(null); const groups = getGroupByColumns( group_by as GroupByColumnTypes, project, cycle, projectModule, label, projectState, member, true, isWorkspaceLevel(storeType) ); // Enable Auto Scroll for Main Kanban useEffect(() => { const element = containerRef.current; if (!element) return; return combine( autoScrollForElements({ element, }) ); }, [containerRef]); if (!groups) return null; const getGroupIndex = (groupId: string | undefined) => groups.findIndex(({ id }) => id === groupId); const is_list = group_by === null ? true : false; // create groupIds array and entities object for bulk ops const groupIds = groups.map((g) => g.id); const orderedGroups: Record = {}; groupIds.forEach((gID) => { orderedGroups[gID] = []; }); let entities: Record = {}; if (is_list) { entities = Object.assign(orderedGroups, { [groupIds[0]]: groupedIssueIds[ALL_ISSUES] }); } else if(Array.isArray(groupedIssueIds[groupIds[0]])){ entities = Object.assign(orderedGroups, { ...groupedIssueIds }); } else { entities = orderedGroups; } return (
{groups && ( {(helpers) => ( <>
{groups.map((group: IGroupByColumn) => ( ))}
)}
)}
); });