Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

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

guru_sainathc0ad5952dfd0
diff --git a/web/ce/services/index.ts b/web/ce/services/index.ts
new file mode 100644
index 0000000000..9ff8c7dff4
--- /dev/null
+++ b/web/ce/services/index.ts
@@ -0,0 +1 @@
+export * from "./project";
diff --git a/web/core/services/project/estimate.service.ts b/web/ce/services/project/estimate.service.ts
similarity index 74%
rename from web/core/services/project/estimate.service.ts
rename to web/ce/services/project/estimate.service.ts
index cbb81c43fc..1659d9966f 100644
--- a/web/core/services/project/estimate.service.ts
+++ b/web/ce/services/project/estimate.service.ts
@@ -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();
diff --git a/web/ce/services/project/index.ts b/web/ce/services/project/index.ts
new file mode 100644
index 0000000000..29b17e55d3
--- /dev/null
+++ b/web/ce/services/project/index.ts
@@ -0,0 +1 @@
+export * from "./estimate.service";
diff --git a/web/core/store/estimates/estimate.ts b/web/ce/store/estimates/estimate.ts
similarity index 51%
rename from web/core/store/estimates/estimate.ts
rename to web/ce/store/estimates/estimate.ts
index a37176b846..a61b9ee36e 100644
--- a/web/core/store/estimates/estimate.ts
+++ b/web/ce/store/estimates/estimate.ts
@@ -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;
- }
- };
}
diff --git a/web/core/components/dropdowns/estimate.tsx b/web/core/components/dropdowns/estimate.tsx
index 127e18a978..839696bba8 100644
--- a/web/core/components/dropdowns/estimate.tsx
+++ b/web/core/components/dropdowns/estimate.tsx
@@ -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({
diff --git a/web/core/hooks/store/estimates/use-estimate.ts b/web/core/hooks/store/estimates/use-estimate.ts
index a1c6ad4ef7..17aaf559e8 100644
--- a/web/core/hooks/store/estimates/use-estimate.ts
+++ b/web/core/hooks/store/estimates/use-estimate.ts
@@ -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);
diff --git a/web/core/services/project/index.ts b/web/core/services/project/index.ts
index 73121627c6..9b11f60ed9 100644
--- a/web/core/services/project/index.ts
+++ b/web/core/services/project/index.ts
@@ -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";
diff --git a/web/core/store/estimates/estimate-point.ts b/web/core/store/estimates/estimate-point.ts
index 495a1e7be6..e956770c06 100644
--- a/web/core/store/estimates/estimate-point.ts
+++ b/web/core/store/estimates/estimate-point.ts
@@ -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";
diff --git a/web/core/store/estimates/project-estimate.store.ts b/web/core/store/estimates/project-estimate.store.ts
index c9e8408122..f4a4500ec7 100644
--- a/web/core/store/estimates/project-estimate.store.ts
+++ b/web/core/store/estimates/project-estimate.store.ts
@@ -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;
diff --git a/web/ee/services/index.ts b/web/ee/services/index.ts
new file mode 100644
index 0000000000..9ff8c7dff4
--- /dev/null
+++ b/web/ee/services/index.ts
@@ -0,0 +1 @@
+export * from "./project";
diff --git a/web/ee/services/project/estimate.service.ts b/web/ee/services/project/estimate.service.ts
new file mode 100644
index 0000000000..752dd56efc
--- /dev/null
+++ b/web/ee/services/project/estimate.service.ts
@@ -0,0 +1 @@
+export * from "ce/services/project/estimate.service";
diff --git a/web/ee/services/project/index.ts b/web/ee/services/project/index.ts
new file mode 100644
index 0000000000..29b17e55d3
--- /dev/null
+++ b/web/ee/services/project/index.ts
@@ -0,0 +1 @@
+export * from "./estimate.service";
diff --git a/web/ee/store/estimates/estimate.ts b/web/ee/store/estimates/estimate.ts
new file mode 100644
index 0000000000..baf2d1af73
--- /dev/null
+++ b/web/ee/store/estimates/estimate.ts
@@ -0,0 +1 @@
+export * from "ce/store/estimates/estimate";