From c0ad5952dfd0253bc199f1db30602cac8578abb6 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Thu, 20 Jun 2024 19:29:09 +0530 Subject: [PATCH] [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 --- web/ce/services/index.ts | 1 + .../services/project/estimate.service.ts | 38 +---- web/ce/services/project/index.ts | 1 + web/{core => ce}/store/estimates/estimate.ts | 160 +----------------- web/core/components/dropdowns/estimate.tsx | 3 +- .../hooks/store/estimates/use-estimate.ts | 2 +- web/core/services/project/index.ts | 1 - web/core/store/estimates/estimate-point.ts | 6 +- .../store/estimates/project-estimate.store.ts | 7 +- web/ee/services/index.ts | 1 + web/ee/services/project/estimate.service.ts | 1 + web/ee/services/project/index.ts | 1 + web/ee/store/estimates/estimate.ts | 1 + 13 files changed, 28 insertions(+), 195 deletions(-) create mode 100644 web/ce/services/index.ts rename web/{core => ce}/services/project/estimate.service.ts (74%) create mode 100644 web/ce/services/project/index.ts rename web/{core => ce}/store/estimates/estimate.ts (51%) create mode 100644 web/ee/services/index.ts create mode 100644 web/ee/services/project/estimate.service.ts create mode 100644 web/ee/services/project/index.ts create mode 100644 web/ee/store/estimates/estimate.ts diff --git a/web/ce/services/index.ts b/web/ce/services/index.ts new file mode 100644 index 000000000..9ff8c7dff --- /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 cbb81c43f..1659d9966 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 - ): Promise { - 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 { 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 { - 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 000000000..29b17e55d --- /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 a37176b84..a61b9ee36 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 { estimatePointIds: string[] | undefined; estimatePointById: (estimatePointId: string) => IEstimatePointType | undefined; // actions - updateEstimateSortOrder: ( - workspaceSlug: string, - projectId: string, - payload: TEstimatePointsObject[] - ) => Promise; - updateEstimateSwitch: ( - workspaceSlug: string, - projectId: string, - payload: IEstimateFormData - ) => Promise; creteEstimatePoint: ( workspaceSlug: string, projectId: string, payload: Partial ) => Promise; - deleteEstimatePoint: ( - workspaceSlug: string, - projectId: string, - estimatePointId: string, - newEstimatePointId: string | undefined - ) => Promise; } export class Estimate implements IEstimate { @@ -72,8 +52,8 @@ export class Estimate implements IEstimate { estimatePoints: Record = {}; 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 => { - 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 => { - 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 => { - 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 127e18a97..839696bba 100644 --- a/web/core/components/dropdowns/estimate.tsx +++ b/web/core/components/dropdowns/estimate.tsx @@ -120,7 +120,8 @@ export const EstimateDropdown: React.FC = 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 a1c6ad4ef..17aaf559e 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 73121627c..9b11f60ed 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 495a1e7be..e956770c0 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 c9e840812..f4a4500ec 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 000000000..9ff8c7dff --- /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 000000000..752dd56ef --- /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 000000000..29b17e55d --- /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 000000000..baf2d1af7 --- /dev/null +++ b/web/ee/store/estimates/estimate.ts @@ -0,0 +1 @@ +export * from "ce/store/estimates/estimate";