mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
a17b08dd15
* fix: Implemented new workflow in the issue store and updated the quick add workflow in list layout * fix: initial load and mutaion of issues in list layout * dev: implemented the new project issues store with grouped, subGrouped and unGrouped issue computed functions * dev: default display properties data made as a function * conflict: merge conflict resolved * dev: implemented quick add logic in kanban * chore: implemented quick add logic in calendar and spreadsheet layout * fix: spreadsheet layout quick add fix * dev: optimised the issues workflow and handled the issues order_by filter * dev: project issue CRUD operations in new issue store architecture * dev: issues filtering in calendar layout * fix: build error * dev/issue_filters_store * chore: updated filters computed structure * conflict: merge conflicts resolved in project issues * dev: implemented gantt chart for project issues using the new mobx store * dev: initialized cycle and module issue filters store * dev: issue store and list layout store updates * dev: quick add and update, delete issue in the list * refactor list root changes * dev: store new structure * refactor spreadsheet and gnatt project roots * fix errors for base gantt and spreadsheet roots * connect Calendar project view * minor house keeping * connect Kanban View to th enew store * generalise base calendar issue actions * dev: store project issues and issue filters * dev: store project issues and filters * dev: updated undefined with displayFilters in project issue store * Add Quick add to all the layouts * connect module views to store * dev: Rendering list issues in project issues * dev: removed console log * dev: module filters store * fix errors and connect modules list and quick add for list * dev: module issue store * dev: modle filter store issue fixed and updates cycle issue filters * minor house keeping changes * dev: cycle issues and cycle filters * connecty cycles to teh store * dev: project view issues and issue filtrs * connect project views * dev: updated applied filters in layouts * dev: replaced project id with view id in project views * dev: in cycle and module store made cycledId and moduleId as optional * fix minor issues and build errots * dev: project draft and archived issues store and filters --------- Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so> Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com> Co-authored-by: rahulramesha <rahulramesham@gmail.com>
316 lines
9.3 KiB
TypeScript
316 lines
9.3 KiB
TypeScript
import { action, observable, makeObservable, computed, runInAction, autorun } from "mobx";
|
|
// base class
|
|
import { IssueBaseStore } from "store/issues";
|
|
// services
|
|
import { IssueService } from "services/issue";
|
|
import { CycleService } from "services/cycle.service";
|
|
// types
|
|
import { TIssueGroupByOptions } from "types";
|
|
import { IIssue } from "types/issues";
|
|
import { IIssueResponse, TLoader, IGroupedIssues, ISubGroupedIssues, TUnGroupedIssues } from "../../types";
|
|
import { RootStore } from "store/root";
|
|
|
|
export interface ICycleIssuesStore {
|
|
// observable
|
|
loader: TLoader;
|
|
issues: { [cycle_id: string]: IIssueResponse } | undefined;
|
|
// computed
|
|
getIssues: IIssueResponse | undefined;
|
|
getIssuesIds: IGroupedIssues | ISubGroupedIssues | TUnGroupedIssues | undefined;
|
|
// actions
|
|
fetchIssues: (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
loadType: TLoader,
|
|
cycleId?: string | undefined
|
|
) => Promise<IIssueResponse | undefined>;
|
|
createIssue: (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
data: Partial<IIssue>,
|
|
cycleId?: string | undefined
|
|
) => Promise<IIssue | undefined>;
|
|
updateIssue: (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
issueId: string,
|
|
data: Partial<IIssue>,
|
|
cycleId?: string | undefined
|
|
) => Promise<IIssue | undefined>;
|
|
removeIssue: (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
issueId: string,
|
|
cycleId?: string | undefined
|
|
) => Promise<IIssue | undefined>;
|
|
quickAddIssue: (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
data: IIssue,
|
|
cycleId?: string | undefined
|
|
) => Promise<IIssue | undefined>;
|
|
removeIssueFromCycle: (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
cycleId: string,
|
|
issueId: string,
|
|
issueBridgeId: string
|
|
) => Promise<IIssue>;
|
|
}
|
|
|
|
export class CycleIssuesStore extends IssueBaseStore implements ICycleIssuesStore {
|
|
loader: TLoader = "init-loader";
|
|
issues: { [cycle_id: string]: IIssueResponse } | undefined = undefined;
|
|
// root store
|
|
rootStore;
|
|
// service
|
|
cycleService;
|
|
issueService;
|
|
|
|
constructor(_rootStore: RootStore) {
|
|
super(_rootStore);
|
|
|
|
makeObservable(this, {
|
|
// observable
|
|
loader: observable.ref,
|
|
issues: observable.ref,
|
|
// computed
|
|
getIssues: computed,
|
|
getIssuesIds: computed,
|
|
// action
|
|
fetchIssues: action,
|
|
createIssue: action,
|
|
updateIssue: action,
|
|
removeIssue: action,
|
|
quickAddIssue: action,
|
|
removeIssueFromCycle: action,
|
|
});
|
|
|
|
this.rootStore = _rootStore;
|
|
this.issueService = new IssueService();
|
|
this.cycleService = new CycleService();
|
|
|
|
autorun(() => {
|
|
const workspaceSlug = this.rootStore.workspace.workspaceSlug;
|
|
const projectId = this.rootStore.project.projectId;
|
|
const cycleId = this.rootStore.cycle.cycleId;
|
|
if (!workspaceSlug || !projectId || !cycleId) return;
|
|
|
|
const userFilters = this.rootStore?.cycleIssuesFilter?.issueFilters?.filters;
|
|
if (userFilters) this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
});
|
|
}
|
|
|
|
get getIssues() {
|
|
const cycleId = this.rootStore?.cycle?.cycleId;
|
|
if (!cycleId || !this.issues || !this.issues[cycleId]) return undefined;
|
|
|
|
return this.issues[cycleId];
|
|
}
|
|
|
|
get getIssuesIds() {
|
|
const cycleId = this.rootStore?.cycle?.cycleId;
|
|
const displayFilters = this.rootStore?.cycleIssuesFilter?.issueFilters?.displayFilters;
|
|
|
|
const subGroupBy = displayFilters?.sub_group_by;
|
|
const groupBy = displayFilters?.group_by;
|
|
const orderBy = displayFilters?.order_by;
|
|
const layout = displayFilters?.layout;
|
|
|
|
if (!cycleId || !this.issues || !this.issues[cycleId]) return undefined;
|
|
|
|
let issues: IIssueResponse | IGroupedIssues | ISubGroupedIssues | TUnGroupedIssues | undefined = undefined;
|
|
|
|
if (layout === "list" && orderBy) {
|
|
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, this.issues[cycleId]);
|
|
else issues = this.unGroupedIssues(orderBy, this.issues[cycleId]);
|
|
} else if (layout === "kanban" && groupBy && orderBy) {
|
|
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, this.issues[cycleId]);
|
|
else issues = this.groupedIssues(groupBy, orderBy, this.issues[cycleId]);
|
|
} else if (layout === "calendar")
|
|
issues = this.groupedIssues("target_date" as TIssueGroupByOptions, "target_date", this.issues[cycleId], true);
|
|
else if (layout === "spreadsheet") issues = this.unGroupedIssues(orderBy ?? "-created_at", this.issues[cycleId]);
|
|
else if (layout === "gantt_chart") issues = this.unGroupedIssues(orderBy ?? "sort_order", this.issues[cycleId]);
|
|
|
|
return issues;
|
|
}
|
|
|
|
fetchIssues = async (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
loadType: TLoader = "init-loader",
|
|
cycleId: string | undefined = undefined
|
|
) => {
|
|
if (!cycleId) return undefined;
|
|
|
|
try {
|
|
this.loader = loadType;
|
|
|
|
const params = this.rootStore?.cycleIssuesFilter?.appliedFilters;
|
|
const response = await this.cycleService.getV3CycleIssues(workspaceSlug, projectId, cycleId, params);
|
|
|
|
const _issues = { ...this.issues, [cycleId]: { ...response } };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
this.loader = undefined;
|
|
});
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
this.loader = undefined;
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
createIssue = async (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
data: Partial<IIssue>,
|
|
cycleId: string | undefined = undefined
|
|
) => {
|
|
if (!cycleId) return undefined;
|
|
|
|
try {
|
|
const response = await this.rootStore.projectIssues.createIssue(workspaceSlug, projectId, data);
|
|
const issueToCycle = await this.issueService.addIssueToCycle(workspaceSlug, projectId, cycleId, {
|
|
issues: [response.id],
|
|
});
|
|
|
|
let _issues = this.issues;
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[cycleId]) _issues[cycleId] = {};
|
|
_issues[cycleId] = { ..._issues[cycleId], ...{ [response.id]: response } };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
return issueToCycle;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
updateIssue = async (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
issueId: string,
|
|
data: Partial<IIssue>,
|
|
cycleId: string | undefined = undefined
|
|
) => {
|
|
if (!cycleId) return undefined;
|
|
|
|
try {
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[cycleId]) _issues[cycleId] = {};
|
|
_issues[cycleId][issueId] = { ..._issues[cycleId][issueId], ...data };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
const response = await this.rootStore.projectIssues.updateIssue(workspaceSlug, projectId, issueId, data);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
removeIssue = async (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
issueId: string,
|
|
cycleId: string | undefined = undefined
|
|
) => {
|
|
if (!cycleId) return undefined;
|
|
try {
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[cycleId]) _issues[cycleId] = {};
|
|
delete _issues?.[cycleId]?.[issueId];
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
const response = await this.rootStore.projectIssues.removeIssue(workspaceSlug, projectId, issueId);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
quickAddIssue = async (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
data: IIssue,
|
|
cycleId: string | undefined = undefined
|
|
) => {
|
|
if (!cycleId) return;
|
|
try {
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[cycleId]) _issues[cycleId] = {};
|
|
_issues[cycleId] = { ..._issues[cycleId], ...{ [data.id as keyof IIssue]: data } };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
const response = await this.createIssue(workspaceSlug, projectId, data, cycleId);
|
|
|
|
if (this.issues) {
|
|
delete this.issues[cycleId][data.id as keyof IIssue];
|
|
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[cycleId]) _issues[cycleId] = {};
|
|
_issues[cycleId] = { ..._issues[cycleId], ...{ [response.id as keyof IIssue]: response } };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
}
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
removeIssueFromCycle = async (
|
|
workspaceSlug: string,
|
|
projectId: string,
|
|
cycleId: string,
|
|
issueId: string,
|
|
issueBridgeId: string
|
|
) => {
|
|
try {
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[cycleId]) _issues[cycleId] = {};
|
|
delete _issues?.[cycleId]?.[issueId];
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
const response = await this.issueService.removeIssueFromCycle(workspaceSlug, projectId, cycleId, issueBridgeId);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation", cycleId);
|
|
throw error;
|
|
}
|
|
};
|
|
}
|