Some checks failed
Branch Build CE / Build Setup (push) Has been cancelled
Branch Build CE / Build-Push Admin Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Web Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Space Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Live Collaboration Docker Image (push) Has been cancelled
Branch Build CE / Build-Push API Server Docker Image (push) Has been cancelled
Branch Build CE / Build-Push Proxy Docker Image (push) Has been cancelled
Branch Build CE / Build-Push AIO Docker Image (push) Has been cancelled
Branch Build CE / Upload Build Assets (push) Has been cancelled
Branch Build CE / Build Release (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Codespell / Check for spelling errors (push) Has been cancelled
Sync Repositories / sync_changes (push) Has been cancelled
Synced from upstream: 8853637e981ed7d8a6cff32bd98e7afe20f54362
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import { observer } from "mobx-react";
|
|
import { useTranslation } from "@plane/i18n";
|
|
import { EstimatePropertyIcon } from "@plane/propel/icons";
|
|
import { EEstimateSystem } from "@plane/types";
|
|
import { cn, convertMinutesToHoursMinutesString } from "@plane/utils";
|
|
// hooks
|
|
import { useProjectEstimates } from "@/hooks/store/estimates";
|
|
import { useEstimate } from "@/hooks/store/estimates/use-estimate";
|
|
|
|
export type TReadonlyEstimateProps = {
|
|
className?: string;
|
|
hideIcon?: boolean;
|
|
value: string | undefined | null;
|
|
placeholder?: string;
|
|
projectId: string | undefined;
|
|
workspaceSlug: string;
|
|
};
|
|
|
|
export const ReadonlyEstimate: React.FC<TReadonlyEstimateProps> = observer((props) => {
|
|
const { className, hideIcon = false, value, placeholder, projectId, workspaceSlug } = props;
|
|
|
|
const { t } = useTranslation();
|
|
const { currentActiveEstimateIdByProjectId, getEstimateById, getProjectEstimates } = useProjectEstimates();
|
|
|
|
const currentActiveEstimateId = projectId ? currentActiveEstimateIdByProjectId(projectId) : undefined;
|
|
const currentActiveEstimate = currentActiveEstimateId ? getEstimateById(currentActiveEstimateId) : undefined;
|
|
const { estimatePointById } = useEstimate(currentActiveEstimateId);
|
|
|
|
const estimatePoint = value ? estimatePointById(value) : null;
|
|
|
|
const displayValue = estimatePoint
|
|
? currentActiveEstimate?.type === EEstimateSystem.TIME
|
|
? convertMinutesToHoursMinutesString(Number(estimatePoint.value))
|
|
: estimatePoint.value
|
|
: null;
|
|
|
|
useEffect(() => {
|
|
if (projectId) {
|
|
getProjectEstimates(workspaceSlug, projectId);
|
|
}
|
|
}, [projectId, workspaceSlug]);
|
|
|
|
return (
|
|
<div className={cn("flex items-center gap-1 text-sm", className)}>
|
|
{!hideIcon && <EstimatePropertyIcon className="size-4 flex-shrink-0" />}
|
|
<span className="flex-grow truncate">{displayValue ?? placeholder ?? t("common.none")}</span>
|
|
</div>
|
|
);
|
|
});
|