2023-12-18 07:01:57 +00:00
|
|
|
import { observable, makeObservable, action } from "mobx";
|
2023-12-15 09:28:40 +00:00
|
|
|
import { RootStore } from "../root.store";
|
|
|
|
// types
|
|
|
|
import { IIssueLabel } from "types";
|
|
|
|
import { IProjectLabelStore, ProjectLabelStore } from "./project-label.store";
|
|
|
|
import { IWorkspaceLabelStore, WorkspaceLabelStore } from "./workspace-label.store";
|
|
|
|
|
|
|
|
export interface ILabelRootStore {
|
|
|
|
// observables
|
|
|
|
labelMap: Record<string, IIssueLabel>;
|
|
|
|
// computed actions
|
|
|
|
getLabelById: (labelId: string) => IIssueLabel | null;
|
|
|
|
// sub-stores
|
|
|
|
project: IProjectLabelStore;
|
|
|
|
workspace: IWorkspaceLabelStore;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class LabelRootStore implements ILabelRootStore {
|
|
|
|
// observables
|
|
|
|
labelMap: Record<string, IIssueLabel> = {};
|
|
|
|
// root store
|
|
|
|
rootStore;
|
|
|
|
// sub-stores
|
|
|
|
project: IProjectLabelStore;
|
|
|
|
workspace: IWorkspaceLabelStore;
|
|
|
|
|
|
|
|
constructor(_rootStore: RootStore) {
|
|
|
|
makeObservable(this, {
|
|
|
|
// observables
|
|
|
|
labelMap: observable,
|
|
|
|
// computed actions
|
2023-12-18 07:01:57 +00:00
|
|
|
getLabelById: action,
|
2023-12-15 09:28:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// root store
|
|
|
|
this.rootStore = _rootStore;
|
|
|
|
// sub-stores
|
|
|
|
this.project = new ProjectLabelStore(_rootStore);
|
|
|
|
this.workspace = new WorkspaceLabelStore(_rootStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get label info from the map of labels in the store using label id
|
|
|
|
* @param labelId
|
|
|
|
*/
|
|
|
|
getLabelById = (labelId: string): IIssueLabel | null => this.labelMap?.[labelId] || null;
|
|
|
|
}
|