diff --git a/web/components/issues/issue-detail/module-select.tsx b/web/components/issues/issue-detail/module-select.tsx index 1c4d80168..940ce9879 100644 --- a/web/components/issues/issue-detail/module-select.tsx +++ b/web/components/issues/issue-detail/module-select.tsx @@ -10,6 +10,7 @@ import { Spinner } from "@plane/ui"; import { cn } from "helpers/common.helper"; // types import type { TIssueOperations } from "./root"; +import { xor } from "lodash"; type TIssueModuleSelect = { className?: string; @@ -34,19 +35,15 @@ export const IssueModuleSelect: React.FC = observer((props) const handleIssueModuleChange = async (moduleIds: string[]) => { if (!issue || !issue.module_ids) return; - setIsUpdating(true); - - if (moduleIds.length === 0) - await issueOperations.removeModulesFromIssue?.(workspaceSlug, projectId, issueId, issue.module_ids); - else if (moduleIds.length > issue.module_ids.length) { - const newModuleIds = moduleIds.filter((m) => !issue.module_ids?.includes(m)); - await issueOperations.addModulesToIssue?.(workspaceSlug, projectId, issueId, newModuleIds); - } else if (moduleIds.length < issue.module_ids.length) { - const removedModuleIds = issue.module_ids.filter((m) => !moduleIds.includes(m)); - await issueOperations.removeModulesFromIssue?.(workspaceSlug, projectId, issueId, removedModuleIds); + const updatedModuleId = xor(issue.module_ids, moduleIds)[0]; + if (updatedModuleId !== undefined) { + if (issue.module_ids.includes(updatedModuleId)) { + await issueOperations.removeModulesFromIssue?.(workspaceSlug, projectId, issueId, [updatedModuleId]); + } else { + await issueOperations.addModulesToIssue?.(workspaceSlug, projectId, issueId, [updatedModuleId]); + } } - setIsUpdating(false); }; diff --git a/web/store/issue/module/issue.store.ts b/web/store/issue/module/issue.store.ts index c9ed459a1..e7f75604c 100644 --- a/web/store/issue/module/issue.store.ts +++ b/web/store/issue/module/issue.store.ts @@ -356,7 +356,7 @@ export class ModuleIssues extends IssueHelperStore implements IModuleIssues { runInAction(() => { moduleIds.forEach((moduleId) => { update(this.issues, moduleId, (moduleIssueIds = []) => { - if (moduleIssueIds.includes(issueId)) return moduleIssueIds; + if (moduleIssueIds.includes(issueId)) return pull(moduleIssueIds, issueId); else return uniq(concat(moduleIssueIds, [issueId])); }); update(this.rootStore.issues.issuesMap, [issueId, "module_ids"], (issueModuleIds = []) =>