fix: module select fix

This commit is contained in:
Anmol Singh Bhatia 2024-02-20 20:52:38 +05:30
parent 95871b0049
commit c5d70db237
2 changed files with 9 additions and 12 deletions

View File

@ -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<TIssueModuleSelect> = 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);
};

View File

@ -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 = []) =>