Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-1492] fix: resolved issue creation error in layouts while group_by and sub_group_by filters applied in quick add #4682

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions web/store/issue/cycle/issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,20 @@ export class CycleIssues extends IssueHelperStore implements ICycleIssues {
const cycleIssueIds = this.issues[cycleId];
if (!cycleIssueIds) return;

const _issues = this.rootIssueStore.issues.getIssuesByIds(cycleIssueIds, "un-archived");
if (!_issues) return [];
const currentIssues = this.rootIssueStore.issues.getIssuesByIds(cycleIssueIds, "un-archived");
if (!currentIssues) return [];

let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues = [];

if (layout === "list" && orderBy) {
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, _issues);
else issues = this.unGroupedIssues(orderBy, _issues);
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, currentIssues);
else issues = this.unGroupedIssues(orderBy, currentIssues);
} else if (layout === "kanban" && groupBy && orderBy) {
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, _issues);
else issues = this.groupedIssues(groupBy, orderBy, _issues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", _issues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", _issues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", _issues);
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, currentIssues);
else issues = this.groupedIssues(groupBy, orderBy, currentIssues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", currentIssues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", currentIssues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", currentIssues);

return issues;
}
Expand Down Expand Up @@ -301,14 +301,17 @@ export class CycleIssues extends IssueHelperStore implements ICycleIssues {
});
}

if (data.module_ids && data.module_ids.length > 0) {
const currentModuleIds =
data.module_ids && data.module_ids.length > 0 ? data.module_ids.filter((moduleId) => moduleId != "None") : [];

if (currentModuleIds.length > 0) {
await this.rootStore.moduleIssues.changeModulesInIssue(
workspaceSlug,
projectId,
response.id,
data.module_ids,
currentModuleIds,
[]
)
);
}

this.rootIssueStore.rootStore.cycle.fetchCycleDetails(workspaceSlug, projectId, cycleId);
Expand Down
24 changes: 12 additions & 12 deletions web/store/issue/module/issue.store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import concat from "lodash/concat";
import pull from "lodash/pull";
import isEmpty from "lodash/isEmpty";
import set from "lodash/set";
import uniq from "lodash/uniq";
import update from "lodash/update";
Expand Down Expand Up @@ -148,20 +147,20 @@ export class ModuleIssues extends IssueHelperStore implements IModuleIssues {
const moduleIssueIds = this.issues[moduleId];
if (!moduleIssueIds) return;

const _issues = this.rootIssueStore.issues.getIssuesByIds(moduleIssueIds, "un-archived");
if (!_issues) return [];
const currentIssues = this.rootIssueStore.issues.getIssuesByIds(moduleIssueIds, "un-archived");
if (!currentIssues) return [];

let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues = [];

if (layout === "list" && orderBy) {
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, _issues);
else issues = this.unGroupedIssues(orderBy, _issues);
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, currentIssues);
else issues = this.unGroupedIssues(orderBy, currentIssues);
} else if (layout === "kanban" && groupBy && orderBy) {
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, _issues);
else issues = this.groupedIssues(groupBy, orderBy, _issues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", _issues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", _issues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", _issues);
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, currentIssues);
else issues = this.groupedIssues(groupBy, orderBy, currentIssues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", currentIssues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", currentIssues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", currentIssues);

return issues;
}
Expand Down Expand Up @@ -302,8 +301,9 @@ export class ModuleIssues extends IssueHelperStore implements IModuleIssues {
});
}

if (data.cycle_id && data.cycle_id !== "") {
await this.rootStore.cycleIssues.addCycleToIssue(workspaceSlug, projectId, data.cycle_id, response.id)
const currentCycleId = data.cycle_id !== "" && data.cycle_id === "None" ? undefined : data.cycle_id;
if (currentCycleId) {
await this.rootStore.cycleIssues.addCycleToIssue(workspaceSlug, projectId, currentCycleId, response.id);
}

this.rootIssueStore.rootStore.module.fetchModuleDetails(workspaceSlug, projectId, moduleId);
Expand Down
47 changes: 27 additions & 20 deletions web/store/issue/project-views/issue.store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pull from "lodash/pull";
import set from "lodash/set";
import { action, observable, makeObservable, computed, runInAction } from "mobx";
import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types";
// base class
import { IssueService } from "@/services/issue/issue.service";
import { TIssue, TLoader, TGroupedIssues, TSubGroupedIssues, TUnGroupedIssues, ViewFlags } from "@plane/types";
import { IssueHelperStore } from "../helpers/issue-helper.store";
// services
// types
Expand Down Expand Up @@ -97,20 +97,20 @@ export class ProjectViewIssues extends IssueHelperStore implements IProjectViewI
const viewIssueIds = this.issues[viewId];
if (!viewIssueIds) return;

const _issues = this.rootStore.issues.getIssuesByIds(viewIssueIds, "un-archived");
if (!_issues) return [];
const currentIssues = this.rootStore.issues.getIssuesByIds(viewIssueIds, "un-archived");
if (!currentIssues) return [];

let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues = [];

if (layout === "list" && orderBy) {
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, _issues);
else issues = this.unGroupedIssues(orderBy, _issues);
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, currentIssues);
else issues = this.unGroupedIssues(orderBy, currentIssues);
} else if (layout === "kanban" && groupBy && orderBy) {
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, _issues);
else issues = this.groupedIssues(groupBy, orderBy, _issues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", _issues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", _issues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", _issues);
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, currentIssues);
else issues = this.groupedIssues(groupBy, orderBy, currentIssues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", currentIssues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", currentIssues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", currentIssues);

return issues;
}
Expand Down Expand Up @@ -247,18 +247,25 @@ export class ProjectViewIssues extends IssueHelperStore implements IProjectViewI
});
}

