mirror of
https://github.com/makeplane/plane.git
synced 2025-12-29 00:24:56 +01:00
[WEB-522] chore: Updated the estimates store and service on the ee (#455)
* fix: validating and showing proper alert estimate point has to be taken greater than 0 in create and update * chore: updated estimate store and service in ee * chore: updated estimate store * chore: resolved lint errors * chore: updated the lint errors and added ce in ts config
This commit is contained in:
@@ -1 +1,50 @@
|
||||
export * from "ce/services/project/estimate.service";
|
||||
/* eslint-disable no-useless-catch */
|
||||
|
||||
// types
|
||||
import { IEstimate, IEstimateFormData, IEstimatePoint } from "@plane/types";
|
||||
// ce services
|
||||
import { EstimateService as CeEstimateService } from "@/ce/services/project/estimate.service";
|
||||
|
||||
class EstimateService extends CeEstimateService {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
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 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();
|
||||
|
||||
export default estimateService;
|
||||
|
||||
@@ -1 +1,176 @@
|
||||
export * from "ce/store/estimates/estimate";
|
||||
/* eslint-disable no-useless-catch */
|
||||
|
||||
import set from "lodash/set";
|
||||
import unset from "lodash/unset";
|
||||
import { action, makeObservable, runInAction } from "mobx";
|
||||
// types
|
||||
import {
|
||||
IEstimate as IEstimateType,
|
||||
IEstimatePoint as IEstimatePointType,
|
||||
IEstimateFormData,
|
||||
TEstimatePointsObject,
|
||||
} from "@plane/types";
|
||||
// plane web store
|
||||
import { IEstimate as ICeEstimate, Estimate as CeEstimate } from "@/ce/store/estimates/estimate";
|
||||
// plane web service
|
||||
import estimateService from "@/plane-web/services/project/estimate.service";
|
||||
// store
|
||||
import { EstimatePoint } from "@/store/estimates/estimate-point";
|
||||
import { CoreRootStore } from "@/store/root.store";
|
||||
|
||||
export interface IEstimate extends ICeEstimate {
|
||||
// actions
|
||||
updateEstimateSortOrder: (
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
payload: TEstimatePointsObject[]
|
||||
) => Promise<IEstimateType | undefined>;
|
||||
updateEstimateSwitch: (
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
payload: IEstimateFormData
|
||||
) => Promise<IEstimateType | undefined>;
|
||||
deleteEstimatePoint: (
|
||||
workspaceSlug: string,
|
||||
projectId: string,
|
||||
estimatePointId: string,
|
||||
newEstimatePointId: string | undefined
|
||||
) => Promise<IEstimatePointType[] | undefined>;
|
||||
}
|
||||
|
||||
export class Estimate extends CeEstimate implements IEstimate {
|
||||
constructor(
|
||||
public store: CoreRootStore,
|
||||
public data: IEstimateType
|
||||
) {
|
||||
super(store, data);
|
||||
makeObservable(this, {
|
||||
// actions
|
||||
updateEstimateSortOrder: action,
|
||||
updateEstimateSwitch: action,
|
||||
deleteEstimatePoint: action,
|
||||
});
|
||||
}
|
||||
|
||||
// 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 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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"@/helpers/*": ["helpers/*"],
|
||||
"@/public/*": ["public/*"],
|
||||
"@/styles/*": ["styles/*"],
|
||||
"@/plane-web/*": ["ee/*"]
|
||||
"@/plane-web/*": ["ee/*"],
|
||||
"@/ce/*": ["ce/*"]
|
||||
},
|
||||
"plugins": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user