2023-09-20 15:03:25 +00:00
|
|
|
import { observable, action, computed, makeObservable, runInAction } from "mobx";
|
|
|
|
import { IIssue } from "types";
|
2023-09-20 18:09:55 +00:00
|
|
|
import { RootStore } from "./root";
|
2023-09-20 15:03:25 +00:00
|
|
|
|
|
|
|
export interface IIssueStore {
|
|
|
|
loader: boolean;
|
|
|
|
error: any | null;
|
2023-09-21 12:20:43 +00:00
|
|
|
|
|
|
|
issues: {
|
|
|
|
[project_id: string]: {
|
|
|
|
grouped: {
|
2023-09-22 06:59:22 +00:00
|
|
|
[group_id: string]: IIssue[];
|
|
|
|
};
|
|
|
|
groupWithSubGroups: {
|
|
|
|
[group_id: string]: {
|
|
|
|
[sub_group_id: string]: IIssue[];
|
|
|
|
};
|
2023-09-21 12:20:43 +00:00
|
|
|
};
|
|
|
|
ungrouped: IIssue[];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
addIssueToIssuesStore: (projectId: string, issue: IIssue) => void;
|
|
|
|
updateIssueInIssuesStore: (projectId: string, issue: IIssue) => void;
|
|
|
|
deleteIssueFromIssuesStore: (projectId: string, issueId: string) => void;
|
2023-09-20 15:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class IssueStore implements IIssueStore {
|
|
|
|
loader: boolean = false;
|
|
|
|
error: any | null = null;
|
|
|
|
issues: {
|
|
|
|
[project_id: string]: {
|
2023-09-21 12:20:43 +00:00
|
|
|
grouped: {
|
|
|
|
[issueId: string]: IIssue[];
|
|
|
|
};
|
2023-09-22 06:59:22 +00:00
|
|
|
groupWithSubGroups: {
|
|
|
|
[group_id: string]: {
|
|
|
|
[sub_group_id: string]: IIssue[];
|
|
|
|
};
|
|
|
|
};
|
2023-09-20 15:03:25 +00:00
|
|
|
ungrouped: IIssue[];
|
|
|
|
};
|
|
|
|
} = {};
|
|
|
|
|
2023-09-20 18:09:55 +00:00
|
|
|
rootStore;
|
|
|
|
|
|
|
|
constructor(_rootStore: RootStore) {
|
2023-09-20 15:03:25 +00:00
|
|
|
makeObservable(this, {
|
|
|
|
// observable
|
|
|
|
loader: observable.ref,
|
|
|
|
error: observable.ref,
|
|
|
|
issues: observable.ref,
|
2023-09-21 12:20:43 +00:00
|
|
|
|
|
|
|
addIssueToIssuesStore: action,
|
|
|
|
updateIssueInIssuesStore: action,
|
|
|
|
deleteIssueFromIssuesStore: action,
|
2023-09-20 15:03:25 +00:00
|
|
|
});
|
2023-09-20 18:09:55 +00:00
|
|
|
this.rootStore = _rootStore;
|
2023-09-20 15:03:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-21 12:20:43 +00:00
|
|
|
addIssueToIssuesStore = (projectId: string, issue: IIssue) => {
|
|
|
|
runInAction(() => {
|
|
|
|
this.rootStore.issue.issues = {
|
|
|
|
...this.rootStore.issue.issues,
|
|
|
|
[projectId]: {
|
|
|
|
...this.rootStore.issue.issues[projectId],
|
|
|
|
ungrouped: [...this.rootStore.issue.issues[projectId].ungrouped, issue],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
updateIssueInIssuesStore = (projectId: string, issue: IIssue) => {
|
|
|
|
const newUngroupedIssues = this.rootStore.issue.issues[projectId].ungrouped.map((i) => ({
|
|
|
|
...i,
|
|
|
|
...(i.id === issue.id ? issue : {}),
|
|
|
|
}));
|
|
|
|
|
|
|
|
runInAction(() => {
|
|
|
|
this.rootStore.issue.issues = {
|
|
|
|
...this.rootStore.issue.issues,
|
|
|
|
[projectId]: {
|
|
|
|
...this.rootStore.issue.issues[projectId],
|
|
|
|
ungrouped: newUngroupedIssues,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
deleteIssueFromIssuesStore = (projectId: string, issueId: string) => {
|
|
|
|
const newUngroupedIssues = this.rootStore.issue.issues[projectId].ungrouped.filter((i) => i.id !== issueId);
|
|
|
|
|
|
|
|
runInAction(() => {
|
|
|
|
this.rootStore.issue.issues = {
|
|
|
|
...this.rootStore.issue.issues,
|
|
|
|
[projectId]: {
|
|
|
|
...this.rootStore.issue.issues[projectId],
|
|
|
|
ungrouped: newUngroupedIssues,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2023-09-20 15:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default IssueStore;
|