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, TUnGroupedIssues, IGroupByColumn, TIssueOrderByOptions, TIssueGroupByOptions, } from "@plane/types"; // components import { MultipleSelectGroup } from "@/components/core"; import { IssueBulkOperationsRoot } from "@/components/issues"; // hooks import { EIssuesStoreType } from "@/constants/issue"; import { useCycle, useLabel, useMember, useModule, useProject, useProjectState } from "@/hooks/store"; // utils import { getGroupByColumns, isWorkspaceLevel, GroupDropLocation } from "../utils"; import { ListGroup } from "./list-group"; import { TRenderQuickActions } from "./list-view-types"; export interface IGroupByList { issueIds: TGroupedIssues | TUnGroupedIssues | any; issuesMap: TIssueMap; group_by: TIssueGroupByOptions | null; orderBy: TIssueOrderByOptions | undefined; updateIssue: ((projectId: string, issueId: string, data: Partial) => Promise) | undefined; quickActions: TRenderQuickActions; displayProperties: IIssueDisplayProperties | undefined; enableIssueQuickAdd: boolean; showEmptyGroup?: boolean; canEditProperties: (projectId: string | undefined) => boolean; quickAddCallback?: ( workspaceSlug: string, projectId: string, data: TIssue, viewId?: string ) => Promise; disableIssueCreation?: boolean; storeType: EIssuesStoreType; handleOnDrop: (source: GroupDropLocation, destination: GroupDropLocation) => Promise; addIssuesToView?: (issueIds: string[]) => Promise; viewId?: string; isCompletedCycle?: boolean; } const GroupByList: React.FC = observer((props) => { const { issueIds, issuesMap, group_by, orderBy, updateIssue, quickActions, displayProperties, enableIssueQuickAdd, showEmptyGroup, canEditProperties, quickAddCallback, viewId, disableIssueCreation, storeType, handleOnDrop, addIssuesToView, isCompletedCycle = false, } = props; // 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 validateEmptyIssueGroups = (issues: TIssue[]) => { const issuesCount = issues?.length || 0; if (!showEmptyGroup && issuesCount <= 0) return false; return true; }; 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]]: issueIds }); } else { entities = Object.assign(orderedGroups, { ...issueIds }); } return (
{groups && ( {(helpers) => ( <>
{groups.map( (group: IGroupByColumn) => validateEmptyIssueGroups(is_list ? issueIds : issueIds?.[group.id]) && ( ) )}
)}
)}
); }); GroupByList.displayName = "GroupByList"; export interface IList { issueIds: TGroupedIssues | TUnGroupedIssues | any; issuesMap: TIssueMap; group_by: TIssueGroupByOptions | null; orderBy: TIssueOrderByOptions | undefined; updateIssue: ((projectId: string, issueId: string, data: Partial) => Promise) | undefined; quickActions: TRenderQuickActions; displayProperties: IIssueDisplayProperties | undefined; showEmptyGroup: boolean; enableIssueQuickAdd: boolean; canEditProperties: (projectId: string | undefined) => boolean; quickAddCallback?: ( workspaceSlug: string, projectId: string, data: TIssue, viewId?: string ) => Promise; viewId?: string; disableIssueCreation?: boolean; storeType: EIssuesStoreType; handleOnDrop: (source: GroupDropLocation, destination: GroupDropLocation) => Promise; addIssuesToView?: (issueIds: string[]) => Promise; isCompletedCycle?: boolean; } export const List: React.FC = (props) => { const { issueIds, issuesMap, group_by, orderBy, updateIssue, quickActions, quickAddCallback, viewId, displayProperties, showEmptyGroup, enableIssueQuickAdd, canEditProperties, disableIssueCreation, storeType, handleOnDrop, addIssuesToView, isCompletedCycle = false, } = props; return (
); };