Adding percentage in Infrastructure.

This commit is contained in:
Kartik Sharma 2025-10-07 11:23:03 +05:30 committed by pramod.mahajan
parent 00353b23d6
commit 6151fa9424
2 changed files with 49 additions and 19 deletions

View File

@ -108,7 +108,10 @@ const WorkArea = ({ workArea, floor, forBuilding }) => {
<ProgressBar
completedWork={formatNumber(workArea?.completedWork)}
plannedWork={formatNumber(workArea?.plannedWork)}
className="m-0 my-2 me-6 text-info"
className="m-0 my-2"
height="6px"
rounded
showLabel={true}
/>
</div>
</div>

View File

@ -3,35 +3,62 @@ import React from "react";
const ProgressBar = ({
plannedWork = 100,
completedWork = 0,
height = "8px",
height = "6px",
className = "mb-4",
rounded = true,
showLabel = true,
}) => {
const getProgress = (planned, completed) => {
if (!planned || planned === 0) return "0%";
return `${Math.min((completed / planned) * 100, 100).toFixed(2)}%`;
if (!planned || planned === 0) return 0;
return Math.min((completed / planned) * 100, 100);
};
const progressStyle = {
width: getProgress(plannedWork, completedWork),
const percentage = getProgress(plannedWork, completedWork);
const progressBarStyle = {
width: `${percentage.toFixed(2)}%`,
transition: "width 0.4s ease",
};
const containerStyle = {
height,
display: "flex",
alignItems: "center",
gap: "8px",
};
return (
<div
className={`progress ${className} ${rounded ? "rounded" : ""}`}
style={{ height }}
>
<div
className={`progress-bar ${rounded ? "rounded" : ""}`}
role="progressbar"
style={progressStyle}
aria-valuenow={completedWork}
aria-valuemin="0"
aria-valuemax={plannedWork}
></div>
<div className={`d-flex align-items-center ${className}`} style={containerStyle}>
<div className="flex-grow-1">
<div
className={`progress ${rounded ? "rounded" : ""}`}
style={{ height, backgroundColor: "#f0f0f0" }}
>
<div
className={`progress-bar ${rounded ? "rounded" : ""}`}
role="progressbar"
style={progressBarStyle}
aria-valuenow={completedWork}
aria-valuemin="0"
aria-valuemax={plannedWork}
/>
</div>
</div>
{showLabel && (
<span
className="fw-semibold text-secondary"
style={{
minWidth: "45px",
textAlign: "right",
fontSize: "0.8rem",
}}
>
{percentage.toFixed(2)}%
</span>
)}
</div>
);
};
export default ProgressBar;