import React, { useCallback } from "react"; import xor from "lodash/xor"; import { observer } from "mobx-react"; import { useParams, usePathname } from "next/navigation"; // types import { TIssue } from "@plane/types"; // components import { ModuleDropdown } from "@/components/dropdowns"; // constants import { EIssuesStoreType } from "@/constants/issue"; // hooks import { useEventTracker, useIssues } from "@/hooks/store"; type Props = { issue: TIssue; onClose: () => void; disabled: boolean; }; export const SpreadsheetModuleColumn: React.FC = observer((props) => { const { issue, disabled, onClose } = props; // router const { workspaceSlug } = useParams(); const pathname = usePathname(); // hooks const { captureIssueEvent } = useEventTracker(); const { issues: { changeModulesInIssue }, } = useIssues(EIssuesStoreType.MODULE); const handleModule = useCallback( async (moduleIds: string[] | null) => { if (!workspaceSlug || !issue || !issue.module_ids || !moduleIds) return; const updatedModuleIds = xor(issue.module_ids, moduleIds); const modulesToAdd: string[] = []; const modulesToRemove: string[] = []; for (const moduleId of updatedModuleIds) { if (issue.module_ids.includes(moduleId)) modulesToRemove.push(moduleId); else modulesToAdd.push(moduleId); } changeModulesInIssue(workspaceSlug.toString(), issue.project_id, issue.id, modulesToAdd, modulesToRemove); captureIssueEvent({ eventName: "Issue updated", payload: { ...issue, module_ids: moduleIds, element: "Spreadsheet layout", }, updates: { changed_property: "module_ids", change_details: { module_ids: moduleIds } }, path: pathname, }); }, [workspaceSlug, issue, changeModulesInIssue, captureIssueEvent, pathname] ); return (
); });