if (data.cycle_id && data.cycle_id !== "") {
await this.rootStore.cycleIssues.addCycleToIssue(workspaceSlug, projectId, data.cycle_id, response.id)
const currentCycleId = data.cycle_id !== "" && data.cycle_id === "None" ? undefined : data.cycle_id;
const currentModuleIds =
data.module_ids && data.module_ids.length > 0 ? data.module_ids.filter((moduleId) => moduleId != "None") : [];

const multipleIssuePromises = [];
if (currentCycleId) {
multipleIssuePromises.push(
this.rootStore.cycleIssues.addCycleToIssue(workspaceSlug, projectId, currentCycleId, response.id)
);
}

if (currentModuleIds.length > 0) {
multipleIssuePromises.push(
this.rootStore.moduleIssues.changeModulesInIssue(workspaceSlug, projectId, response.id, currentModuleIds, [])
);
}

if (data.module_ids && data.module_ids.length > 0) {
await this.rootStore.moduleIssues.changeModulesInIssue(
workspaceSlug,
projectId,
response.id,
data.module_ids,
[]
)
if (multipleIssuePromises && multipleIssuePromises.length > 0) {
await Promise.all(multipleIssuePromises);
}

return response;
Expand Down
49 changes: 28 additions & 21 deletions web/store/issue/project/issue.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,20 @@ export class ProjectIssues extends IssueHelperStore implements IProjectIssues {
const projectIssueIds = this.issues[projectId];
if (!projectIssueIds) return;

const _issues = this.rootStore.issues.getIssuesByIds(projectIssueIds, "un-archived");
if (!_issues) return [];
const currentIssues = this.rootStore.issues.getIssuesByIds(projectIssueIds, "un-archived");
if (!currentIssues) return [];

let issues: TGroupedIssues | TSubGroupedIssues | TUnGroupedIssues = [];

if (layout === "list" && orderBy) {
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, _issues);
else issues = this.unGroupedIssues(orderBy, _issues);
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, currentIssues);
else issues = this.unGroupedIssues(orderBy, currentIssues);
} else if (layout === "kanban" && groupBy && orderBy) {
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, _issues);
else issues = this.groupedIssues(groupBy, orderBy, _issues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", _issues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", _issues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", _issues);
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, currentIssues);
else issues = this.groupedIssues(groupBy, orderBy, currentIssues);
} else if (layout === "calendar") issues = this.groupedIssues("target_date", "target_date", currentIssues, true);
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", currentIssues);
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", currentIssues);

return issues;
}
Expand Down Expand Up @@ -244,28 +244,35 @@ export class ProjectIssues extends IssueHelperStore implements IProjectIssues {
const response = await this.createIssue(workspaceSlug, projectId, data);

const quickAddIssueIndex = this.issues[projectId].findIndex((_issueId) => _issueId === data.id);

if (quickAddIssueIndex >= 0) {
runInAction(() => {
this.issues[projectId].splice(quickAddIssueIndex, 1);
this.rootStore.issues.removeIssue(data.id);
});
}

//TODO: error handling needs to be improved for rare cases
if (data.cycle_id && data.cycle_id !== "") {
await this.rootStore.cycleIssues.addCycleToIssue(workspaceSlug, projectId, data.cycle_id, response.id)
const currentCycleId = data.cycle_id !== "" && data.cycle_id === "None" ? undefined : data.cycle_id;
const currentModuleIds =
data.module_ids && data.module_ids.length > 0 ? data.module_ids.filter((moduleId) => moduleId != "None") : [];

const multipleIssuePromises = [];
if (currentCycleId) {
multipleIssuePromises.push(
this.rootStore.cycleIssues.addCycleToIssue(workspaceSlug, projectId, currentCycleId, response.id)
);
}

if (data.module_ids && data.module_ids.length > 0) {
await this.rootStore.moduleIssues.changeModulesInIssue(
workspaceSlug,
projectId,
response.id,
data.module_ids,
[]
)
if (currentModuleIds.length > 0) {
multipleIssuePromises.push(
this.rootStore.moduleIssues.changeModulesInIssue(workspaceSlug, projectId, response.id, currentModuleIds, [])
);
}

if (multipleIssuePromises && multipleIssuePromises.length > 0) {
await Promise.all(multipleIssuePromises);
}

return response;
} catch (error) {
this.fetchIssues(workspaceSlug, projectId, "mutation");
Expand Down
Loading