2023-09-01 11:12:30 +00:00
|
|
|
import { observable, action, computed, makeObservable, runInAction, reaction } from "mobx";
|
|
|
|
// services
|
2023-08-11 11:48:33 +00:00
|
|
|
import IssueService from "services/issue.service";
|
2023-09-01 11:12:30 +00:00
|
|
|
// store
|
|
|
|
import { RootStore } from "./root";
|
2023-08-11 11:48:33 +00:00
|
|
|
// types
|
2023-09-01 11:12:30 +00:00
|
|
|
// import { IssueDetailType, TIssueBoardKeys } from "types/issue";
|
|
|
|
import { IIssue, IIssueState, IIssueLabel } from "types/issue";
|
|
|
|
|
|
|
|
export interface IIssueStore {
|
|
|
|
loader: boolean;
|
|
|
|
error: any;
|
|
|
|
// issue options
|
|
|
|
issues: IIssue[] | null;
|
|
|
|
states: IIssueState[] | null;
|
|
|
|
labels: IIssueLabel[] | null;
|
|
|
|
// filtering
|
|
|
|
filteredStates: string[];
|
|
|
|
filteredLabels: string[];
|
|
|
|
filteredPriorities: string[];
|
|
|
|
// service
|
|
|
|
issueService: any;
|
|
|
|
// actions
|
|
|
|
fetchPublicIssues: (workspace_slug: string, project_slug: string, params: any) => void;
|
|
|
|
getCountOfIssuesByState: (state: string) => number;
|
|
|
|
getFilteredIssuesByState: (state: string) => IIssue[];
|
|
|
|
}
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
class IssueStore implements IIssueStore {
|
|
|
|
loader: boolean = false;
|
|
|
|
error: any | null = null;
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
states: IIssueState[] | null = [];
|
|
|
|
labels: IIssueLabel[] | null = [];
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
filteredStates: string[] = [];
|
|
|
|
filteredLabels: string[] = [];
|
|
|
|
filteredPriorities: string[] = [];
|
|
|
|
|
|
|
|
issues: IIssue[] | null = [];
|
|
|
|
issue_detail: any = {};
|
|
|
|
|
|
|
|
rootStore: RootStore;
|
|
|
|
issueService: any;
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
constructor(_rootStore: any) {
|
|
|
|
makeObservable(this, {
|
|
|
|
// observable
|
|
|
|
loader: observable,
|
|
|
|
error: observable,
|
2023-09-01 11:12:30 +00:00
|
|
|
// issue options
|
2023-08-11 11:48:33 +00:00
|
|
|
states: observable.ref,
|
|
|
|
labels: observable.ref,
|
2023-09-01 11:12:30 +00:00
|
|
|
// filtering
|
|
|
|
filteredStates: observable.ref,
|
|
|
|
filteredLabels: observable.ref,
|
|
|
|
filteredPriorities: observable.ref,
|
|
|
|
// issues
|
2023-08-11 11:48:33 +00:00
|
|
|
issues: observable.ref,
|
2023-09-01 11:12:30 +00:00
|
|
|
issue_detail: observable.ref,
|
|
|
|
// actions
|
|
|
|
fetchPublicIssues: action,
|
|
|
|
getFilteredIssuesByState: action,
|
2023-08-11 11:48:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.rootStore = _rootStore;
|
|
|
|
this.issueService = new IssueService();
|
|
|
|
}
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
fetchPublicIssues = async (workspaceSlug: string, projectId: string, params: any) => {
|
2023-08-11 11:48:33 +00:00
|
|
|
try {
|
|
|
|
this.loader = true;
|
|
|
|
this.error = null;
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
const response = await this.issueService.getPublicIssues(workspaceSlug, projectId, params);
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
if (response) {
|
|
|
|
const _states: IIssueState[] = [...response?.states];
|
|
|
|
const _labels: IIssueLabel[] = [...response?.labels];
|
|
|
|
const _issues: IIssue[] = [...response?.issues];
|
|
|
|
runInAction(() => {
|
|
|
|
this.states = _states;
|
|
|
|
this.labels = _labels;
|
|
|
|
this.issues = _issues;
|
|
|
|
this.loader = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.loader = false;
|
|
|
|
this.error = error;
|
|
|
|
}
|
|
|
|
};
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
// computed
|
|
|
|
getCountOfIssuesByState(state_id: string): number {
|
|
|
|
return this.issues?.filter((issue) => issue.state == state_id).length || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
getFilteredIssuesByState = (state_id: string): IIssue[] | [] =>
|
|
|
|
this.issues?.filter((issue) => issue.state == state_id) || [];
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default IssueStore;
|