forked from github/plane
b3ac9def8d
* dev: workspace states and estimates * refactor issue dropdown logic to help work properly with issues on global level * fix: project labels response change * fix label type * change store computed actions to computed functions from mobx-utils * fix: state response change * chore: project and workspace state change * fix state and label types * chore: state and label serializer change * modify state and label types * fix dropdown reset on project id change * fix label sort order --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: Rahul R <rahulr@Rahuls-MacBook-Pro.local> Co-authored-by: NarayanBavisetti <narayan3119@gmail.com> Co-authored-by: Rahul R <rahul.ramesha@plane.so>
108 lines
3.0 KiB
TypeScript
108 lines
3.0 KiB
TypeScript
import { observable, action, makeObservable, runInAction, computed } from "mobx";
|
|
import { computedFn } from "mobx-utils";
|
|
import { set } from "lodash";
|
|
// services
|
|
import { InboxService } from "services/inbox.service";
|
|
// types
|
|
import { RootStore } from "store/root.store";
|
|
import { IInbox } from "@plane/types";
|
|
|
|
export interface IInboxStore {
|
|
// observables
|
|
inboxesList: {
|
|
[projectId: string]: IInbox[];
|
|
};
|
|
inboxDetails: {
|
|
[inboxId: string]: IInbox;
|
|
};
|
|
// computed
|
|
isInboxEnabled: boolean;
|
|
// computed actions
|
|
getInboxId: (projectId: string) => string | null;
|
|
// fetch actions
|
|
fetchInboxesList: (workspaceSlug: string, projectId: string) => Promise<IInbox[]>;
|
|
fetchInboxDetails: (workspaceSlug: string, projectId: string, inboxId: string) => Promise<IInbox>;
|
|
}
|
|
|
|
export class InboxStore implements IInboxStore {
|
|
// observables
|
|
inboxesList: {
|
|
[projectId: string]: IInbox[];
|
|
} = {};
|
|
inboxDetails: {
|
|
[inboxId: string]: IInbox;
|
|
} = {};
|
|
// root store
|
|
rootStore;
|
|
// services
|
|
inboxService;
|
|
|
|
constructor(_rootStore: RootStore) {
|
|
makeObservable(this, {
|
|
// observables
|
|
inboxesList: observable,
|
|
inboxDetails: observable,
|
|
// computed
|
|
isInboxEnabled: computed,
|
|
// actions
|
|
fetchInboxesList: action,
|
|
});
|
|
|
|
// root store
|
|
this.rootStore = _rootStore;
|
|
// services
|
|
this.inboxService = new InboxService();
|
|
}
|
|
|
|
/**
|
|
* Returns true if inbox is enabled for current project
|
|
*/
|
|
get isInboxEnabled() {
|
|
const projectId = this.rootStore.app.router.projectId;
|
|
if (!projectId) return false;
|
|
const projectDetails = this.rootStore.projectRoot.project.currentProjectDetails;
|
|
if (!projectDetails) return false;
|
|
return projectDetails.inbox_view;
|
|
}
|
|
|
|
/**
|
|
* Returns the inbox Id belongs to a specific project
|
|
*/
|
|
getInboxId = computedFn((projectId: string) => {
|
|
const projectDetails = this.rootStore.projectRoot.project.getProjectById(projectId);
|
|
if (!projectDetails || !projectDetails.inbox_view) return null;
|
|
return this.inboxesList[projectId]?.[0]?.id ?? null;
|
|
});
|
|
|
|
/**
|
|
* Fetches the inboxes list belongs to a specific project
|
|
* @param workspaceSlug
|
|
* @param projectId
|
|
* @returns Promise<IInbox[]>
|
|
*/
|
|
fetchInboxesList = async (workspaceSlug: string, projectId: string) => {
|
|
return await this.inboxService.getInboxes(workspaceSlug, projectId).then((inboxes) => {
|
|
runInAction(() => {
|
|
set(this.inboxesList, projectId, inboxes);
|
|
});
|
|
return inboxes;
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Fetches the inbox details belongs to a specific inbox
|
|
* @param workspaceSlug
|
|
* @param projectId
|
|
* @param inboxId
|
|
* @returns Promise<IInbox>
|
|
*/
|
|
fetchInboxDetails = async (workspaceSlug: string, projectId: string, inboxId: string) => {
|
|
return await this.inboxService.getInboxById(workspaceSlug, projectId, inboxId).then((inboxDetailsResponse) => {
|
|
runInAction(() => {
|
|
set(this.inboxDetails, inboxId, inboxDetailsResponse);
|
|
});
|
|
return inboxDetailsResponse;
|
|
});
|
|
};
|
|
}
|