mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: handled estimate edit
This commit is contained in:
parent
1c1620a822
commit
e6fa881721
@ -36,7 +36,7 @@ export const EstimatePointDelete: FC<TEstimatePointDelete> = observer((props) =>
|
|||||||
try {
|
try {
|
||||||
setLoader(true);
|
setLoader(true);
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
await deleteEstimatePoint(workspaceSlug, projectId, estimateId, estimateInputValue);
|
await deleteEstimatePoint(workspaceSlug, projectId, estimatePointId, estimateInputValue);
|
||||||
setLoader(false);
|
setLoader(false);
|
||||||
setError(undefined);
|
setError(undefined);
|
||||||
handleClose();
|
handleClose();
|
||||||
|
@ -23,7 +23,7 @@ export const EstimatePointEditRoot: FC<TEstimatePointEditRoot> = observer((props
|
|||||||
// hooks
|
// hooks
|
||||||
const { asJson: estimate, estimatePointIds, estimatePointById, updateEstimateSortOrder } = useEstimate(estimateId);
|
const { asJson: estimate, estimatePointIds, estimatePointById, updateEstimateSortOrder } = useEstimate(estimateId);
|
||||||
// states
|
// states
|
||||||
const [estimatePointCreateToggle, setEstimatePointCreateToggle] = useState(false);
|
const [estimatePointCreate, setEstimatePointCreate] = useState<TEstimatePointsObject[] | undefined>(undefined);
|
||||||
|
|
||||||
const estimatePoints: TEstimatePointsObject[] =
|
const estimatePoints: TEstimatePointsObject[] =
|
||||||
estimatePointIds && estimatePointIds.length > 0
|
estimatePointIds && estimatePointIds.length > 0
|
||||||
@ -33,6 +33,25 @@ export const EstimatePointEditRoot: FC<TEstimatePointEditRoot> = observer((props
|
|||||||
}) as TEstimatePointsObject[])
|
}) as TEstimatePointsObject[])
|
||||||
: ([] as TEstimatePointsObject[]);
|
: ([] as TEstimatePointsObject[]);
|
||||||
|
|
||||||
|
const handleEstimatePointCreate = (mode: "add" | "remove", value: TEstimatePointsObject) => {
|
||||||
|
switch (mode) {
|
||||||
|
case "add":
|
||||||
|
setEstimatePointCreate((prevValue) => {
|
||||||
|
prevValue = prevValue ? [...prevValue] : [];
|
||||||
|
return [...prevValue, value];
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "remove":
|
||||||
|
setEstimatePointCreate((prevValue) => {
|
||||||
|
prevValue = prevValue ? [...prevValue] : [];
|
||||||
|
return prevValue.filter((item) => item.key !== value.key);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleDragEstimatePoints = (updatedEstimatedOrder: TEstimatePointsObject[]) => {
|
const handleDragEstimatePoints = (updatedEstimatedOrder: TEstimatePointsObject[]) => {
|
||||||
const updatedEstimateKeysOrder = updatedEstimatedOrder.map((item, index) => ({ ...item, key: index + 1 }));
|
const updatedEstimateKeysOrder = updatedEstimatedOrder.map((item, index) => ({ ...item, key: index + 1 }));
|
||||||
updateEstimateSortOrder(workspaceSlug, projectId, updatedEstimateKeysOrder);
|
updateEstimateSortOrder(workspaceSlug, projectId, updatedEstimateKeysOrder);
|
||||||
@ -60,21 +79,28 @@ export const EstimatePointEditRoot: FC<TEstimatePointEditRoot> = observer((props
|
|||||||
keyExtractor={(item: TEstimatePointsObject) => item?.id?.toString() || item.value.toString()}
|
keyExtractor={(item: TEstimatePointsObject) => item?.id?.toString() || item.value.toString()}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{estimatePointCreateToggle && (
|
{estimatePointCreate &&
|
||||||
|
estimatePointCreate.map((estimatePoint) => (
|
||||||
<EstimatePointCreate
|
<EstimatePointCreate
|
||||||
|
key={estimatePoint?.key}
|
||||||
workspaceSlug={workspaceSlug}
|
workspaceSlug={workspaceSlug}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
estimateId={estimateId}
|
estimateId={estimateId}
|
||||||
callback={() => setEstimatePointCreateToggle(false)}
|
callback={() => handleEstimatePointCreate("remove", estimatePoint)}
|
||||||
/>
|
/>
|
||||||
)}
|
))}
|
||||||
{estimatePoints && estimatePoints.length <= maxEstimatesCount && (
|
{estimatePoints && estimatePoints.length + (estimatePointCreate?.length || 0) <= maxEstimatesCount && (
|
||||||
<Button
|
<Button
|
||||||
variant="link-primary"
|
variant="link-primary"
|
||||||
size="sm"
|
size="sm"
|
||||||
prependIcon={<Plus />}
|
prependIcon={<Plus />}
|
||||||
onClick={() => setEstimatePointCreateToggle(true)}
|
onClick={() =>
|
||||||
disabled={estimatePointCreateToggle}
|
handleEstimatePointCreate("add", {
|
||||||
|
id: undefined,
|
||||||
|
key: estimatePoints.length + (estimatePointCreate?.length || 0) + 1,
|
||||||
|
value: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
>
|
>
|
||||||
Add {estimate?.type}
|
Add {estimate?.type}
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -114,7 +114,7 @@ export class EstimateService extends APIService {
|
|||||||
estimateId: string,
|
estimateId: string,
|
||||||
estimatePointId: string,
|
estimatePointId: string,
|
||||||
params?: { new_estimate_id: string | undefined }
|
params?: { new_estimate_id: string | undefined }
|
||||||
): Promise<void> {
|
): Promise<IEstimatePoint[] | undefined> {
|
||||||
return this.delete(
|
return this.delete(
|
||||||
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-points/${estimatePointId}/`,
|
`/api/workspaces/${workspaceSlug}/projects/${projectId}/estimates/${estimateId}/estimate-points/${estimatePointId}/`,
|
||||||
params
|
params
|
||||||
|
@ -50,7 +50,7 @@ export interface IEstimate extends IEstimateType {
|
|||||||
projectId: string,
|
projectId: string,
|
||||||
estimatePointId: string,
|
estimatePointId: string,
|
||||||
newEstimatePointId: string | undefined
|
newEstimatePointId: string | undefined
|
||||||
) => Promise<void>;
|
) => Promise<IEstimatePointType[] | undefined>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Estimate implements IEstimate {
|
export class Estimate implements IEstimate {
|
||||||
@ -252,7 +252,7 @@ export class Estimate implements IEstimate {
|
|||||||
projectId: string,
|
projectId: string,
|
||||||
estimatePointId: string,
|
estimatePointId: string,
|
||||||
newEstimatePointId: string | undefined
|
newEstimatePointId: string | undefined
|
||||||
) => {
|
): Promise<IEstimatePointType[] | undefined> => {
|
||||||
try {
|
try {
|
||||||
if (!this.id) return;
|
if (!this.id) return;
|
||||||
|
|
||||||
@ -267,6 +267,14 @@ export class Estimate implements IEstimate {
|
|||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
unset(this.estimatePoints, [estimatePointId]);
|
unset(this.estimatePoints, [estimatePointId]);
|
||||||
});
|
});
|
||||||
|
if (deleteEstimatePoint && deleteEstimatePoint.length > 0) {
|
||||||
|
runInAction(() => {
|
||||||
|
deleteEstimatePoint.map((estimatePoint) => {
|
||||||
|
if (estimatePoint.id)
|
||||||
|
set(this.estimatePoints, [estimatePoint.id], new EstimatePoint(this.store, this.data, estimatePoint));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return deleteEstimatePoint;
|
return deleteEstimatePoint;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user