common component props
This commit is contained in:
@@ -161,7 +161,6 @@ export default function Dashboard() {
|
|||||||
config={configuration}
|
config={configuration}
|
||||||
data={data}
|
data={data}
|
||||||
isFetching={report.isFetching}
|
isFetching={report.isFetching}
|
||||||
onFlowChange={handleFlowChange}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,27 +19,23 @@ export interface DashboardState {
|
|||||||
export interface DashboardStateSetters {
|
export interface DashboardStateSetters {
|
||||||
setSelectedPeriodId: (id: DashboardSelectedPeriodId) => void;
|
setSelectedPeriodId: (id: DashboardSelectedPeriodId) => void;
|
||||||
setSelectedGroupKey: (groupKey: GroupKey | null) => void;
|
setSelectedGroupKey: (groupKey: GroupKey | null) => void;
|
||||||
|
toggleFlow: () => void;
|
||||||
togglePeriodType: () => void;
|
togglePeriodType: () => void;
|
||||||
toggleComparison: () => void;
|
toggleComparison: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DashboardSection {
|
export interface DashboardSection {
|
||||||
id: string;
|
id: string;
|
||||||
title?: string;
|
title: string;
|
||||||
summary?: string;
|
|
||||||
component: React.ComponentType<any>;
|
component: React.ComponentType<any>;
|
||||||
|
summary?: string;
|
||||||
settings?: Record<string, any>;
|
settings?: Record<string, any>;
|
||||||
isList?: boolean;
|
|
||||||
style?: {
|
|
||||||
size?: number;
|
|
||||||
[key: string]: any;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ColorDefinition {
|
export interface ColorDefinition {
|
||||||
primary: string;
|
primary: string;
|
||||||
background?: string;
|
background: string;
|
||||||
text?: string;
|
text: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ThemeAwarePalette {
|
export interface ThemeAwarePalette {
|
||||||
@@ -49,14 +45,28 @@ export interface ThemeAwarePalette {
|
|||||||
|
|
||||||
export interface DashboardConfig {
|
export interface DashboardConfig {
|
||||||
sections: DashboardSection[];
|
sections: DashboardSection[];
|
||||||
style?: {
|
style: {
|
||||||
palette?: Record<DashboardFlow, ThemeAwarePalette>;
|
palette: Record<DashboardFlow, ThemeAwarePalette>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DashboardProps {
|
export interface DashboardProps {
|
||||||
config: DashboardConfig;
|
config: DashboardConfig;
|
||||||
data: ReportData;
|
data: ReportData;
|
||||||
isFetching?: boolean;
|
isFetching: boolean;
|
||||||
onFlowChange?: (state: DashboardState) => void;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface ComponentProps extends DashboardSection {
|
||||||
|
reportData: ReportData;
|
||||||
|
|
||||||
|
state: DashboardState;
|
||||||
|
stateSetters: DashboardStateSetters;
|
||||||
|
isFetching: boolean;
|
||||||
|
|
||||||
|
colorScheme: {
|
||||||
|
primary: string;
|
||||||
|
light: string;
|
||||||
|
text: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import DashboardView from "./Dashboard.view";
|
import {
|
||||||
|
Box,
|
||||||
|
Container,
|
||||||
|
Grid,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
Button
|
||||||
|
} from "@mui/material";
|
||||||
|
import { useTheme, alpha } from "@mui/material/styles";
|
||||||
import { DashboardProps, DashboardState, DashboardStateSetters } from "./Dashboard.models";
|
import { DashboardProps, DashboardState, DashboardStateSetters } from "./Dashboard.models";
|
||||||
|
|
||||||
export default function Dashboard(props: DashboardProps) {
|
export default function Dashboard({
|
||||||
|
config,
|
||||||
|
data,
|
||||||
|
isFetching,
|
||||||
|
}: DashboardProps) {
|
||||||
|
const theme = useTheme();
|
||||||
|
const themeMode = theme.palette.mode;
|
||||||
|
|
||||||
const [state, setState] = React.useState<DashboardState>({
|
const [state, setState] = React.useState<DashboardState>({
|
||||||
flow: "outflows",
|
flow: "outflows",
|
||||||
periodType: "rolling",
|
periodType: "rolling",
|
||||||
@@ -11,20 +26,11 @@ export default function Dashboard(props: DashboardProps) {
|
|||||||
comparison: false,
|
comparison: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleFlow = (
|
const toggleFlow = () => {
|
||||||
event: React.MouseEvent<HTMLElement>,
|
setState(prev => ({
|
||||||
newFlow: "outflows" | "inflows" | null
|
...prev,
|
||||||
) => {
|
flow: prev.flow === "outflows" ? "inflows" : "outflows",
|
||||||
if (newFlow === null) return;
|
}));
|
||||||
|
|
||||||
setState(prev => {
|
|
||||||
if (prev.flow === newFlow) return prev;
|
|
||||||
|
|
||||||
const next = { ...prev, flow: newFlow };
|
|
||||||
props.onFlowChange?.(next);
|
|
||||||
|
|
||||||
return next;
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const togglePeriodType = () => {
|
const togglePeriodType = () => {
|
||||||
@@ -52,17 +58,119 @@ export default function Dashboard(props: DashboardProps) {
|
|||||||
const stateSetters: DashboardStateSetters = {
|
const stateSetters: DashboardStateSetters = {
|
||||||
togglePeriodType,
|
togglePeriodType,
|
||||||
toggleComparison,
|
toggleComparison,
|
||||||
|
toggleFlow,
|
||||||
setSelectedPeriodId,
|
setSelectedPeriodId,
|
||||||
setSelectedGroupKey,
|
setSelectedGroupKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const { flow, selectedGroupKey } = state;
|
||||||
|
|
||||||
|
const colors = React.useMemo(() => {
|
||||||
|
const palette = config.style.palette[flow];
|
||||||
|
const modeColors = palette[themeMode];
|
||||||
|
|
||||||
|
return {
|
||||||
|
primary: modeColors.primary,
|
||||||
|
light: modeColors.background || alpha(modeColors.primary, 0.1),
|
||||||
|
text:
|
||||||
|
modeColors.text ||
|
||||||
|
(themeMode === "light" ? theme.palette.text.primary : "#fff"),
|
||||||
|
};
|
||||||
|
|
||||||
|
// if (modeColors) {
|
||||||
|
// return {
|
||||||
|
// primary: modeColors.primary,
|
||||||
|
// light: modeColors.background || alpha(modeColors.primary, 0.1),
|
||||||
|
// text:
|
||||||
|
// modeColors.text ||
|
||||||
|
// (themeMode === "light" ? theme.palette.text.primary : "#fff"),
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// const themeColor =
|
||||||
|
// flow === "outflows" ? theme.palette.error : theme.palette.success;
|
||||||
|
//
|
||||||
|
// return {
|
||||||
|
// primary: themeColor.main,
|
||||||
|
// light: alpha(themeColor.main, themeMode === "light" ? 0.08 : 0.15),
|
||||||
|
// text: themeColor.main,
|
||||||
|
// };
|
||||||
|
}, [config.style?.palette, flow, themeMode, theme.palette]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardView
|
<Container
|
||||||
{...props}
|
sx={{
|
||||||
state={state}
|
mt: 4,
|
||||||
setState={setState}
|
mb: 4,
|
||||||
toggleFlow={toggleFlow}
|
background: `linear-gradient(180deg, ${colors.light} 0%, transparent 100%)`,
|
||||||
stateSetters={stateSetters}
|
borderRadius: 4,
|
||||||
/>
|
p: 2,
|
||||||
|
transition: "background 0.3s ease",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
mb: 3,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ToggleButtonGroup
|
||||||
|
value={flow}
|
||||||
|
exclusive
|
||||||
|
onChange={toggleFlow}
|
||||||
|
sx={{
|
||||||
|
borderRadius: 3,
|
||||||
|
overflow: "hidden",
|
||||||
|
"& .MuiToggleButton-root": {
|
||||||
|
px: 3,
|
||||||
|
textTransform: "none",
|
||||||
|
color: "text.secondary",
|
||||||
|
},
|
||||||
|
"&.Mui-selected": {
|
||||||
|
bgcolor: colors.primary,
|
||||||
|
color: "white",
|
||||||
|
borderColor: colors.primary,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ToggleButton value="outflows">Outflows</ToggleButton>
|
||||||
|
<ToggleButton value="inflows">Inflows</ToggleButton>
|
||||||
|
</ToggleButtonGroup>
|
||||||
|
|
||||||
|
{selectedGroupKey && Object.keys(selectedGroupKey).length > 0 && (
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
sx={{ mt: 1, textTransform: "none" }}
|
||||||
|
onClick={() => setSelectedGroupKey(null)}
|
||||||
|
>
|
||||||
|
Clear Drill-down
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Grid container spacing={4}>
|
||||||
|
{config.sections.map((section) => {
|
||||||
|
const Component = section.component;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid key={section.id} size={12}>
|
||||||
|
<Component
|
||||||
|
{...section}
|
||||||
|
|
||||||
|
reportData={data}
|
||||||
|
|
||||||
|
state={state}
|
||||||
|
stateSetters={stateSetters}
|
||||||
|
isFetching={isFetching}
|
||||||
|
|
||||||
|
colorScheme={colors}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Grid>
|
||||||
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,129 +0,0 @@
|
|||||||
import * as React from "react";
|
|
||||||
import {
|
|
||||||
Box,
|
|
||||||
Container,
|
|
||||||
Grid,
|
|
||||||
Typography,
|
|
||||||
ToggleButton,
|
|
||||||
ToggleButtonGroup,
|
|
||||||
Button
|
|
||||||
} from "@mui/material";
|
|
||||||
import { useTheme, alpha } from "@mui/material/styles";
|
|
||||||
import { GroupKey } from "../../features/report";
|
|
||||||
import { DashboardProps, DashboardState, DashboardStateSetters } from "./Dashboard.models";
|
|
||||||
|
|
||||||
interface ViewProps extends DashboardProps {
|
|
||||||
state: DashboardState;
|
|
||||||
setState: React.Dispatch<React.SetStateAction<DashboardState>>;
|
|
||||||
toggleFlow: (event: React.MouseEvent<HTMLElement>, newFlow: "outflows" | "inflows" | null) => void;
|
|
||||||
stateSetters: DashboardStateSetters;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function DashboardView({
|
|
||||||
config,
|
|
||||||
data,
|
|
||||||
state,
|
|
||||||
setState,
|
|
||||||
toggleFlow,
|
|
||||||
stateSetters,
|
|
||||||
}: ViewProps) {
|
|
||||||
const theme = useTheme();
|
|
||||||
const themeMode = theme.palette.mode;
|
|
||||||
const { flow, selectedGroupKey } = state;
|
|
||||||
const { setSelectedGroupKey } = stateSetters;
|
|
||||||
|
|
||||||
// Resolve colors with fallbacks
|
|
||||||
const colors = React.useMemo(() => {
|
|
||||||
const palette = config.style?.palette?.[flow];
|
|
||||||
const modeColors = palette ? palette[themeMode] : null;
|
|
||||||
|
|
||||||
if (modeColors) {
|
|
||||||
return {
|
|
||||||
primary: modeColors.primary,
|
|
||||||
light: modeColors.background || alpha(modeColors.primary, 0.1),
|
|
||||||
text: modeColors.text || (themeMode === 'light' ? theme.palette.text.primary : '#fff')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback to standard theme colors
|
|
||||||
const themeColor = flow === 'outflows' ? theme.palette.error : theme.palette.success;
|
|
||||||
return {
|
|
||||||
primary: themeColor.main,
|
|
||||||
light: alpha(themeColor.main, themeMode === 'light' ? 0.08 : 0.15),
|
|
||||||
text: themeColor.main
|
|
||||||
};
|
|
||||||
}, [config.style?.palette, flow, themeMode, theme.palette]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Container
|
|
||||||
sx={{
|
|
||||||
mt: 4,
|
|
||||||
mb: 4,
|
|
||||||
background: `linear-gradient(180deg, ${colors.light} 0%, transparent 100%)`,
|
|
||||||
borderRadius: 4,
|
|
||||||
p: 2,
|
|
||||||
transition: 'background 0.3s ease'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Box sx={{ display: "flex", flexDirection: "column", alignItems: "center", mb: 3 }}>
|
|
||||||
<ToggleButtonGroup
|
|
||||||
value={flow}
|
|
||||||
exclusive
|
|
||||||
onChange={toggleFlow}
|
|
||||||
sx={{
|
|
||||||
borderRadius: 3,
|
|
||||||
overflow: "hidden",
|
|
||||||
"& .MuiToggleButton-root": {
|
|
||||||
px: 3,
|
|
||||||
textTransform: "none",
|
|
||||||
color: "text.secondary"
|
|
||||||
},
|
|
||||||
"&.Mui-selected": {
|
|
||||||
bgcolor: colors.primary,
|
|
||||||
color: "white",
|
|
||||||
borderColor: colors.primary
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ToggleButton value="outflows">Outflows</ToggleButton>
|
|
||||||
<ToggleButton value="inflows">Inflows</ToggleButton>
|
|
||||||
</ToggleButtonGroup>
|
|
||||||
|
|
||||||
{selectedGroupKey && Object.keys(selectedGroupKey).length > 0 && (
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
sx={{ mt: 1, textTransform: "none" }}
|
|
||||||
onClick={() => setSelectedGroupKey(null)}
|
|
||||||
>
|
|
||||||
Clear Drill-down
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Grid container spacing={4}>
|
|
||||||
{config.sections.map((section) => {
|
|
||||||
const Component = section.component;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Grid key={section.id} size={section.style?.size || 12 as any}>
|
|
||||||
<Component
|
|
||||||
{...section.settings}
|
|
||||||
header={section.title}
|
|
||||||
summary={section.summary}
|
|
||||||
reportData={data}
|
|
||||||
title={section.title}
|
|
||||||
accentColor={colors.primary}
|
|
||||||
colorScheme={colors}
|
|
||||||
|
|
||||||
// State management
|
|
||||||
state={state}
|
|
||||||
stateSetters={stateSetters}
|
|
||||||
isFetching={arguments[0].isFetching}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Grid>
|
|
||||||
</Container>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import { ComponentProps } from "../report.props";
|
|
||||||
|
|
||||||
export interface _ChartDataPoint {
|
export interface _ChartDataPoint {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -10,7 +8,3 @@ export interface _ChartDataPoint {
|
|||||||
export interface ChartDataPoint extends _ChartDataPoint {
|
export interface ChartDataPoint extends _ChartDataPoint {
|
||||||
compare?: _ChartDataPoint;
|
compare?: _ChartDataPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HistoryChartProps extends ComponentProps {
|
|
||||||
tabs: string[];
|
|
||||||
}
|
|
||||||
|
|||||||
21
src/components/HistoryChart/HistoryChart.props.ts
Normal file
21
src/components/HistoryChart/HistoryChart.props.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { ComponentProps } from "../Dashboard";
|
||||||
|
import { ChartDataPoint } from "./HistoryChart.models";
|
||||||
|
|
||||||
|
export interface HistoryChartProps extends ComponentProps {
|
||||||
|
settings: {
|
||||||
|
tabs: string[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HistoryChartViewProps extends HistoryChartProps {
|
||||||
|
activeTab: string;
|
||||||
|
setActiveTab: (v: string) => void;
|
||||||
|
currentData: ChartDataPoint[];
|
||||||
|
visibleData: ChartDataPoint[];
|
||||||
|
maxAmount: number;
|
||||||
|
visibleCount: number;
|
||||||
|
startIndex: number;
|
||||||
|
setStartIndex: React.Dispatch<React.SetStateAction<number>>;
|
||||||
|
activeDataKey: string;
|
||||||
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { HistoryChartProps } from "./HistoryChart.models";
|
|
||||||
import HistoryChartView from "./HistoryChart.view";
|
import HistoryChartView from "./HistoryChart.view";
|
||||||
import { buildChartData, tabToKey } from "./HistoryChart.adapter";
|
import { buildChartData, tabToKey } from "./HistoryChart.adapter";
|
||||||
|
import { HistoryChartProps } from "./HistoryChart.props";
|
||||||
|
|
||||||
|
|
||||||
export default function HistoryChart(props: HistoryChartProps) {
|
export default function HistoryChart(props: HistoryChartProps) {
|
||||||
const {
|
const {
|
||||||
tabs,
|
settings,
|
||||||
reportData,
|
reportData,
|
||||||
state,
|
state,
|
||||||
stateSetters,
|
stateSetters,
|
||||||
|
|
||||||
|
isFetching,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const { flow, comparison, selectedPeriodId } = state;
|
const { flow, comparison, selectedPeriodId } = state;
|
||||||
const { setSelectedPeriodId } = stateSetters;
|
const { setSelectedPeriodId } = stateSetters;
|
||||||
|
const { tabs } = settings;
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = React.useState<string>(tabs[0] || "");
|
const [activeTab, setActiveTab] = React.useState<string>(tabs[0] || "");
|
||||||
const [startIndex, setStartIndex] = React.useState(0);
|
const [startIndex, setStartIndex] = React.useState(0);
|
||||||
|
|||||||
@@ -11,43 +11,31 @@ import IconButton from "@mui/material/IconButton";
|
|||||||
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
|
import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
|
||||||
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
|
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
|
||||||
import {
|
import {
|
||||||
ChartDataPoint,
|
HistoryChartViewProps,
|
||||||
HistoryChartProps,
|
} from "./HistoryChart.props";
|
||||||
} from "./HistoryChart.models";
|
|
||||||
import { formatDisplay } from "./HistoryChart.utils";
|
import { formatDisplay } from "./HistoryChart.utils";
|
||||||
|
|
||||||
interface ViewProps extends HistoryChartProps {
|
export default function HistoryChartView({
|
||||||
activeTab: string;
|
title,
|
||||||
setActiveTab: (v: string) => void;
|
summary,
|
||||||
currentData: ChartDataPoint[];
|
settings,
|
||||||
visibleData: ChartDataPoint[];
|
|
||||||
maxAmount: number;
|
|
||||||
visibleCount: number;
|
|
||||||
startIndex: number;
|
|
||||||
setStartIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
||||||
activeDataKey: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function HistoryChartView(props: ViewProps) {
|
state,
|
||||||
const {
|
stateSetters,
|
||||||
header,
|
isFetching,
|
||||||
summary,
|
|
||||||
tabs,
|
|
||||||
colorScheme,
|
|
||||||
|
|
||||||
state,
|
colorScheme,
|
||||||
stateSetters,
|
|
||||||
|
|
||||||
activeTab,
|
activeTab,
|
||||||
setActiveTab,
|
setActiveTab,
|
||||||
currentData,
|
currentData,
|
||||||
visibleData,
|
visibleData,
|
||||||
maxAmount,
|
maxAmount,
|
||||||
visibleCount,
|
visibleCount,
|
||||||
startIndex,
|
startIndex,
|
||||||
setStartIndex,
|
setStartIndex,
|
||||||
activeDataKey,
|
activeDataKey,
|
||||||
} = props;
|
}: HistoryChartViewProps) {
|
||||||
|
|
||||||
const { flow, periodType, selectedPeriodId, comparison } = state;
|
const { flow, periodType, selectedPeriodId, comparison } = state;
|
||||||
const { togglePeriodType, setSelectedPeriodId, toggleComparison } = stateSetters;
|
const { togglePeriodType, setSelectedPeriodId, toggleComparison } = stateSetters;
|
||||||
@@ -89,13 +77,13 @@ export default function HistoryChartView(props: ViewProps) {
|
|||||||
border: "1px solid",
|
border: "1px solid",
|
||||||
borderColor: "divider",
|
borderColor: "divider",
|
||||||
bgcolor: isDark ? "background.paper" : colorScheme.light,
|
bgcolor: isDark ? "background.paper" : colorScheme.light,
|
||||||
opacity: props.isFetching ? 0.6 : 1,
|
opacity: isFetching ? 0.6 : 1,
|
||||||
transition: "opacity 0.3s ease",
|
transition: "opacity 0.3s ease",
|
||||||
pointerEvents: props.isFetching ? "none" : "auto",
|
pointerEvents: isFetching ? "none" : "auto",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="h6" fontWeight={700} gutterBottom>
|
<Typography variant="h6" fontWeight={700} gutterBottom>
|
||||||
{header}
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
{summary && (
|
{summary && (
|
||||||
@@ -105,7 +93,7 @@ export default function HistoryChartView(props: ViewProps) {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<ToggleButtonGroup value={activeTab} exclusive onChange={handleTabChange} fullWidth sx={{ mb: 4 }}>
|
<ToggleButtonGroup value={activeTab} exclusive onChange={handleTabChange} fullWidth sx={{ mb: 4 }}>
|
||||||
{tabs.map((tab) => (
|
{settings.tabs.map((tab) => (
|
||||||
<ToggleButton key={tab} value={tab}>
|
<ToggleButton key={tab} value={tab}>
|
||||||
{tab}
|
{tab}
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
|
|||||||
14
src/components/ProgressCard/ProgressCard.props.ts
Normal file
14
src/components/ProgressCard/ProgressCard.props.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { ComponentProps } from "../Dashboard";
|
||||||
|
|
||||||
|
export interface ProgressCardProps extends ComponentProps {
|
||||||
|
settings: {
|
||||||
|
compact: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProgressCardViewProps extends ProgressCardProps {
|
||||||
|
progressAmount: number;
|
||||||
|
totalAmount: number;
|
||||||
|
selected: boolean;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import * as React from "react";
|
|
||||||
import ProgressCardView from "./ProgressCard.view";
|
|
||||||
import { ProgressCardProps } from "./ProgressCard.models";
|
|
||||||
import { getPercentage, formatCurrency } from "../report.helpers";
|
|
||||||
|
|
||||||
export default function ProgressCard(props: ProgressCardProps) {
|
|
||||||
const { progressAmount, totalAmount, compact = false } = props;
|
|
||||||
|
|
||||||
const percentage = getPercentage(progressAmount, totalAmount);
|
|
||||||
|
|
||||||
const formattedProgress = formatCurrency(progressAmount);
|
|
||||||
const formattedTotal = formatCurrency(totalAmount);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ProgressCardView
|
|
||||||
{...props}
|
|
||||||
percentage={percentage}
|
|
||||||
formattedProgress={formattedProgress}
|
|
||||||
formattedTotal={formattedTotal}
|
|
||||||
compact={compact}
|
|
||||||
selected={props.selected}
|
|
||||||
onClick={props.onClick}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -8,93 +8,83 @@ import {
|
|||||||
linearProgressClasses
|
linearProgressClasses
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { useTheme, alpha } from "@mui/material/styles";
|
import { useTheme, alpha } from "@mui/material/styles";
|
||||||
import { ProgressCardProps } from "./ProgressCard.models";
|
import { getPercentage, formatCurrency } from "../report.helpers";
|
||||||
|
import { ProgressCardViewProps } from "./ProgressCard.props";
|
||||||
interface ViewProps extends ProgressCardProps {
|
|
||||||
percentage: number;
|
|
||||||
formattedProgress: string;
|
|
||||||
formattedTotal: string;
|
|
||||||
selected?: boolean;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ProgressCardView({
|
export default function ProgressCardView({
|
||||||
header,
|
title,
|
||||||
colorTheme = "info",
|
settings,
|
||||||
percentage,
|
|
||||||
formattedProgress,
|
isFetching,
|
||||||
formattedTotal,
|
|
||||||
compact = false,
|
colorScheme,
|
||||||
|
|
||||||
|
progressAmount,
|
||||||
|
totalAmount,
|
||||||
selected,
|
selected,
|
||||||
onClick,
|
onClick,
|
||||||
}: ViewProps) {
|
}: ProgressCardViewProps) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isDark = theme.palette.mode === "dark";
|
const isDark = theme.palette.mode === "dark";
|
||||||
|
|
||||||
|
const percentage = getPercentage(progressAmount, totalAmount);
|
||||||
|
const formattedProgress = formatCurrency(progressAmount);
|
||||||
|
const formattedTotal = formatCurrency(totalAmount);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Paper
|
<Paper
|
||||||
elevation={compact ? 2 : 4}
|
elevation={settings.compact ? 2 : 4}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
sx={{
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
p: compact ? { xs: 2.5, md: 3 } : { xs: 3, md: 4 },
|
p: settings.compact ? { xs: 2.5, md: 3 } : { xs: 3, md: 4 },
|
||||||
borderRadius: compact ? 3 : 4,
|
borderRadius: settings.compact ? 3 : 4,
|
||||||
cursor: onClick ? "pointer" : "default",
|
|
||||||
transform: selected ? "scale(1.02)" : "scale(1)",
|
transform: selected ? "scale(1.02)" : "scale(1)",
|
||||||
transition: "transform 0.2s ease, box-shadow 0.2s ease",
|
transition: "transform 0.2s ease, box-shadow 0.2s ease",
|
||||||
background: (theme) => {
|
bgcolor: isDark ? "background.paper" : colorScheme.light,
|
||||||
const baseColor = theme.palette[colorTheme]?.main || theme.palette.primary.main;
|
|
||||||
const lightColor = theme.palette[colorTheme]?.light || theme.palette.primary.light;
|
|
||||||
return isDark
|
|
||||||
? `linear-gradient(135deg, ${alpha(baseColor, 0.9)} 0%, ${alpha(baseColor, 0.3)} 100%)`
|
|
||||||
: `linear-gradient(135deg, ${baseColor} 0%, ${lightColor} 100%)`;
|
|
||||||
},
|
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
alignItems: compact ? "flex-start" : "center",
|
alignItems: settings.compact ? "flex-start" : "center",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
position: "relative",
|
position: "relative",
|
||||||
overflow: "hidden",
|
overflow: "hidden",
|
||||||
border: selected
|
border: selected
|
||||||
? `2px solid #fff`
|
? `2px solid #fff`
|
||||||
: isDark ? "1px solid rgba(255,255,255,0.1)" : "none",
|
: isDark
|
||||||
boxShadow: (theme) => {
|
? "1px solid rgba(255,255,255,0.1)"
|
||||||
const baseShadow = `0 ${compact ? 6 : 12}px ${compact ? 12 : 24}px -10px ${
|
: "none",
|
||||||
isDark
|
boxShadow: "none",
|
||||||
? "rgba(0,0,0,0.5)"
|
opacity: isFetching ? 0.6 : 1,
|
||||||
: theme.palette[colorTheme]?.main || theme.palette.primary.main
|
pointerEvents: isFetching ? "none" : "auto",
|
||||||
}`;
|
|
||||||
return selected
|
|
||||||
? `${baseShadow}, 0 0 0 2px ${theme.palette.background.paper}, 0 0 0 4px ${theme.palette[colorTheme]?.main || theme.palette.primary.main}`
|
|
||||||
: baseShadow;
|
|
||||||
},
|
|
||||||
opacity: arguments[0].isFetching ? 0.6 : 1,
|
|
||||||
pointerEvents: arguments[0].isFetching ? "none" : "auto",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography
|
<Typography
|
||||||
variant={compact ? "body2" : "subtitle1"}
|
variant={settings.compact ? "body2" : "subtitle1"}
|
||||||
fontWeight={700}
|
fontWeight={700}
|
||||||
sx={{
|
sx={{
|
||||||
opacity: 0.95,
|
opacity: 0.95,
|
||||||
mb: compact ? 1.5 : 2,
|
mb: settings.compact ? 1.5 : 2,
|
||||||
width: '100%',
|
width: "100%",
|
||||||
overflow: 'hidden',
|
overflow: "hidden",
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: "ellipsis",
|
||||||
whiteSpace: 'nowrap',
|
whiteSpace: "nowrap",
|
||||||
letterSpacing: 0.5,
|
letterSpacing: 0.5,
|
||||||
textShadow: isDark ? '0 1px 2px rgba(0,0,0,0.3)' : 'none'
|
textShadow: isDark ? "0 1px 2px rgba(0,0,0,0.3)" : "none",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{header}
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Box sx={{ mb: compact ? 2 : 3, width: '100%' }}>
|
<Box sx={{ mb: settings.compact ? 2 : 3, width: "100%" }}>
|
||||||
<Typography
|
<Typography
|
||||||
variant={compact ? "h5" : "h3"}
|
variant={settings.compact ? "h5" : "h3"}
|
||||||
fontWeight={900}
|
fontWeight={900}
|
||||||
sx={{ mb: 0.5, lineHeight: 1.2, textShadow: isDark ? '0 2px 4px rgba(0,0,0,0.3)' : 'none' }}
|
sx={{
|
||||||
|
mb: 0.5,
|
||||||
|
lineHeight: 1.2,
|
||||||
|
textShadow: isDark ? "0 2px 4px rgba(0,0,0,0.3)" : "none",
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{formattedProgress}
|
{formattedProgress}
|
||||||
</Typography>
|
</Typography>
|
||||||
@@ -108,24 +98,24 @@ export default function ProgressCardView({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
variant={compact ? "caption" : "body2"}
|
variant={settings.compact ? "caption" : "body2"}
|
||||||
sx={{
|
sx={{
|
||||||
opacity: 0.85,
|
opacity: 0.85,
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
display: "block",
|
display: "block",
|
||||||
color: "rgba(255,255,255,0.9)"
|
color: "rgba(255,255,255,0.9)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
of {formattedTotal}
|
of {formattedTotal}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box sx={{ width: "100%", mt: 'auto' }}>
|
<Box sx={{ width: "100%", mt: "auto" }}>
|
||||||
<LinearProgress
|
<LinearProgress
|
||||||
variant="determinate"
|
variant="determinate"
|
||||||
value={percentage}
|
value={percentage}
|
||||||
sx={{
|
sx={{
|
||||||
height: compact ? 6 : 10,
|
height: settings.compact ? 6 : 10,
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
[`&.${linearProgressClasses.colorPrimary}`]: {
|
[`&.${linearProgressClasses.colorPrimary}`]: {
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.25)",
|
backgroundColor: "rgba(0, 0, 0, 0.25)",
|
||||||
@@ -133,7 +123,7 @@ export default function ProgressCardView({
|
|||||||
[`& .${linearProgressClasses.bar}`]: {
|
[`& .${linearProgressClasses.bar}`]: {
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
backgroundColor: "#fff",
|
backgroundColor: "#fff",
|
||||||
boxShadow: '0 0 8px rgba(255,255,255,0.4)'
|
boxShadow: "0 0 8px rgba(255,255,255,0.4)",
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Box, Paper, Typography } from "@mui/material";
|
import { Box, Paper, Typography } from "@mui/material";
|
||||||
import { ComponentProps } from "../report.props";
|
import ProgressCardView from "./ProgressCard.view";
|
||||||
import ProgressCard from "./ProgressCard";
|
|
||||||
import { extractTopPayees } from "./TopPayees.adapter";
|
import { extractTopPayees } from "./TopPayees.adapter";
|
||||||
|
import { ProgressCardProps } from "./ProgressCard.props";
|
||||||
|
|
||||||
interface Props extends ComponentProps {
|
export default function TopPayees(props: ProgressCardProps) {
|
||||||
compact?: boolean;
|
const {
|
||||||
}
|
title,
|
||||||
|
|
||||||
export default function TopPayees({
|
reportData,
|
||||||
reportData,
|
state,
|
||||||
state,
|
stateSetters,
|
||||||
stateSetters,
|
|
||||||
header,
|
isFetching,
|
||||||
compact = true,
|
} = props
|
||||||
isFetching,
|
|
||||||
}: Props) {
|
|
||||||
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
||||||
const { setSelectedGroupKey } = stateSetters;
|
const { setSelectedGroupKey } = stateSetters;
|
||||||
|
|
||||||
@@ -39,7 +37,7 @@ export default function TopPayees({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="h6" fontWeight={700} gutterBottom>
|
<Typography variant="h6" fontWeight={700} gutterBottom>
|
||||||
{header}
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
@@ -54,17 +52,15 @@ export default function TopPayees({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{items.map((item) => {
|
{items.map((item) => {
|
||||||
const isSelected = selectedGroupKey?.payee?.includes(item.name);
|
const isSelected = !!selectedGroupKey?.payee?.includes(item.name);
|
||||||
return (
|
return (
|
||||||
<ProgressCard
|
<ProgressCardView
|
||||||
|
{...props}
|
||||||
key={item.name}
|
key={item.name}
|
||||||
header={item.name}
|
title={item.name}
|
||||||
progressAmount={item.amount}
|
progressAmount={item.amount}
|
||||||
totalAmount={total}
|
totalAmount={total}
|
||||||
compact={compact}
|
|
||||||
colorTheme={flow === "outflows" ? "error" : "success"}
|
|
||||||
selected={isSelected}
|
selected={isSelected}
|
||||||
isFetching={isFetching}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (setSelectedGroupKey) {
|
if (setSelectedGroupKey) {
|
||||||
let newKey = selectedGroupKey ? { ...selectedGroupKey } : {};
|
let newKey = selectedGroupKey ? { ...selectedGroupKey } : {};
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Box, Paper, Typography } from "@mui/material";
|
import { Box, Paper, Typography } from "@mui/material";
|
||||||
import { ComponentProps } from "../report.props";
|
import ProgressCardView from "./ProgressCard.view";
|
||||||
import ProgressCard from "./ProgressCard";
|
|
||||||
import { extractTopTags } from "./TopTags.adapter";
|
import { extractTopTags } from "./TopTags.adapter";
|
||||||
|
import { ProgressCardProps } from "./ProgressCard.props";
|
||||||
|
|
||||||
interface Props extends ComponentProps {
|
export default function TopTags(props: ProgressCardProps) {
|
||||||
compact?: boolean;
|
const {
|
||||||
}
|
title,
|
||||||
|
|
||||||
export default function TopTags({
|
reportData,
|
||||||
reportData,
|
state,
|
||||||
state,
|
stateSetters,
|
||||||
stateSetters,
|
|
||||||
header,
|
isFetching,
|
||||||
compact = true,
|
} = props
|
||||||
isFetching,
|
|
||||||
}: Props) {
|
|
||||||
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
||||||
const { setSelectedGroupKey } = stateSetters;
|
const { setSelectedGroupKey } = stateSetters;
|
||||||
|
|
||||||
@@ -39,7 +37,7 @@ export default function TopTags({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography variant="h6" fontWeight={700} gutterBottom>
|
<Typography variant="h6" fontWeight={700} gutterBottom>
|
||||||
{header}
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
@@ -54,17 +52,15 @@ export default function TopTags({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{items.map((item) => {
|
{items.map((item) => {
|
||||||
const isSelected = selectedGroupKey?.tags?.includes(item.tag);
|
const isSelected = !!selectedGroupKey?.tags?.includes(item.tag);
|
||||||
return (
|
return (
|
||||||
<ProgressCard
|
<ProgressCardView
|
||||||
|
{...props}
|
||||||
key={item.tag}
|
key={item.tag}
|
||||||
header={item.tag}
|
title={item.tag}
|
||||||
progressAmount={item.amount}
|
progressAmount={item.amount}
|
||||||
totalAmount={total}
|
totalAmount={total}
|
||||||
compact={compact}
|
|
||||||
colorTheme={flow === "outflows" ? "error" : "success"}
|
|
||||||
selected={isSelected}
|
selected={isSelected}
|
||||||
isFetching={isFetching}
|
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (setSelectedGroupKey) {
|
if (setSelectedGroupKey) {
|
||||||
let newKey = selectedGroupKey ? { ...selectedGroupKey } : {};
|
let newKey = selectedGroupKey ? { ...selectedGroupKey } : {};
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
import { ReportData } from "../features/report";
|
|
||||||
import { DashboardState, DashboardStateSetters } from "./Dashboard";
|
|
||||||
|
|
||||||
export interface ComponentProps {
|
|
||||||
reportData: ReportData;
|
|
||||||
state: DashboardState;
|
|
||||||
stateSetters: DashboardStateSetters;
|
|
||||||
isFetching?: boolean;
|
|
||||||
header: string;
|
|
||||||
summary?: string;
|
|
||||||
accentColor?: string;
|
|
||||||
colorScheme?: {
|
|
||||||
primary: string;
|
|
||||||
light: string;
|
|
||||||
text: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -14,9 +14,6 @@ export const configuration: DashboardConfig = {
|
|||||||
settings: {
|
settings: {
|
||||||
tabs: ["Weekly", "Monthly"],
|
tabs: ["Weekly", "Monthly"],
|
||||||
},
|
},
|
||||||
style: {
|
|
||||||
size: 12,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "top-categories",
|
id: "top-categories",
|
||||||
@@ -25,9 +22,6 @@ export const configuration: DashboardConfig = {
|
|||||||
settings: {
|
settings: {
|
||||||
compact: true,
|
compact: true,
|
||||||
},
|
},
|
||||||
style: {
|
|
||||||
size: 12,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "top-payees",
|
id: "top-payees",
|
||||||
@@ -36,17 +30,11 @@ export const configuration: DashboardConfig = {
|
|||||||
settings: {
|
settings: {
|
||||||
compact: true,
|
compact: true,
|
||||||
},
|
},
|
||||||
style: {
|
|
||||||
size: 12,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "items",
|
id: "items",
|
||||||
title: 'Recent Transactions',
|
title: 'Recent Transactions',
|
||||||
component: LatestItems,
|
component: LatestItems,
|
||||||
style: {
|
|
||||||
size: 12,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
style: {
|
style: {
|
||||||
|
|||||||
Reference in New Issue
Block a user