[WEB-522] chore: Move the estimates store and service out of core (#4896)

* chore: moved the estimate store from core to ce and ee

* chore: moved the estimate service from core to ce and ee

* chore: updated constructors from private to public in estimate store

* chore: exported estimate service
This commit is contained in:
guru_sainath 2024-06-20 19:29:09 +05:30 committed by GitHub
parent 94e6fd4b29
commit c0ad5952df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 28 additions and 195 deletions

1
web/ce/services/index.ts Normal file
View file

@ -0,0 +1 @@
export * from "./project";

View file

@ -1,3 +1,5 @@
/* eslint-disable no-useless-catch */
// types
import { IEstimate, IEstimateFormData, IEstimatePoint } from "@plane/types";
// helpers
@ -5,7 +7,7 @@ import { API_BASE_URL } from "@/helpers/common.helper";
// services
import { APIService } from "@/services/api.service";
class EstimateService extends APIService {
export class EstimateService extends APIService {
constructor() {
super(API_BASE_URL);
}
@ -56,23 +58,6 @@ class EstimateService extends APIService {
}
}
async updateEstimate(
workspaceSlug: string,
projectId: string,
estimateId: string,
payload: Partial<IEstimateFormData>
): Promise<IEstimate | undefined> {
try {
const { data } = await this.patch(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`,
payload
);
return data || undefined;
} catch (error) {
throw error;
}
}
async deleteEstimate(workspaceSlug: string, projectId: string, estimateId: string): Promise<void> {
try {
await this.delete(`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/`);
@ -115,23 +100,6 @@ class EstimateService extends APIService {
throw error;
}
}
async removeEstimatePoint(
workspaceSlug: string,
projectId: string,
estimateId: string,
estimatePointId: string,
params?: { new_estimate_id: string | undefined }
): Promise<IEstimatePoint[] | undefined> {
return this.delete(
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-points/${estimatePointId}/`,
params
)
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}
const estimateService = new EstimateService();

View file

@ -0,0 +1 @@
export * from "./estimate.service";

View file

@ -1,18 +1,14 @@
/* eslint-disable no-useless-catch */
import orderBy from "lodash/orderBy";
import set from "lodash/set";
import unset from "lodash/unset";
// import unset from "lodash/unset";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
import { computedFn } from "mobx-utils";
// types
import {
IEstimate as IEstimateType,
IEstimatePoint as IEstimatePointType,
TEstimateSystemKeys,
IEstimateFormData,
TEstimatePointsObject,
} from "@plane/types";
// services
import estimateService from "@/services/project/estimate.service";
import { IEstimate as IEstimateType, IEstimatePoint as IEstimatePointType, TEstimateSystemKeys } from "@plane/types";
// plane web services
import estimateService from "@/plane-web/services/project/estimate.service";
// store
import { IEstimatePoint, EstimatePoint } from "@/store/estimates/estimate-point";
import { CoreRootStore } from "@/store/root.store";
@ -31,27 +27,11 @@ export interface IEstimate extends Omit<IEstimateType, "points"> {
estimatePointIds: string[] | undefined;
estimatePointById: (estimatePointId: string) => IEstimatePointType | undefined;
// actions
updateEstimateSortOrder: (
workspaceSlug: string,
projectId: string,
payload: TEstimatePointsObject[]
) => Promise<IEstimateType | undefined>;
updateEstimateSwitch: (
workspaceSlug: string,
projectId: string,
payload: IEstimateFormData
) => Promise<IEstimateType | undefined>;
creteEstimatePoint: (
workspaceSlug: string,
projectId: string,
payload: Partial<IEstimatePointType>
) => Promise<IEstimatePointType | undefined>;
deleteEstimatePoint: (
workspaceSlug: string,
projectId: string,
estimatePointId: string,
newEstimatePointId: string | undefined
) => Promise<IEstimatePointType[] | undefined>;
}
export class Estimate implements IEstimate {
@ -72,8 +52,8 @@ export class Estimate implements IEstimate {
estimatePoints: Record<string, IEstimatePoint> = {};
constructor(
private store: CoreRootStore,
private data: IEstimateType
public store: CoreRootStore,
public data: IEstimateType
) {
makeObservable(this, {
// data model observables
@ -95,10 +75,7 @@ export class Estimate implements IEstimate {
asJson: computed,
estimatePointIds: computed,
// actions
updateEstimateSortOrder: action,
updateEstimateSwitch: action,
creteEstimatePoint: action,
deleteEstimatePoint: action,
});
this.id = this.data.id;
this.name = this.data.name;
@ -151,75 +128,6 @@ export class Estimate implements IEstimate {
});
// actions
/**
* @description update an estimate sort order
* @param { string } workspaceSlug
* @param { string } projectId
* @param { TEstimatePointsObject[] } payload
* @returns { IEstimateType | undefined }
*/
updateEstimateSortOrder = async (
workspaceSlug: string,
projectId: string,
payload: TEstimatePointsObject[]
): Promise<IEstimateType | undefined> => {
try {
if (!this.id || !payload) return;
const estimate = await estimateService.updateEstimate(workspaceSlug, projectId, this.id, {
estimate_points: payload,
});
runInAction(() => {
estimate?.points &&
estimate?.points.map((estimatePoint) => {
if (estimatePoint.id)
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
});
});
return estimate;
} catch (error) {
throw error;
}
};
/**
* @description update an estimate sort order
* @param { string } workspaceSlug
* @param { string } projectId
* @param { IEstimateFormData} payload
* @returns { IEstimateType | undefined }
*/
updateEstimateSwitch = async (
workspaceSlug: string,
projectId: string,
payload: IEstimateFormData
): Promise<IEstimateType | undefined> => {
try {
if (!this.id || !payload) return;
const estimate = await estimateService.updateEstimate(workspaceSlug, projectId, this.id, payload);
if (estimate) {
runInAction(() => {
this.name = estimate?.name;
this.type = estimate?.type;
estimate?.points &&
estimate?.points.map((estimatePoint) => {
if (estimatePoint.id)
this.estimatePoints?.[estimatePoint.id]?.updateEstimatePointObject({
key: estimatePoint.key,
value: estimatePoint.value,
});
});
});
}
return estimate;
} catch (error) {
throw error;
}
};
/**
* @description create an estimate point
* @param { string } workspaceSlug
@ -247,56 +155,4 @@ export class Estimate implements IEstimate {
throw error;
}
};
/**
* @description delete an estimate point
* @param { string } workspaceSlug
* @param { string } projectId
* @param { string } estimatePointId
* @param { string | undefined } newEstimatePointId
* @returns { void }
*/
deleteEstimatePoint = async (
workspaceSlug: string,
projectId: string,
estimatePointId: string,
newEstimatePointId: string | undefined
): Promise<IEstimatePointType[] | undefined> => {
try {
if (!this.id) return;
const deleteEstimatePoint = await estimateService.removeEstimatePoint(
workspaceSlug,
projectId,
this.id,
estimatePointId,
newEstimatePointId ? { new_estimate_id: newEstimatePointId } : undefined
);
const currentIssues = Object.values(this.store.issue.issues.issuesMap || {});
if (currentIssues) {
currentIssues.map((issue) => {
if (issue.estimate_point === estimatePointId) {
this.store.issue.issues.updateIssue(issue.id, { estimate_point: newEstimatePointId });
}
});
}
runInAction(() => {
unset(this.estimatePoints, [estimatePointId]);
});
if (deleteEstimatePoint) {
runInAction(() => {
deleteEstimatePoint.map((estimatePoint) => {
if (estimatePoint.id)
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
});
});
}
return deleteEstimatePoint;
} catch (error) {
throw error;
}
};
}

View file

@ -120,7 +120,8 @@ export const EstimateDropdown: React.FC<Props> = observer((props) => {
const selectedEstimate = value && estimatePointById ? estimatePointById(value) : undefined;
const onOpen = async () => {
if (!currentActiveEstimateId && workspaceSlug && projectId) await getProjectEstimates(workspaceSlug.toString(), projectId);
if (!currentActiveEstimateId && workspaceSlug && projectId)
await getProjectEstimates(workspaceSlug.toString(), projectId);
};
const { handleClose, handleKeyDown, handleOnClick, searchInputKeyDown } = useDropdown({

View file

@ -2,7 +2,7 @@ import { useContext } from "react";
// mobx store
import { StoreContext } from "@/lib/store-context";
// mobx store
import { IEstimate } from "@/store/estimates/estimate";
import { IEstimate } from "@/plane-web/store/estimates/estimate";
export const useEstimate = (estimateId: string | undefined): IEstimate => {
const context = useContext(StoreContext);

View file

@ -1,5 +1,4 @@
export * from "./project.service";
export * from "./estimate.service";
export * from "./project-export.service";
export * from "./project-member.service";
export * from "./project-state.service";

View file

@ -1,9 +1,11 @@
/* eslint-disable no-useless-catch */
import set from "lodash/set";
import { action, computed, makeObservable, observable, runInAction } from "mobx";
// types
import { IEstimate, IEstimatePoint as IEstimatePointType } from "@plane/types";
// services
import estimateService from "@/services/project/estimate.service";
// plane web services
import estimateService from "@/plane-web/services/project/estimate.service";
// store
import { CoreRootStore } from "@/store/root.store";

View file

@ -6,10 +6,11 @@ import { action, computed, makeObservable, observable, runInAction } from "mobx"
import { computedFn } from "mobx-utils";
// types
import { IEstimate as IEstimateType, IEstimateFormData } from "@plane/types";
// services
import estimateService from "@/services/project/estimate.service";
// plane web services
import estimateService from "@/plane-web/services/project/estimate.service";
// plane web store
import { IEstimate, Estimate } from "@/plane-web/store/estimates/estimate";
// store
import { IEstimate, Estimate } from "@/store/estimates/estimate";
import { CoreRootStore } from "../root.store";
type TEstimateLoader = "init-loader" | "mutation-loader" | undefined;

1
web/ee/services/index.ts Normal file
View file

@ -0,0 +1 @@
export * from "./project";

View file

@ -0,0 +1 @@
export * from "ce/services/project/estimate.service";

View file

@ -0,0 +1 @@
export * from "./estimate.service";

View file

@ -0,0 +1 @@
export * from "ce/store/estimates/estimate";