fix: gantt chart blocks drag and resize logic (#2516)
This commit is contained in:
parent
c739b7235d
commit
05a76c5ee3
8 changed files with 234 additions and 63 deletions
|
|
@ -6,6 +6,7 @@ import { IIssue } from "types";
|
|||
// services
|
||||
import { IssueService } from "services/issue";
|
||||
import { sortArrayByDate, sortArrayByPriority } from "constants/kanban-helpers";
|
||||
import { IBlockUpdateData } from "components/gantt-chart";
|
||||
|
||||
export type IIssueType = "grouped" | "groupWithSubGroups" | "ungrouped";
|
||||
export type IIssueGroupedStructure = { [group_id: string]: IIssue[] };
|
||||
|
|
@ -34,6 +35,7 @@ export interface IIssueStore {
|
|||
fetchIssues: (workspaceSlug: string, projectId: string) => Promise<any>;
|
||||
updateIssueStructure: (group_id: string | null, sub_group_id: string | null, issue: IIssue) => void;
|
||||
deleteIssue: (group_id: string | null, sub_group_id: string | null, issue: IIssue) => void;
|
||||
updateGanttIssueStructure: (workspaceSlug: string, issue: IIssue, payload: IBlockUpdateData) => void;
|
||||
}
|
||||
|
||||
export class IssueStore implements IIssueStore {
|
||||
|
|
@ -69,6 +71,7 @@ export class IssueStore implements IIssueStore {
|
|||
fetchIssues: action,
|
||||
updateIssueStructure: action,
|
||||
deleteIssue: action,
|
||||
updateGanttIssueStructure: action,
|
||||
});
|
||||
|
||||
this.rootStore = _rootStore;
|
||||
|
|
@ -165,6 +168,45 @@ export class IssueStore implements IIssueStore {
|
|||
});
|
||||
};
|
||||
|
||||
updateGanttIssueStructure = async (workspaceSlug: string, issue: IIssue, payload: IBlockUpdateData) => {
|
||||
if (!issue || !workspaceSlug) return;
|
||||
|
||||
const issues = this.getIssues as IIssueUnGroupedStructure;
|
||||
|
||||
const newIssues = issues.map((i) => ({
|
||||
...i,
|
||||
...(i.id === issue.id
|
||||
? {
|
||||
sort_order: payload.sort_order?.newSortOrder ?? i.sort_order,
|
||||
start_date: payload.start_date,
|
||||
target_date: payload.target_date,
|
||||
}
|
||||
: {}),
|
||||
}));
|
||||
|
||||
if (payload.sort_order) {
|
||||
const removedElement = newIssues.splice(payload.sort_order.sourceIndex, 1)[0];
|
||||
removedElement.sort_order = payload.sort_order.newSortOrder;
|
||||
newIssues.splice(payload.sort_order.destinationIndex, 0, removedElement);
|
||||
}
|
||||
|
||||
runInAction(() => {
|
||||
this.issues = {
|
||||
...this.issues,
|
||||
[issue.project]: {
|
||||
...this.issues[issue.project],
|
||||
ungrouped: newIssues,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const newPayload: any = { ...payload };
|
||||
|
||||
if (newPayload.sort_order && payload.sort_order) newPayload.sort_order = payload.sort_order.newSortOrder;
|
||||
|
||||
this.rootStore.issueDetail.updateIssue(workspaceSlug, issue.project, issue.id, newPayload);
|
||||
};
|
||||
|
||||
deleteIssue = async (group_id: string | null, sub_group_id: string | null, issue: IIssue) => {
|
||||
const projectId: string | null = issue?.project;
|
||||
const issueType = this.getIssueType;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue