major refactor of the dashboard and react-openapi integration #1

Merged
aetos merged 44 commits from period-selection into main 2026-05-07 11:00:54 +00:00
3 changed files with 62 additions and 42 deletions
Showing only changes of commit 67d4c85146 - Show all commits

View File

@@ -1,23 +1,22 @@
import * as React from "react";
import ProgressCardView from "./ProgressCard.view"; import ProgressCardView from "./ProgressCard.view";
import { ProgressCardProps } from "./ProgressCard.models"; import { ProgressCardProps } from "./ProgressCard.models";
import { getPercentage, parseSummary } from "./ProgressCard.utils"; import { getPercentage, formatCurrency } from "./ProgressCard.utils";
export default function ProgressCard(props: ProgressCardProps) { export default function ProgressCard(props: ProgressCardProps) {
const { progressAmount, totalAmount, summary, compact = false } = props; const { progressAmount, totalAmount, compact = false } = props;
const percentage = getPercentage(progressAmount, totalAmount); const percentage = getPercentage(progressAmount, totalAmount);
const { prefixAmount, suffixString } = parseSummary(
summary, const formattedProgress = formatCurrency(progressAmount);
progressAmount, const formattedTotal = formatCurrency(totalAmount);
totalAmount
);
return ( return (
<ProgressCardView <ProgressCardView
{...props} {...props}
percentage={percentage} percentage={percentage}
prefixAmount={prefixAmount} formattedProgress={formattedProgress}
suffixString={suffixString} formattedTotal={formattedTotal}
compact={compact} compact={compact}
/> />
); );

View File

@@ -3,17 +3,13 @@ export const getPercentage = (progressAmount: number, totalAmount: number) => {
return Math.min(100, Math.max(0, (progressAmount / totalAmount) * 100)); return Math.min(100, Math.max(0, (progressAmount / totalAmount) * 100));
}; };
export const parseSummary = ( export const formatCurrency = (val: number) => {
summary: string | undefined, const absVal = Math.abs(val);
progressAmount: number, if (absVal >= 100000) {
totalAmount: number return `${(val / 100000).toFixed(2)}L`;
) => { }
const displaySummary = summary ?? `Rs ${progressAmount} / Rs ${totalAmount}`; if (absVal >= 1000) {
return `${(val / 1000).toFixed(2)}k`;
const parts = displaySummary.split("/"); }
const prefixAmount = parts[0]?.trim() || ""; return `${val.toFixed(2)}`;
const suffixString =
parts.length > 1 ? `/ ${parts.slice(1).join("/").trim()}` : "";
return { prefixAmount, suffixString };
}; };

View File

@@ -4,22 +4,23 @@ import {
Typography, Typography,
Paper, Paper,
LinearProgress, LinearProgress,
Divider,
linearProgressClasses linearProgressClasses
} from "@mui/material"; } from "@mui/material";
import { ProgressCardProps } from "./ProgressCard.models"; import { ProgressCardProps } from "./ProgressCard.models";
interface ViewProps extends ProgressCardProps { interface ViewProps extends ProgressCardProps {
percentage: number; percentage: number;
prefixAmount: string; formattedProgress: string;
suffixString: string; formattedTotal: string;
} }
export default function ProgressCardView({ export default function ProgressCardView({
header, header,
colorTheme = "info", colorTheme = "info",
percentage, percentage,
prefixAmount, formattedProgress,
suffixString, formattedTotal,
compact = false, compact = false,
}: ViewProps) { }: ViewProps) {
return ( return (
@@ -27,7 +28,7 @@ export default function ProgressCardView({
elevation={compact ? 2 : 4} elevation={compact ? 2 : 4}
sx={{ sx={{
width: "100%", width: "100%",
p: compact ? { xs: 2, md: 2.5 } : { xs: 3, md: 4 }, p: compact ? { xs: 2.5, md: 3 } : { xs: 3, md: 4 },
borderRadius: compact ? 3 : 4, borderRadius: compact ? 3 : 4,
background: (theme) => background: (theme) =>
colorTheme === "info" colorTheme === "info"
@@ -50,26 +51,50 @@ export default function ProgressCardView({
> >
<Typography <Typography
variant={compact ? "body2" : "subtitle1"} variant={compact ? "body2" : "subtitle1"}
fontWeight={600} fontWeight={700}
sx={{ opacity: 0.9, mb: compact ? 0.5 : 1, width: '100%', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }} sx={{
opacity: 0.9,
mb: compact ? 1.5 : 2,
width: '100%',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
letterSpacing: 0.5
}}
> >
{header} {header}
</Typography> </Typography>
<Typography variant={compact ? "h5" : "h3"} fontWeight={800} sx={{ mb: compact ? 2 : 3 }}> <Box sx={{ mb: compact ? 2 : 3, width: '100%' }}>
{prefixAmount}{" "} <Typography
{suffixString && ( variant={compact ? "h5" : "h3"}
<Typography fontWeight={900}
component="span" sx={{ mb: 0.5, lineHeight: 1.2 }}
variant={compact ? "caption" : "subtitle1"} >
sx={{ opacity: 0.7, fontWeight: 500 }} {formattedProgress}
> </Typography>
{suffixString}
</Typography>
)}
</Typography>
<Box sx={{ width: compact ? "100%" : "85%" }}> <Divider
sx={{
my: 1,
borderColor: "rgba(255,255,255,0.4)",
width: "100%",
}}
/>
<Typography
variant={compact ? "caption" : "body2"}
sx={{
opacity: 0.8,
fontWeight: 400,
display: "block"
}}
>
{formattedTotal}
</Typography>
</Box>
<Box sx={{ width: "100%", mt: 'auto' }}>
<LinearProgress <LinearProgress
variant="determinate" variant="determinate"
value={percentage} value={percentage}