plane/web/components/issues/issue-layouts/calendar/utils.ts
2024-03-04 18:20:18 +05:30

43 lines
1.6 KiB
TypeScript

import { DraggableLocation } from "@hello-pangea/dnd";
import { ICycleIssues } from "oldStore/issue/cycle";
import { IModuleIssues } from "oldStore/issue/module";
import { IProjectIssues } from "oldStore/issue/project";
import { IProjectViewIssues } from "oldStore/issue/project-views";
import { TGroupedIssues, IIssueMap } from "@plane/types";
export const handleDragDrop = async (
source: DraggableLocation,
destination: DraggableLocation,
workspaceSlug: string | undefined,
projectId: string | undefined,
store: IProjectIssues | IModuleIssues | ICycleIssues | IProjectViewIssues,
issueMap: IIssueMap,
issueWithIds: TGroupedIssues,
viewId: string | null = null // it can be moduleId, cycleId
) => {
if (!issueMap || !issueWithIds || !workspaceSlug || !projectId) return;
const sourceColumnId = source?.droppableId || null;
const destinationColumnId = destination?.droppableId || null;
if (!workspaceSlug || !projectId || !sourceColumnId || !destinationColumnId) return;
if (sourceColumnId === destinationColumnId) return;
// horizontal
if (sourceColumnId != destinationColumnId) {
const sourceIssues = issueWithIds[sourceColumnId] || [];
const [removed] = sourceIssues.splice(source.index, 1);
const removedIssueDetail = issueMap[removed];
const updateIssue = {
id: removedIssueDetail?.id,
target_date: destinationColumnId,
};
if (viewId) return await store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue, viewId);
else return await store?.updateIssue(workspaceSlug, projectId, updateIssue.id, updateIssue);
}
};