forked from github/plane
2bf7e63625
* dev: draft and archived issue store * connect draft and archived issues * kanban for draft issues * fix filter store for calendar and kanban * dev: profile issues store and draft issues filters in header * disble issue creation for draft issues * dev: profile issues store filters * disable kanban properties in draft issues * dev: profile issues store filters * dev: seperated adding issues to the cycle and module as seperate methds in cycle and module store * dev: workspace profile issues store * dev: sub group issues in the swimlanes * profile issues and create issue connection * fix profile issues * fix spreadsheet issues * fix dissapearing project from create issue modal * page level modifications * fix additional bugs * dev: issues profile and global iisues and filters update * fix issue related bugs * fix project views for list and kanban * fix build errors --------- Co-authored-by: rahulramesha <rahulramesham@gmail.com>
189 lines
6.1 KiB
TypeScript
189 lines
6.1 KiB
TypeScript
import { action, observable, makeObservable, computed, runInAction, autorun } from "mobx";
|
|
// base class
|
|
import { IssueBaseStore } from "store/issues";
|
|
// services
|
|
import { IssueDraftService } from "services/issue/issue_draft.service";
|
|
// types
|
|
import { IIssue } from "types/issues";
|
|
import { IIssueResponse, TLoader, IGroupedIssues, ISubGroupedIssues, TUnGroupedIssues, ViewFlags } from "../../types";
|
|
import { RootStore } from "store/root";
|
|
|
|
export interface IProjectDraftIssuesStore {
|
|
// observable
|
|
loader: TLoader;
|
|
issues: { [project_id: string]: IIssueResponse } | undefined;
|
|
// computed
|
|
getIssues: IIssueResponse | undefined;
|
|
getIssuesIds: IGroupedIssues | ISubGroupedIssues | TUnGroupedIssues | undefined;
|
|
// actions
|
|
fetchIssues: (workspaceSlug: string, projectId: string, loadType: TLoader) => Promise<IIssueResponse>;
|
|
createIssue: (workspaceSlug: string, projectId: string, data: Partial<IIssue>) => Promise<IIssue>;
|
|
updateIssue: (workspaceSlug: string, projectId: string, issueId: string, data: Partial<IIssue>) => Promise<IIssue>;
|
|
removeIssue: (workspaceSlug: string, projectId: string, issueId: string) => Promise<IIssue>;
|
|
|
|
quickAddIssue: undefined;
|
|
viewFlags: ViewFlags;
|
|
}
|
|
|
|
export class ProjectDraftIssuesStore extends IssueBaseStore implements IProjectDraftIssuesStore {
|
|
loader: TLoader = "init-loader";
|
|
issues: { [project_id: string]: IIssueResponse } | undefined = undefined;
|
|
// root store
|
|
rootStore;
|
|
// service
|
|
issueDraftService;
|
|
|
|
//viewData
|
|
viewFlags = {
|
|
enableQuickAdd: false,
|
|
enableIssueCreation: false,
|
|
enableInlineEditing: false,
|
|
};
|
|
|
|
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,
|
|
});
|
|
|
|
this.rootStore = _rootStore;
|
|
this.issueDraftService = new IssueDraftService();
|
|
|
|
autorun(() => {
|
|
const workspaceSlug = this.rootStore.workspace.workspaceSlug;
|
|
const projectId = this.rootStore.project.projectId;
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
const userFilters = this.rootStore?.projectDraftIssuesFilter?.issueFilters?.filters;
|
|
if (userFilters) this.fetchIssues(workspaceSlug, projectId, "mutation");
|
|
});
|
|
}
|
|
|
|
get getIssues() {
|
|
const projectId = this.rootStore?.project.projectId;
|
|
if (!projectId || !this.issues || !this.issues[projectId]) return undefined;
|
|
|
|
return this.issues[projectId];
|
|
}
|
|
|
|
get getIssuesIds() {
|
|
const projectId = this.rootStore?.project.projectId;
|
|
const displayFilters = this.rootStore?.projectDraftIssuesFilter?.issueFilters?.displayFilters;
|
|
if (!displayFilters) return undefined;
|
|
|
|
const subGroupBy = displayFilters?.sub_group_by;
|
|
const groupBy = displayFilters?.group_by;
|
|
const orderBy = displayFilters?.order_by;
|
|
const layout = displayFilters?.layout;
|
|
|
|
if (!projectId || !this.issues || !this.issues[projectId]) return undefined;
|
|
|
|
let issues: IIssueResponse | IGroupedIssues | ISubGroupedIssues | TUnGroupedIssues | undefined = undefined;
|
|
|
|
if (layout === "list" && orderBy) {
|
|
if (groupBy) issues = this.groupedIssues(groupBy, orderBy, this.issues[projectId]);
|
|
else issues = this.unGroupedIssues(orderBy, this.issues[projectId]);
|
|
} else if (layout === "kanban" && groupBy && orderBy) {
|
|
if (subGroupBy) issues = this.subGroupedIssues(subGroupBy, groupBy, orderBy, this.issues[projectId]);
|
|
else issues = this.groupedIssues(groupBy, orderBy, this.issues[projectId]);
|
|
}
|
|
|
|
return issues;
|
|
}
|
|
|
|
fetchIssues = async (workspaceSlug: string, projectId: string, loadType: TLoader = "init-loader") => {
|
|
try {
|
|
this.loader = loadType;
|
|
|
|
const params = this.rootStore?.projectDraftIssuesFilter?.appliedFilters;
|
|
const response = await this.issueDraftService.getV3DraftIssues(workspaceSlug, projectId, params);
|
|
|
|
const _issues = { ...this.issues, [projectId]: { ...response } };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
this.loader = undefined;
|
|
});
|
|
|
|
return response;
|
|
} catch (error) {
|
|
console.error(error);
|
|
this.loader = undefined;
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
createIssue = async (workspaceSlug: string, projectId: string, data: Partial<IIssue>) => {
|
|
try {
|
|
const response = await this.issueDraftService.createDraftIssue(workspaceSlug, projectId, data);
|
|
|
|
let _issues = this.issues;
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[projectId]) _issues[projectId] = {};
|
|
_issues[projectId] = { ..._issues[projectId], ...{ [response.id]: response } };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation");
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
updateIssue = async (workspaceSlug: string, projectId: string, issueId: string, data: Partial<IIssue>) => {
|
|
try {
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[projectId]) _issues[projectId] = {};
|
|
_issues[projectId][issueId] = { ..._issues[projectId][issueId], ...data };
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
const response = await this.issueDraftService.updateDraftIssue(workspaceSlug, projectId, issueId, data);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation");
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
removeIssue = async (workspaceSlug: string, projectId: string, issueId: string) => {
|
|
try {
|
|
let _issues = { ...this.issues };
|
|
if (!_issues) _issues = {};
|
|
if (!_issues[projectId]) _issues[projectId] = {};
|
|
delete _issues?.[projectId]?.[issueId];
|
|
|
|
runInAction(() => {
|
|
this.issues = _issues;
|
|
});
|
|
|
|
const response = await this.issueDraftService.deleteDraftIssue(workspaceSlug, projectId, issueId);
|
|
|
|
return response;
|
|
} catch (error) {
|
|
this.fetchIssues(workspaceSlug, projectId, "mutation");
|
|
throw error;
|
|
}
|
|
};
|
|
|
|
quickAddIssue: undefined;
|
|
}
|