2024-05-14 08:56:54 +00:00
|
|
|
import { observable, action, makeObservable, runInAction } from "mobx";
|
2024-06-10 06:46:23 +00:00
|
|
|
import { computedFn } from "mobx-utils";
|
|
|
|
// types
|
|
|
|
import { IStateLite } from "@plane/types";
|
2023-09-01 11:12:30 +00:00
|
|
|
// services
|
2024-03-19 14:38:35 +00:00
|
|
|
import IssueService from "@/services/issue.service";
|
2024-05-14 08:56:54 +00:00
|
|
|
// types
|
2024-06-10 06:46:23 +00:00
|
|
|
import { IIssue, IIssueLabel } from "@/types/issue";
|
2023-09-01 11:12:30 +00:00
|
|
|
// store
|
2024-05-08 17:31:20 +00:00
|
|
|
import { RootStore } from "./root.store";
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
export interface IIssueStore {
|
|
|
|
loader: boolean;
|
|
|
|
error: any;
|
2024-06-10 06:46:23 +00:00
|
|
|
// observables
|
|
|
|
issues: IIssue[];
|
|
|
|
states: IStateLite[];
|
|
|
|
labels: IIssueLabel[];
|
|
|
|
// filter observables
|
2023-09-01 11:12:30 +00:00
|
|
|
filteredStates: string[];
|
|
|
|
filteredLabels: string[];
|
|
|
|
filteredPriorities: string[];
|
|
|
|
// actions
|
2024-06-10 06:46:23 +00:00
|
|
|
fetchPublicIssues: (anchor: string, params: any) => Promise<void>;
|
|
|
|
// helpers
|
|
|
|
getCountOfIssuesByState: (stateID: string) => number;
|
|
|
|
getFilteredIssuesByState: (stateID: string) => IIssue[];
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-05-14 08:56:54 +00:00
|
|
|
export class IssueStore implements IIssueStore {
|
2023-08-11 11:48:33 +00:00
|
|
|
loader: boolean = false;
|
|
|
|
error: any | null = null;
|
2024-06-10 06:46:23 +00:00
|
|
|
// observables
|
|
|
|
states: IStateLite[] = [];
|
|
|
|
labels: IIssueLabel[] = [];
|
|
|
|
issues: IIssue[] = [];
|
|
|
|
// filter observables
|
2023-09-01 11:12:30 +00:00
|
|
|
filteredStates: string[] = [];
|
|
|
|
filteredLabels: string[] = [];
|
|
|
|
filteredPriorities: string[] = [];
|
2024-06-10 06:46:23 +00:00
|
|
|
// root store
|
2023-09-01 11:12:30 +00:00
|
|
|
rootStore: RootStore;
|
2024-06-10 06:46:23 +00:00
|
|
|
// services
|
|
|
|
issueService: IssueService;
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
constructor(_rootStore: RootStore) {
|
2023-08-11 11:48:33 +00:00
|
|
|
makeObservable(this, {
|
2024-06-10 06:46:23 +00:00
|
|
|
loader: observable.ref,
|
2023-08-11 11:48:33 +00:00
|
|
|
error: observable,
|
2024-06-10 06:46:23 +00:00
|
|
|
// observables
|
|
|
|
states: observable,
|
|
|
|
labels: observable,
|
|
|
|
issues: observable,
|
|
|
|
// filter observables
|
|
|
|
filteredStates: observable,
|
|
|
|
filteredLabels: observable,
|
|
|
|
filteredPriorities: observable,
|
2023-09-01 11:12:30 +00:00
|
|
|
// actions
|
|
|
|
fetchPublicIssues: action,
|
2023-08-11 11:48:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.rootStore = _rootStore;
|
|
|
|
this.issueService = new IssueService();
|
|
|
|
}
|
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
/**
|
|
|
|
* @description fetch issues, states and labels
|
|
|
|
* @param {string} anchor
|
|
|
|
* @param params
|
|
|
|
*/
|
|
|
|
fetchPublicIssues = async (anchor: string, params: any) => {
|
2023-08-11 11:48:33 +00:00
|
|
|
try {
|
2024-06-10 06:46:23 +00:00
|
|
|
runInAction(() => {
|
|
|
|
this.loader = true;
|
|
|
|
this.error = null;
|
|
|
|
});
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
const response = await this.issueService.fetchPublicIssues(anchor, params);
|
2023-08-11 11:48:33 +00:00
|
|
|
|
|
|
|
if (response) {
|
|
|
|
runInAction(() => {
|
2024-06-10 06:46:23 +00:00
|
|
|
this.states = response.states;
|
|
|
|
this.labels = response.labels;
|
|
|
|
this.issues = response.issues;
|
2023-08-11 11:48:33 +00:00
|
|
|
this.loader = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.loader = false;
|
|
|
|
this.error = error;
|
|
|
|
}
|
|
|
|
};
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
/**
|
|
|
|
* @description get total count of issues under a particular state
|
|
|
|
* @param {string} stateID
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
getCountOfIssuesByState = computedFn(
|
|
|
|
(stateID: string) => this.issues?.filter((issue) => issue.state == stateID).length || 0
|
|
|
|
);
|
2023-09-01 11:12:30 +00:00
|
|
|
|
2024-06-10 06:46:23 +00:00
|
|
|
/**
|
|
|
|
* @description get array of issues under a particular state
|
|
|
|
* @param {string} stateID
|
|
|
|
* @returns {IIssue[]}
|
|
|
|
*/
|
|
|
|
getFilteredIssuesByState = computedFn(
|
|
|
|
(stateID: string) => this.issues?.filter((issue) => issue.state == stateID) || []
|
|
|
|
);
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|