mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
17f83d6458
* dev: change layout * chore: replace workspace slug and project id with anchor * chore: migration fixes * chore: update filtering logic * chore: endpoint changes * chore: update endpoint * chore: changed url pratterns * chore: use client side for layout and page * chore: issue vote changes * chore: project deploy board response change * refactor: publish project store and components * fix: update layout options after fetching settings * chore: remove unnecessary types * style: peek overview * refactor: components folder structure * fix: redirect from old path * chore: make the whole issue block clickable * chore: removed the migration file * chore: add server side redirection for old routes * chore: is enabled key change * chore: update types * chore: removed the migration file --------- Co-authored-by: NarayanBavisetti <narayan3119@gmail.com>
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import { observable, action, makeObservable, runInAction } from "mobx";
|
|
import { computedFn } from "mobx-utils";
|
|
// types
|
|
import { IStateLite } from "@plane/types";
|
|
// services
|
|
import IssueService from "@/services/issue.service";
|
|
// types
|
|
import { IIssue, IIssueLabel } from "@/types/issue";
|
|
// store
|
|
import { RootStore } from "./root.store";
|
|
|
|
export interface IIssueStore {
|
|
loader: boolean;
|
|
error: any;
|
|
// observables
|
|
issues: IIssue[];
|
|
states: IStateLite[];
|
|
labels: IIssueLabel[];
|
|
// filter observables
|
|
filteredStates: string[];
|
|
filteredLabels: string[];
|
|
filteredPriorities: string[];
|
|
// actions
|
|
fetchPublicIssues: (anchor: string, params: any) => Promise<void>;
|
|
// helpers
|
|
getCountOfIssuesByState: (stateID: string) => number;
|
|
getFilteredIssuesByState: (stateID: string) => IIssue[];
|
|
}
|
|
|
|
export class IssueStore implements IIssueStore {
|
|
loader: boolean = false;
|
|
error: any | null = null;
|
|
// observables
|
|
states: IStateLite[] = [];
|
|
labels: IIssueLabel[] = [];
|
|
issues: IIssue[] = [];
|
|
// filter observables
|
|
filteredStates: string[] = [];
|
|
filteredLabels: string[] = [];
|
|
filteredPriorities: string[] = [];
|
|
// root store
|
|
rootStore: RootStore;
|
|
// services
|
|
issueService: IssueService;
|
|
|
|
constructor(_rootStore: RootStore) {
|
|
makeObservable(this, {
|
|
loader: observable.ref,
|
|
error: observable,
|
|
// observables
|
|
states: observable,
|
|
labels: observable,
|
|
issues: observable,
|
|
// filter observables
|
|
filteredStates: observable,
|
|
filteredLabels: observable,
|
|
filteredPriorities: observable,
|
|
// actions
|
|
fetchPublicIssues: action,
|
|
});
|
|
|
|
this.rootStore = _rootStore;
|
|
this.issueService = new IssueService();
|
|
}
|
|
|
|
/**
|
|
* @description fetch issues, states and labels
|
|
* @param {string} anchor
|
|
* @param params
|
|
*/
|
|
fetchPublicIssues = async (anchor: string, params: any) => {
|
|
try {
|
|
runInAction(() => {
|
|
this.loader = true;
|
|
this.error = null;
|
|
});
|
|
|
|
const response = await this.issueService.fetchPublicIssues(anchor, params);
|
|
|
|
if (response) {
|
|
runInAction(() => {
|
|
this.states = response.states;
|
|
this.labels = response.labels;
|
|
this.issues = response.issues;
|
|
this.loader = false;
|
|
});
|
|
}
|
|
} catch (error) {
|
|
this.loader = false;
|
|
this.error = error;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @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
|
|
);
|
|
|
|
/**
|
|
* @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) || []
|
|
);
|
|
}
|