Compare commits
2 Commits
0.0.1
...
16d164b92a
| Author | SHA1 | Date | |
|---|---|---|---|
| 16d164b92a | |||
| 8bea3d06f6 |
@@ -1,4 +1,4 @@
|
|||||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useMutation, useQueryClient, keepPreviousData } from "@tanstack/react-query";
|
||||||
import { api } from "../api/client";
|
import { api } from "../api/client";
|
||||||
import { ResourceConfig } from "../types/config";
|
import { ResourceConfig } from "../types/config";
|
||||||
import { ConfigContext } from "../providers/ConfigContext";
|
import { ConfigContext } from "../providers/ConfigContext";
|
||||||
@@ -26,6 +26,7 @@ export function useResource<T = any>(config: ResourceConfig | undefined) {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
enabled: !!endpoint,
|
enabled: !!endpoint,
|
||||||
|
placeholderData: keepPreviousData,
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- READ ONE ---
|
// --- READ ONE ---
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
|
||||||
import ConfigurableDashboard from "./components/Dashboard";
|
import ConfigurableDashboard from "./components/Dashboard";
|
||||||
|
import { DashboardState } from "./components/Dashboard";
|
||||||
import { configuration } from "./dashboard-config";
|
import { configuration } from "./dashboard-config";
|
||||||
import {
|
import {
|
||||||
useReport,
|
useReport,
|
||||||
@@ -18,6 +19,8 @@ import {
|
|||||||
} from "./features/report";
|
} from "./features/report";
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
|
const [flow, setFlow] = React.useState<"outflows" | "inflows">("outflows");
|
||||||
|
|
||||||
const [appliedPayees, setAppliedPayees] = React.useState<string[]>([]);
|
const [appliedPayees, setAppliedPayees] = React.useState<string[]>([]);
|
||||||
const [appliedTags, setAppliedTags] = React.useState<string[]>([]);
|
const [appliedTags, setAppliedTags] = React.useState<string[]>([]);
|
||||||
|
|
||||||
@@ -28,10 +31,8 @@ export default function Dashboard() {
|
|||||||
const [loadedTags, setLoadedTags] = React.useState<string[]>([]);
|
const [loadedTags, setLoadedTags] = React.useState<string[]>([]);
|
||||||
|
|
||||||
const report = useReport({
|
const report = useReport({
|
||||||
periods: ["weekly", "monthly", "full"],
|
periods: ["daily", "weekly", "monthly", "all"],
|
||||||
rolling: true,
|
flow: flow,
|
||||||
include_transactions: true,
|
|
||||||
group_by: ["tags"],
|
|
||||||
payee: appliedPayees.length > 0 ? appliedPayees : undefined,
|
payee: appliedPayees.length > 0 ? appliedPayees : undefined,
|
||||||
tags: appliedTags.length > 0 ? appliedTags : undefined,
|
tags: appliedTags.length > 0 ? appliedTags : undefined,
|
||||||
});
|
});
|
||||||
@@ -43,10 +44,7 @@ export default function Dashboard() {
|
|||||||
report.data.data.buckets.forEach((b: any) => {
|
report.data.data.buckets.forEach((b: any) => {
|
||||||
Object.values(b.periods).forEach((periodArray: any) => {
|
Object.values(b.periods).forEach((periodArray: any) => {
|
||||||
periodArray?.forEach((p: any) => {
|
periodArray?.forEach((p: any) => {
|
||||||
p.expenses?.transactions?.forEach((t: any) => {
|
p.metric?.transactions?.forEach((t: any) => {
|
||||||
if (t.payee?.name) pSet.add(t.payee.name);
|
|
||||||
});
|
|
||||||
p.incomes?.transactions?.forEach((t: any) => {
|
|
||||||
if (t.payee?.name) pSet.add(t.payee.name);
|
if (t.payee?.name) pSet.add(t.payee.name);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -60,10 +58,7 @@ export default function Dashboard() {
|
|||||||
report.data.data.buckets.forEach((b: any) => {
|
report.data.data.buckets.forEach((b: any) => {
|
||||||
Object.values(b.periods).forEach((periodArray: any) => {
|
Object.values(b.periods).forEach((periodArray: any) => {
|
||||||
periodArray?.forEach((p: any) => {
|
periodArray?.forEach((p: any) => {
|
||||||
p.expenses?.transactions?.forEach((t: any) => {
|
p.metric?.transactions?.forEach((t: any) => {
|
||||||
t.tags?.forEach((tag: any) => tSet.add(tag.name || tag));
|
|
||||||
});
|
|
||||||
p.incomes?.transactions?.forEach((t: any) => {
|
|
||||||
t.tags?.forEach((tag: any) => tSet.add(tag.name || tag));
|
t.tags?.forEach((tag: any) => tSet.add(tag.name || tag));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -77,6 +72,10 @@ export default function Dashboard() {
|
|||||||
const isLoading = report.isLoading;
|
const isLoading = report.isLoading;
|
||||||
const error = report.error;
|
const error = report.error;
|
||||||
|
|
||||||
|
/** Callback for the ConfigurableDashboard's flow toggle */
|
||||||
|
const handleFlowChange = React.useCallback((newState: DashboardState) => {
|
||||||
|
setFlow(newState.flow);
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (isLoading && !report.data) {
|
if (isLoading && !report.data) {
|
||||||
return (
|
return (
|
||||||
@@ -152,7 +151,7 @@ export default function Dashboard() {
|
|||||||
setAppliedTags(tagsInput);
|
setAppliedTags(tagsInput);
|
||||||
}}
|
}}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
sx={{ height: 40, borderRadius: 2 }} // Changed from 56 to 40 to match minHeight of inputs
|
sx={{ height: 40, borderRadius: 2 }}
|
||||||
>
|
>
|
||||||
Apply
|
Apply
|
||||||
</Button>
|
</Button>
|
||||||
@@ -161,6 +160,8 @@ export default function Dashboard() {
|
|||||||
<ConfigurableDashboard
|
<ConfigurableDashboard
|
||||||
config={configuration}
|
config={configuration}
|
||||||
data={data}
|
data={data}
|
||||||
|
isFetching={report.isFetching}
|
||||||
|
onFlowChange={handleFlowChange}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -4,35 +4,38 @@ import {
|
|||||||
GroupKey,
|
GroupKey,
|
||||||
} from "../../features/report";
|
} from "../../features/report";
|
||||||
|
|
||||||
export type DashboardMode = "expense" | "income";
|
export type DashboardFlow = "outflows" | "inflows";
|
||||||
export type DashboardPeriodType = "rolling" | "calendar";
|
export type DashboardPeriodType = "rolling" | "calendar";
|
||||||
export type DashboardSelectedPeriodId = string | null;
|
export type DashboardSelectedPeriodId = string | null;
|
||||||
|
|
||||||
export interface DashboardState {
|
export interface DashboardState {
|
||||||
mode: DashboardMode;
|
flow: DashboardFlow;
|
||||||
periodType: DashboardPeriodType;
|
periodType: DashboardPeriodType;
|
||||||
selectedPeriodId: DashboardSelectedPeriodId;
|
selectedPeriodId: DashboardSelectedPeriodId;
|
||||||
selectedGroupKey: GroupKey | null;
|
selectedGroupKey: GroupKey | null;
|
||||||
comparison: boolean;
|
comparison: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DashboardStateSetters {
|
||||||
|
setSelectedPeriodId: (id: DashboardSelectedPeriodId) => void;
|
||||||
|
setSelectedGroupKey: (groupKey: GroupKey | null) => void;
|
||||||
|
toggleFlow: () => void;
|
||||||
|
togglePeriodType: () => 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 {
|
||||||
@@ -42,12 +45,29 @@ export interface ThemeAwarePalette {
|
|||||||
|
|
||||||
export interface DashboardConfig {
|
export interface DashboardConfig {
|
||||||
sections: DashboardSection[];
|
sections: DashboardSection[];
|
||||||
style?: {
|
style: {
|
||||||
palette?: Record<DashboardMode, ThemeAwarePalette>;
|
palette: Record<DashboardFlow, ThemeAwarePalette>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DashboardProps {
|
export interface DashboardProps {
|
||||||
config: DashboardConfig;
|
config: DashboardConfig;
|
||||||
data: ReportData;
|
data: ReportData;
|
||||||
|
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,21 +1,62 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import DashboardView from "./Dashboard.view";
|
import {
|
||||||
import { DashboardProps, DashboardState } from "./Dashboard.models";
|
Box,
|
||||||
|
Container,
|
||||||
|
Grid,
|
||||||
|
ToggleButton,
|
||||||
|
ToggleButtonGroup,
|
||||||
|
Button
|
||||||
|
} from "@mui/material";
|
||||||
|
import { useTheme, alpha } from "@mui/material/styles";
|
||||||
|
import { DashboardProps, DashboardState, DashboardStateSetters, DashboardFlow } from "./Dashboard.models";
|
||||||
|
|
||||||
|
export default function Dashboard({
|
||||||
|
config,
|
||||||
|
data,
|
||||||
|
isFetching,
|
||||||
|
onFlowChange,
|
||||||
|
}: DashboardProps) {
|
||||||
|
const theme = useTheme();
|
||||||
|
const themeMode = theme.palette.mode;
|
||||||
|
|
||||||
export default function Dashboard(props: DashboardProps) {
|
|
||||||
const [state, setState] = React.useState<DashboardState>({
|
const [state, setState] = React.useState<DashboardState>({
|
||||||
mode: "expense",
|
flow: "outflows",
|
||||||
periodType: "rolling",
|
periodType: "rolling",
|
||||||
selectedPeriodId: null,
|
selectedPeriodId: null,
|
||||||
selectedGroupKey: null,
|
selectedGroupKey: null,
|
||||||
comparison: false,
|
comparison: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const toggleMode = () => {
|
const toggleFlow = () => {
|
||||||
setState(prev => ({
|
setState(prev => {
|
||||||
|
const nextFlow: DashboardFlow = prev.flow === "outflows" ? "inflows" : "outflows";
|
||||||
|
const nextState: DashboardState = {
|
||||||
...prev,
|
...prev,
|
||||||
mode: prev.mode === "expense" ? "income" : "expense",
|
flow: nextFlow,
|
||||||
}));
|
selectedGroupKey: null,
|
||||||
|
selectedPeriodId: null,
|
||||||
|
};
|
||||||
|
onFlowChange?.(nextState);
|
||||||
|
return nextState;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFlowChange = (
|
||||||
|
_event: React.MouseEvent<HTMLElement>,
|
||||||
|
newFlow: DashboardFlow | null
|
||||||
|
) => {
|
||||||
|
if (newFlow !== null && newFlow !== state.flow) {
|
||||||
|
setState(prev => {
|
||||||
|
const nextState: DashboardState = {
|
||||||
|
...prev,
|
||||||
|
flow: newFlow,
|
||||||
|
selectedGroupKey: null,
|
||||||
|
selectedPeriodId: null,
|
||||||
|
};
|
||||||
|
onFlowChange?.(nextState);
|
||||||
|
return nextState;
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const togglePeriodType = () => {
|
const togglePeriodType = () => {
|
||||||
@@ -40,16 +81,122 @@ export default function Dashboard(props: DashboardProps) {
|
|||||||
setState(prev => ({ ...prev, selectedGroupKey: groupKey }));
|
setState(prev => ({ ...prev, selectedGroupKey: groupKey }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const stateSetters: DashboardStateSetters = {
|
||||||
|
togglePeriodType,
|
||||||
|
toggleComparison,
|
||||||
|
toggleFlow,
|
||||||
|
setSelectedPeriodId,
|
||||||
|
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={{
|
||||||
|
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={handleFlowChange}
|
||||||
|
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}
|
state={state}
|
||||||
setState={setState}
|
stateSetters={stateSetters}
|
||||||
toggleMode={toggleMode}
|
isFetching={isFetching}
|
||||||
togglePeriodType={togglePeriodType}
|
|
||||||
toggleComparison={toggleComparison}
|
colorScheme={colors}
|
||||||
setSelectedPeriodId={setSelectedPeriodId}
|
|
||||||
setSelectedGroupKey={setSelectedGroupKey}
|
|
||||||
/>
|
/>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Grid>
|
||||||
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
import * as React from "react";
|
|
||||||
import {
|
|
||||||
Box,
|
|
||||||
Container,
|
|
||||||
Grid,
|
|
||||||
Typography,
|
|
||||||
ToggleButton,
|
|
||||||
ToggleButtonGroup
|
|
||||||
} from "@mui/material";
|
|
||||||
import { useTheme, alpha } from "@mui/material/styles";
|
|
||||||
import { GroupKey } from "../../features/report";
|
|
||||||
import { DashboardProps, DashboardState } from "./Dashboard.models";
|
|
||||||
|
|
||||||
interface ViewProps extends DashboardProps {
|
|
||||||
state: DashboardState;
|
|
||||||
setState: React.Dispatch<React.SetStateAction<DashboardState>>;
|
|
||||||
toggleMode: () => void;
|
|
||||||
togglePeriodType: () => void;
|
|
||||||
setSelectedPeriodId: (id: string | null) => void;
|
|
||||||
setSelectedGroupKey: (groupKey: GroupKey | null) => void;
|
|
||||||
toggleComparison: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function DashboardView({
|
|
||||||
config,
|
|
||||||
data,
|
|
||||||
state,
|
|
||||||
setState,
|
|
||||||
toggleMode,
|
|
||||||
togglePeriodType,
|
|
||||||
toggleComparison,
|
|
||||||
setSelectedPeriodId,
|
|
||||||
setSelectedGroupKey,
|
|
||||||
}: ViewProps) {
|
|
||||||
const theme = useTheme();
|
|
||||||
const themeMode = theme.palette.mode;
|
|
||||||
const { mode, periodType, comparison, selectedPeriodId, selectedGroupKey } = state;
|
|
||||||
|
|
||||||
// Resolve colors with fallbacks
|
|
||||||
const colors = React.useMemo(() => {
|
|
||||||
const palette = config.style?.palette?.[mode];
|
|
||||||
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 = mode === 'expense' ? 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, mode, 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", justifyContent: "center", mb: 3 }}>
|
|
||||||
<ToggleButtonGroup
|
|
||||||
value={mode}
|
|
||||||
exclusive
|
|
||||||
onChange={toggleMode}
|
|
||||||
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="expense">Expenses</ToggleButton>
|
|
||||||
<ToggleButton value="income">Income</ToggleButton>
|
|
||||||
</ToggleButtonGroup>
|
|
||||||
</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}>
|
|
||||||
{section.title && !section.isList && (
|
|
||||||
<Box sx={{ mb: 2 }}>
|
|
||||||
<Typography variant="h6" fontWeight={700}>
|
|
||||||
{section.title}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Component
|
|
||||||
{...section.settings}
|
|
||||||
header={section.title}
|
|
||||||
summary={section.summary}
|
|
||||||
reportData={data}
|
|
||||||
title={section.title}
|
|
||||||
accentColor={colors.primary}
|
|
||||||
colorScheme={colors}
|
|
||||||
|
|
||||||
// State management
|
|
||||||
mode={mode}
|
|
||||||
|
|
||||||
periodType={periodType}
|
|
||||||
comparison={comparison}
|
|
||||||
selectedPeriodId={selectedPeriodId}
|
|
||||||
selectedGroupKey={selectedGroupKey}
|
|
||||||
|
|
||||||
togglePeriodType={togglePeriodType}
|
|
||||||
toggleComparison={toggleComparison}
|
|
||||||
setSelectedPeriodId={setSelectedPeriodId}
|
|
||||||
setSelectedGroupKey={setSelectedGroupKey}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Grid>
|
|
||||||
</Container>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -9,15 +9,14 @@ import { ChartDataPoint } from "./HistoryChart.models";
|
|||||||
// ─── Tab → PeriodKey ─────────────────────────────────────────
|
// ─── Tab → PeriodKey ─────────────────────────────────────────
|
||||||
|
|
||||||
const TAB_TO_KEY: Record<string, PeriodKey> = {
|
const TAB_TO_KEY: Record<string, PeriodKey> = {
|
||||||
|
Daily: "daily",
|
||||||
Weekly: "weekly",
|
Weekly: "weekly",
|
||||||
Monthly: "monthly",
|
Monthly: "monthly",
|
||||||
Yearly: "yearly",
|
"All Time": "all",
|
||||||
"Financial Year": "fyly",
|
|
||||||
"All Time": "full",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function tabToKey(tab: string): PeriodKey {
|
export function tabToKey(tab: string): PeriodKey {
|
||||||
return TAB_TO_KEY[tab] ?? "full";
|
return TAB_TO_KEY[tab] ?? "all";
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Comparison ──────────────────────────────────────────────
|
// ─── Comparison ──────────────────────────────────────────────
|
||||||
@@ -27,10 +26,9 @@ function attachComparison(
|
|||||||
key: PeriodKey
|
key: PeriodKey
|
||||||
): ChartDataPoint[] {
|
): ChartDataPoint[] {
|
||||||
const getCompareIndex = (i: number) => {
|
const getCompareIndex = (i: number) => {
|
||||||
|
if (key === "daily") return i - 7;
|
||||||
if (key === "weekly") return i - 4;
|
if (key === "weekly") return i - 4;
|
||||||
if (key === "monthly") return i - 12;
|
if (key === "monthly") return i - 12;
|
||||||
if (key === "yearly") return i - 1;
|
|
||||||
if (key === "fyly") return i - 1;
|
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,7 +54,7 @@ function attachComparison(
|
|||||||
export function buildChartData(
|
export function buildChartData(
|
||||||
reportData: ReportData,
|
reportData: ReportData,
|
||||||
key: PeriodKey,
|
key: PeriodKey,
|
||||||
mode: "expense" | "income",
|
flow: "outflows" | "inflows",
|
||||||
comparison: boolean
|
comparison: boolean
|
||||||
): ChartDataPoint[] {
|
): ChartDataPoint[] {
|
||||||
const merged = mergeBucketPeriods(reportData.buckets, key);
|
const merged = mergeBucketPeriods(reportData.buckets, key);
|
||||||
@@ -64,7 +62,7 @@ export function buildChartData(
|
|||||||
let points: ChartDataPoint[] = merged.map((p) => ({
|
let points: ChartDataPoint[] = merged.map((p) => ({
|
||||||
id: p.id,
|
id: p.id,
|
||||||
label: p.label,
|
label: p.label,
|
||||||
amount: getAmount(p, mode),
|
amount: getAmount(p),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (comparison) {
|
if (comparison) {
|
||||||
|
|||||||
@@ -1,10 +1,3 @@
|
|||||||
import {
|
|
||||||
DashboardMode,
|
|
||||||
DashboardPeriodType,
|
|
||||||
DashboardSelectedPeriodId
|
|
||||||
} from "../Dashboard";
|
|
||||||
import { ReportData } from "../../features/report";
|
|
||||||
|
|
||||||
export interface _ChartDataPoint {
|
export interface _ChartDataPoint {
|
||||||
id: string;
|
id: string;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -15,26 +8,3 @@ export interface _ChartDataPoint {
|
|||||||
export interface ChartDataPoint extends _ChartDataPoint {
|
export interface ChartDataPoint extends _ChartDataPoint {
|
||||||
compare?: _ChartDataPoint;
|
compare?: _ChartDataPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HistoryChartProps {
|
|
||||||
header: string;
|
|
||||||
summary?: string;
|
|
||||||
tabs: string[];
|
|
||||||
|
|
||||||
reportData: ReportData;
|
|
||||||
|
|
||||||
colorScheme: {
|
|
||||||
primary: string;
|
|
||||||
light: string;
|
|
||||||
text: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
mode: DashboardMode;
|
|
||||||
periodType: DashboardPeriodType;
|
|
||||||
selectedPeriodId: DashboardSelectedPeriodId;
|
|
||||||
comparison: boolean;
|
|
||||||
|
|
||||||
togglePeriodType: () => void;
|
|
||||||
setSelectedPeriodId: (id: string | null) => void;
|
|
||||||
toggleComparison: () => void;
|
|
||||||
}
|
|
||||||
|
|||||||
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,26 +1,31 @@
|
|||||||
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,
|
||||||
mode,
|
state,
|
||||||
comparison,
|
stateSetters,
|
||||||
selectedPeriodId,
|
|
||||||
setSelectedPeriodId
|
isFetching,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const { flow, comparison, selectedPeriodId } = state;
|
||||||
|
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);
|
||||||
|
|
||||||
const activeDataKey = tabToKey(activeTab);
|
const activeDataKey = tabToKey(activeTab);
|
||||||
|
|
||||||
const currentData = React.useMemo(() => {
|
const currentData = React.useMemo(() => {
|
||||||
return buildChartData(reportData, activeDataKey, mode, comparison);
|
return buildChartData(reportData, activeDataKey, flow, comparison);
|
||||||
}, [reportData, activeDataKey, mode, comparison]);
|
}, [reportData, activeDataKey, flow, comparison]);
|
||||||
|
|
||||||
const maxAmount =
|
const maxAmount =
|
||||||
currentData.length > 0
|
currentData.length > 0
|
||||||
@@ -35,11 +40,10 @@ export default function HistoryChart(props: HistoryChartProps) {
|
|||||||
: 1;
|
: 1;
|
||||||
|
|
||||||
const visibleCountMap = {
|
const visibleCountMap = {
|
||||||
|
daily: 7,
|
||||||
weekly: 6,
|
weekly: 6,
|
||||||
monthly: 4,
|
monthly: 4,
|
||||||
yearly: 4,
|
all: 4,
|
||||||
fyly: 4,
|
|
||||||
full: 4,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const visibleCount = visibleCountMap[activeDataKey] ?? 4;
|
const visibleCount = visibleCountMap[activeDataKey] ?? 4;
|
||||||
|
|||||||
@@ -11,39 +11,21 @@ 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;
|
|
||||||
currentData: ChartDataPoint[];
|
|
||||||
visibleData: ChartDataPoint[];
|
|
||||||
maxAmount: number;
|
|
||||||
visibleCount: number;
|
|
||||||
startIndex: number;
|
|
||||||
setStartIndex: React.Dispatch<React.SetStateAction<number>>;
|
|
||||||
activeDataKey: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function HistoryChartView(props: ViewProps) {
|
|
||||||
const {
|
|
||||||
header,
|
|
||||||
summary,
|
summary,
|
||||||
tabs,
|
settings,
|
||||||
|
|
||||||
|
state,
|
||||||
|
stateSetters,
|
||||||
|
isFetching,
|
||||||
|
|
||||||
colorScheme,
|
colorScheme,
|
||||||
|
|
||||||
mode,
|
|
||||||
periodType,
|
|
||||||
selectedPeriodId,
|
|
||||||
comparison,
|
|
||||||
|
|
||||||
togglePeriodType,
|
|
||||||
setSelectedPeriodId,
|
|
||||||
toggleComparison,
|
|
||||||
|
|
||||||
activeTab,
|
activeTab,
|
||||||
setActiveTab,
|
setActiveTab,
|
||||||
currentData,
|
currentData,
|
||||||
@@ -53,7 +35,10 @@ export default function HistoryChartView(props: ViewProps) {
|
|||||||
startIndex,
|
startIndex,
|
||||||
setStartIndex,
|
setStartIndex,
|
||||||
activeDataKey,
|
activeDataKey,
|
||||||
} = props;
|
}: HistoryChartViewProps) {
|
||||||
|
|
||||||
|
const { flow, periodType, selectedPeriodId, comparison } = state;
|
||||||
|
const { togglePeriodType, setSelectedPeriodId, toggleComparison } = stateSetters;
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isDark = theme.palette.mode === "dark";
|
const isDark = theme.palette.mode === "dark";
|
||||||
@@ -92,10 +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: isFetching ? 0.6 : 1,
|
||||||
|
transition: "opacity 0.3s ease",
|
||||||
|
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>
|
||||||
|
|||||||
@@ -1,56 +1,21 @@
|
|||||||
import { ReportData, Transaction, GroupKey } from "../../features/report";
|
import { ReportData, GroupKey } from "../../features/report";
|
||||||
import {
|
import {
|
||||||
mergeBucketPeriods,
|
|
||||||
periodIdToKey,
|
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
filterBuckets,
|
extractFilteredTransactions,
|
||||||
} from "../report.helpers";
|
} from "../report.helpers";
|
||||||
import { LatestItem } from "./LatestItems.models";
|
import { LatestItem } from "./LatestItems.models";
|
||||||
|
|
||||||
// ─── Transaction extraction ─────────────────────────────────
|
|
||||||
|
|
||||||
function extractTransactions(
|
|
||||||
reportData: ReportData,
|
|
||||||
selectedPeriodId: string | null,
|
|
||||||
selectedGroupKey: GroupKey | null,
|
|
||||||
mode: "expense" | "income"
|
|
||||||
): Transaction[] {
|
|
||||||
const buckets = filterBuckets(reportData.buckets, selectedGroupKey);
|
|
||||||
if (selectedPeriodId) {
|
|
||||||
const key = periodIdToKey(selectedPeriodId);
|
|
||||||
const periods = mergeBucketPeriods(buckets, key);
|
|
||||||
const selected = periods.find((p) => p.id === selectedPeriodId);
|
|
||||||
|
|
||||||
if (!selected) return [];
|
|
||||||
|
|
||||||
return mode === "expense"
|
|
||||||
? (selected.expenses.transactions || [])
|
|
||||||
: (selected.incomes.transactions || []);
|
|
||||||
}
|
|
||||||
|
|
||||||
const periods = mergeBucketPeriods(buckets, "full");
|
|
||||||
|
|
||||||
if (!periods.length) return [];
|
|
||||||
|
|
||||||
const full = periods[0];
|
|
||||||
|
|
||||||
return mode === "expense"
|
|
||||||
? (full.expenses.transactions || [])
|
|
||||||
: (full.incomes.transactions || []);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Main adapter ────────────────────────────────────────────
|
// ─── Main adapter ────────────────────────────────────────────
|
||||||
|
|
||||||
export function buildLatestItems(
|
export function buildLatestItems(
|
||||||
reportData: ReportData,
|
reportData: ReportData,
|
||||||
selectedPeriodId: string | null,
|
selectedPeriodId: string | null | undefined,
|
||||||
selectedGroupKey: GroupKey | null,
|
selectedGroupKey: GroupKey | null | undefined,
|
||||||
mode: "expense" | "income"
|
flow: "outflows" | "inflows"
|
||||||
): LatestItem[] {
|
): LatestItem[] {
|
||||||
const txns = extractTransactions(reportData, selectedPeriodId, selectedGroupKey, mode);
|
const txns = extractFilteredTransactions(reportData, selectedPeriodId, selectedGroupKey);
|
||||||
|
|
||||||
return txns
|
return txns
|
||||||
.filter((t) => (mode === "expense" ? t.amount < 0 : t.amount >= 0))
|
|
||||||
.sort(
|
.sort(
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
new Date(b.occurred_at).getTime() -
|
new Date(b.occurred_at).getTime() -
|
||||||
|
|||||||
@@ -5,10 +5,3 @@ export interface LatestItem {
|
|||||||
amount: string;
|
amount: string;
|
||||||
timeAgo: string;
|
timeAgo: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LatestItemsViewProps {
|
|
||||||
items: LatestItem[];
|
|
||||||
accentColor: string;
|
|
||||||
canExpand: boolean;
|
|
||||||
onExpand: () => void;
|
|
||||||
}
|
|
||||||
|
|||||||
10
src/components/LatestItems/LatestItems.props.ts
Normal file
10
src/components/LatestItems/LatestItems.props.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { ComponentProps } from "../Dashboard";
|
||||||
|
import { LatestItem } from "./LatestItems.models";
|
||||||
|
|
||||||
|
export interface LatestItemsProps extends ComponentProps {}
|
||||||
|
|
||||||
|
export interface LatestItemsViewProps extends LatestItemsProps {
|
||||||
|
items: LatestItem[];
|
||||||
|
canExpand: boolean;
|
||||||
|
onExpand: () => void;
|
||||||
|
}
|
||||||
@@ -1,42 +1,38 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { ReportData, GroupKey } from "../../features/report";
|
|
||||||
import { buildLatestItems } from "./LatestItems.adapter";
|
import { buildLatestItems } from "./LatestItems.adapter";
|
||||||
import LatestItemsView from "./LatestItems.view";
|
import LatestItemsView from "./LatestItems.view";
|
||||||
|
import { LatestItemsProps } from "./LatestItems.props";
|
||||||
|
|
||||||
type Props = {
|
export default function LatestItems(props: LatestItemsProps) {
|
||||||
reportData: ReportData;
|
const {
|
||||||
mode: "expense" | "income";
|
|
||||||
selectedPeriodId: string | null;
|
|
||||||
selectedGroupKey?: GroupKey | null;
|
|
||||||
accentColor: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function LatestItems({
|
|
||||||
reportData,
|
reportData,
|
||||||
mode,
|
state,
|
||||||
selectedPeriodId,
|
stateSetters,
|
||||||
selectedGroupKey = null,
|
isFetching,
|
||||||
accentColor,
|
} = props;
|
||||||
}: Props) {
|
|
||||||
|
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
||||||
const [visibleCount, setVisibleCount] = React.useState(5);
|
const [visibleCount, setVisibleCount] = React.useState(5);
|
||||||
|
|
||||||
const allItems = React.useMemo(() => {
|
// Reset count when flow changes to start clean
|
||||||
return buildLatestItems(reportData, selectedPeriodId, selectedGroupKey, mode);
|
React.useEffect(() => {
|
||||||
}, [reportData, selectedPeriodId, selectedGroupKey, mode]);
|
setVisibleCount(5);
|
||||||
|
}, [flow]);
|
||||||
|
|
||||||
const hasSelection = Boolean(selectedPeriodId) || Boolean(selectedGroupKey);
|
const allItems = React.useMemo(() => {
|
||||||
|
return buildLatestItems(reportData, selectedPeriodId, selectedGroupKey, flow);
|
||||||
|
}, [reportData, selectedPeriodId, selectedGroupKey, flow]);
|
||||||
|
|
||||||
const visibleItems = React.useMemo(() => {
|
const visibleItems = React.useMemo(() => {
|
||||||
if (!hasSelection) return allItems.slice(0, 5);
|
|
||||||
return allItems.slice(0, visibleCount);
|
return allItems.slice(0, visibleCount);
|
||||||
}, [allItems, hasSelection, visibleCount]);
|
}, [allItems, visibleCount]);
|
||||||
|
|
||||||
const canExpand = hasSelection && visibleCount < allItems.length;
|
const canExpand = visibleCount < allItems.length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LatestItemsView
|
<LatestItemsView
|
||||||
|
{...props}
|
||||||
items={visibleItems}
|
items={visibleItems}
|
||||||
accentColor={accentColor}
|
|
||||||
canExpand={canExpand}
|
canExpand={canExpand}
|
||||||
onExpand={() => setVisibleCount((prev) => prev + 5)}
|
onExpand={() => setVisibleCount((prev) => prev + 5)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -10,19 +10,23 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
import { LatestItemsViewProps } from "./LatestItems.models";
|
import { LatestItemsViewProps } from "./LatestItems.props";
|
||||||
|
|
||||||
export default function LatestItemsView({
|
export default function LatestItemsView({
|
||||||
items,
|
items,
|
||||||
accentColor,
|
title,
|
||||||
canExpand,
|
canExpand,
|
||||||
onExpand,
|
onExpand,
|
||||||
|
isFetching,
|
||||||
|
colorScheme,
|
||||||
}: LatestItemsViewProps) {
|
}: LatestItemsViewProps) {
|
||||||
|
const accentColor = colorScheme?.primary || "";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box sx={{ width: "100%", bgcolor: "background.paper", borderRadius: 4, p: 2 }}>
|
<Box sx={{ width: "100%", bgcolor: "background.paper", borderRadius: 4, p: 2, opacity: isFetching ? 0.6 : 1, transition: "opacity 0.3s ease", pointerEvents: isFetching ? "none" : "auto" }}>
|
||||||
<Box sx={{ mb: 2, px: 2 }}>
|
<Box sx={{ mb: 2, px: 2 }}>
|
||||||
<Typography variant="h6" fontWeight="bold">
|
<Typography variant="h6" fontWeight="bold">
|
||||||
Recent Transactions
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
export interface ProgressCardProps {
|
|
||||||
header: string;
|
|
||||||
summary?: string;
|
|
||||||
progressAmount: number;
|
|
||||||
totalAmount: number;
|
|
||||||
colorTheme?: "primary" | "secondary" | "error" | "info" | "success" | "warning";
|
|
||||||
compact?: boolean;
|
|
||||||
selected?: boolean;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
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,91 +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: colorScheme.light,
|
||||||
const baseColor = theme.palette[colorTheme]?.main || theme.palette.primary.main;
|
color: colorScheme.text,
|
||||||
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",
|
|
||||||
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 ${colorScheme.primary}`
|
||||||
: 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 ${
|
: "1px solid rgba(0,0,0,0.06)",
|
||||||
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;
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<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>
|
||||||
@@ -100,38 +92,38 @@ export default function ProgressCardView({
|
|||||||
<Divider
|
<Divider
|
||||||
sx={{
|
sx={{
|
||||||
my: 1,
|
my: 1,
|
||||||
borderColor: "rgba(255,255,255,0.25)",
|
borderColor: isDark ? "rgba(255,255,255,0.15)" : "rgba(0,0,0,0.1)",
|
||||||
width: "100%",
|
width: "100%",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<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: alpha(colorScheme.text, 0.85),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
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: isDark ? "rgba(255, 255, 255, 0.12)" : "rgba(0, 0, 0, 0.08)",
|
||||||
},
|
},
|
||||||
[`& .${linearProgressClasses.bar}`]: {
|
[`& .${linearProgressClasses.bar}`]: {
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
backgroundColor: "#fff",
|
backgroundColor: colorScheme.primary,
|
||||||
boxShadow: '0 0 8px rgba(255,255,255,0.4)'
|
boxShadow: `0 0 8px ${alpha(colorScheme.primary, 0.4)}`,
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
31
src/components/ProgressCard/TopPayees.adapter.ts
Normal file
31
src/components/ProgressCard/TopPayees.adapter.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import { GroupKey, ReportData } from "../../features/report";
|
||||||
|
import {
|
||||||
|
extractFilteredTransactions,
|
||||||
|
aggregateTransactions,
|
||||||
|
} from "../report.helpers";
|
||||||
|
|
||||||
|
export interface PayeeItem {
|
||||||
|
name: string;
|
||||||
|
amount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractTopPayees(
|
||||||
|
reportData: ReportData,
|
||||||
|
flow: "outflows" | "inflows",
|
||||||
|
selectedPeriodId?: string | null,
|
||||||
|
selectedGroupKey?: GroupKey | null
|
||||||
|
): { items: PayeeItem[]; total: number } {
|
||||||
|
const txns = extractFilteredTransactions(reportData, selectedPeriodId, selectedGroupKey);
|
||||||
|
|
||||||
|
const { items, total } = aggregateTransactions(txns, (txn) => {
|
||||||
|
if (txn.payee && txn.payee.name) {
|
||||||
|
return [txn.payee.name];
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
items,
|
||||||
|
total,
|
||||||
|
};
|
||||||
|
}
|
||||||
83
src/components/ProgressCard/TopPayees.tsx
Normal file
83
src/components/ProgressCard/TopPayees.tsx
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { Box, Paper, Typography } from "@mui/material";
|
||||||
|
import ProgressCardView from "./ProgressCard.view";
|
||||||
|
import { extractTopPayees } from "./TopPayees.adapter";
|
||||||
|
import { ProgressCardProps } from "./ProgressCard.props";
|
||||||
|
|
||||||
|
export default function TopPayees(props: ProgressCardProps) {
|
||||||
|
const {
|
||||||
|
title,
|
||||||
|
|
||||||
|
reportData,
|
||||||
|
state,
|
||||||
|
stateSetters,
|
||||||
|
|
||||||
|
isFetching,
|
||||||
|
} = props
|
||||||
|
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
||||||
|
const { setSelectedGroupKey } = stateSetters;
|
||||||
|
|
||||||
|
const { items, total } = React.useMemo(() => {
|
||||||
|
return extractTopPayees(reportData, flow, selectedPeriodId, selectedGroupKey);
|
||||||
|
}, [reportData, flow, selectedPeriodId, selectedGroupKey]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Paper
|
||||||
|
sx={{
|
||||||
|
p: { xs: 2.5, sm: 4 },
|
||||||
|
borderRadius: 4,
|
||||||
|
width: "100%",
|
||||||
|
boxShadow: "none",
|
||||||
|
border: "1px solid",
|
||||||
|
borderColor: "divider",
|
||||||
|
bgcolor: "background.paper",
|
||||||
|
opacity: isFetching ? 0.6 : 1,
|
||||||
|
transition: "opacity 0.3s ease",
|
||||||
|
pointerEvents: isFetching ? "none" : "auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="h6" fontWeight={700} gutterBottom>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: {
|
||||||
|
xs: "1fr",
|
||||||
|
sm: "repeat(2, 1fr)",
|
||||||
|
md: "repeat(4, 1fr)",
|
||||||
|
},
|
||||||
|
gap: 2,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{items.map((item) => {
|
||||||
|
const isSelected = !!selectedGroupKey?.payee?.includes(item.name);
|
||||||
|
return (
|
||||||
|
<ProgressCardView
|
||||||
|
{...props}
|
||||||
|
key={item.name}
|
||||||
|
title={item.name}
|
||||||
|
progressAmount={item.amount}
|
||||||
|
totalAmount={total}
|
||||||
|
selected={isSelected}
|
||||||
|
onClick={() => {
|
||||||
|
if (setSelectedGroupKey) {
|
||||||
|
let newKey = selectedGroupKey ? { ...selectedGroupKey } : {};
|
||||||
|
|
||||||
|
if (isSelected) {
|
||||||
|
delete newKey.payee;
|
||||||
|
} else {
|
||||||
|
newKey.payee = [item.name];
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedGroupKey(Object.keys(newKey).length ? newKey : null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,32 +1,9 @@
|
|||||||
import { ReportData } from "../../features/report";
|
import { ReportData, GroupKey } from "../../features/report";
|
||||||
import {
|
import {
|
||||||
getAmount,
|
extractFilteredTransactions,
|
||||||
DecoratedPeriod,
|
aggregateTransactions,
|
||||||
} from "../report.helpers";
|
} from "../report.helpers";
|
||||||
|
|
||||||
// ─── Helpers ─────────────────────────────────────────────────
|
|
||||||
|
|
||||||
function findPeriod(
|
|
||||||
periods: DecoratedPeriod[],
|
|
||||||
selectedPeriodId?: string | null
|
|
||||||
) {
|
|
||||||
if (!periods.length) return null;
|
|
||||||
|
|
||||||
if (selectedPeriodId) {
|
|
||||||
const match = periods.find((p) => p.id === selectedPeriodId);
|
|
||||||
if (match) return match;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fallback → latest
|
|
||||||
return periods.reduce((latest, p) =>
|
|
||||||
new Date(p.start).getTime() > new Date(latest.start).getTime()
|
|
||||||
? p
|
|
||||||
: latest
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Main adapter ────────────────────────────────────────────
|
|
||||||
|
|
||||||
export interface TagItem {
|
export interface TagItem {
|
||||||
tag: string;
|
tag: string;
|
||||||
amount: number;
|
amount: number;
|
||||||
@@ -34,41 +11,21 @@ export interface TagItem {
|
|||||||
|
|
||||||
export function extractTopTags(
|
export function extractTopTags(
|
||||||
reportData: ReportData,
|
reportData: ReportData,
|
||||||
mode: "expense" | "income",
|
flow: "outflows" | "inflows",
|
||||||
selectedPeriodId?: string | null
|
selectedPeriodId?: string | null,
|
||||||
|
selectedGroupKey?: GroupKey | null
|
||||||
): { items: TagItem[]; total: number } {
|
): { items: TagItem[]; total: number } {
|
||||||
const tagMap = new Map<string, number>();
|
const txns = extractFilteredTransactions(reportData, selectedPeriodId, selectedGroupKey);
|
||||||
|
|
||||||
for (const bucket of reportData.buckets) {
|
const { items, total } = aggregateTransactions(txns, (txn) => {
|
||||||
const tags = bucket.group_key.tags;
|
if (txn.tags && txn.tags.length > 0) {
|
||||||
if (!tags || tags.length === 0) continue;
|
return txn.tags.map((t) => (typeof t === "string" ? t : t.name));
|
||||||
|
|
||||||
// Prefer FULL if available
|
|
||||||
const fullPeriods = (bucket.periods.full || []) as DecoratedPeriod[];
|
|
||||||
|
|
||||||
const periodsToUse = selectedPeriodId
|
|
||||||
? (Object.values(bucket.periods).flat() as DecoratedPeriod[])
|
|
||||||
: fullPeriods;
|
|
||||||
|
|
||||||
const period = findPeriod(periodsToUse, selectedPeriodId);
|
|
||||||
if (!period) continue;
|
|
||||||
|
|
||||||
const amount = getAmount(period, mode);
|
|
||||||
|
|
||||||
for (const tag of tags) {
|
|
||||||
tagMap.set(tag, (tagMap.get(tag) || 0) + amount);
|
|
||||||
}
|
}
|
||||||
}
|
return ["Untagged"];
|
||||||
|
});
|
||||||
const arr = Array.from(tagMap.entries()).map(([tag, amount]) => ({
|
|
||||||
tag,
|
return {
|
||||||
amount,
|
items: items.map((item) => ({ tag: item.name, amount: item.amount })),
|
||||||
}));
|
total,
|
||||||
|
};
|
||||||
arr.sort((a, b) => b.amount - a.amount);
|
|
||||||
|
|
||||||
const top = arr.slice(0, 4);
|
|
||||||
const total = top.reduce((sum, t) => sum + t.amount, 0);
|
|
||||||
|
|
||||||
return { items: top, total };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,45 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Box } from "@mui/material";
|
import { Box, Paper, Typography } from "@mui/material";
|
||||||
import { ReportData, GroupKey } from "../../features/report";
|
import ProgressCardView from "./ProgressCard.view";
|
||||||
import ProgressCard from "./ProgressCard";
|
|
||||||
import { extractTopTags } from "./TopTags.adapter";
|
import { extractTopTags } from "./TopTags.adapter";
|
||||||
|
import { ProgressCardProps } from "./ProgressCard.props";
|
||||||
|
|
||||||
type Props = {
|
export default function TopTags(props: ProgressCardProps) {
|
||||||
reportData: ReportData;
|
const {
|
||||||
mode: "expense" | "income";
|
title,
|
||||||
selectedPeriodId?: string | null;
|
|
||||||
selectedGroupKey?: GroupKey | null;
|
|
||||||
setSelectedGroupKey?: (key: GroupKey | null) => void;
|
|
||||||
compact?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function TopTags({
|
|
||||||
reportData,
|
reportData,
|
||||||
mode,
|
state,
|
||||||
selectedPeriodId,
|
stateSetters,
|
||||||
selectedGroupKey,
|
|
||||||
setSelectedGroupKey,
|
isFetching,
|
||||||
compact = true,
|
} = props
|
||||||
}: Props) {
|
const { flow, selectedPeriodId, selectedGroupKey } = state;
|
||||||
|
const { setSelectedGroupKey } = stateSetters;
|
||||||
|
|
||||||
const { items, total } = React.useMemo(() => {
|
const { items, total } = React.useMemo(() => {
|
||||||
return extractTopTags(reportData, mode, selectedPeriodId);
|
return extractTopTags(reportData, flow, selectedPeriodId, selectedGroupKey);
|
||||||
}, [reportData, mode, selectedPeriodId]);
|
}, [reportData, flow, selectedPeriodId, selectedGroupKey]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<Paper
|
||||||
|
sx={{
|
||||||
|
p: { xs: 2.5, sm: 4 },
|
||||||
|
borderRadius: 4,
|
||||||
|
width: "100%",
|
||||||
|
boxShadow: "none",
|
||||||
|
border: "1px solid",
|
||||||
|
borderColor: "divider",
|
||||||
|
bgcolor: "background.paper",
|
||||||
|
opacity: isFetching ? 0.6 : 1,
|
||||||
|
transition: "opacity 0.3s ease",
|
||||||
|
pointerEvents: isFetching ? "none" : "auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="h6" fontWeight={700} gutterBottom>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "grid",
|
display: "grid",
|
||||||
@@ -38,24 +52,32 @@ 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={mode === "expense" ? "error" : "success"}
|
|
||||||
selected={isSelected}
|
selected={isSelected}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (setSelectedGroupKey) {
|
if (setSelectedGroupKey) {
|
||||||
setSelectedGroupKey(isSelected ? null : { tags: [item.tag] });
|
let newKey = selectedGroupKey ? { ...selectedGroupKey } : {};
|
||||||
|
|
||||||
|
if (isSelected) {
|
||||||
|
delete newKey.tags;
|
||||||
|
} else {
|
||||||
|
newKey.tags = [item.tag];
|
||||||
|
}
|
||||||
|
|
||||||
|
setSelectedGroupKey(Object.keys(newKey).length ? newKey : null);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
export { default } from "./ProgressCard";
|
export { default } from "./ProgressCard.view";
|
||||||
export * from "./ProgressCard.models";
|
export * from "./ProgressCard.props";
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ import {
|
|||||||
ReportPeriod,
|
ReportPeriod,
|
||||||
ReportBucket,
|
ReportBucket,
|
||||||
GroupKey,
|
GroupKey,
|
||||||
|
PeriodType,
|
||||||
|
ReportData,
|
||||||
|
Transaction,
|
||||||
} from "../features/report";
|
} from "../features/report";
|
||||||
|
|
||||||
// ─── Types ────────────────────────────────────────────────────
|
// ─── Types ────────────────────────────────────────────────────
|
||||||
|
|
||||||
export type PeriodKey = "weekly" | "monthly" | "yearly" | "fyly" | "full";
|
export type PeriodKey = PeriodType;
|
||||||
|
|
||||||
export type DecoratedPeriod = ReportPeriod & {
|
export type DecoratedPeriod = ReportPeriod & {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -16,11 +19,10 @@ export type DecoratedPeriod = ReportPeriod & {
|
|||||||
// ─── Period helpers ───────────────────────────────────────────
|
// ─── Period helpers ───────────────────────────────────────────
|
||||||
|
|
||||||
const PREFIX_TO_KEY: Record<string, PeriodKey> = {
|
const PREFIX_TO_KEY: Record<string, PeriodKey> = {
|
||||||
|
D: "daily",
|
||||||
W: "weekly",
|
W: "weekly",
|
||||||
M: "monthly",
|
M: "monthly",
|
||||||
Y: "yearly",
|
ALL: "all",
|
||||||
FY: "fyly",
|
|
||||||
FULL: "full",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,19 +31,16 @@ const PREFIX_TO_KEY: Record<string, PeriodKey> = {
|
|||||||
*/
|
*/
|
||||||
export function periodIdToKey(periodId: string): PeriodKey {
|
export function periodIdToKey(periodId: string): PeriodKey {
|
||||||
const prefix = periodId.split(":")[0];
|
const prefix = periodId.split(":")[0];
|
||||||
return PREFIX_TO_KEY[prefix] ?? "full";
|
return PREFIX_TO_KEY[prefix] ?? "all";
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Metric helpers ───────────────────────────────────────────
|
// ─── Metric helpers ───────────────────────────────────────────
|
||||||
|
|
||||||
export function getAmount(
|
export function getAmount(period: ReportPeriod): number {
|
||||||
period: ReportPeriod,
|
return period.metric.sum;
|
||||||
mode: "expense" | "income"
|
|
||||||
): number {
|
|
||||||
return mode === "expense" ? period.expenses.sum : period.incomes.sum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeMetric(a: ReportPeriod["expenses"], b: ReportPeriod["expenses"]) {
|
function mergeMetric(a: ReportPeriod["metric"], b: ReportPeriod["metric"]) {
|
||||||
const sum = a.sum + b.sum;
|
const sum = a.sum + b.sum;
|
||||||
const count = a.count + b.count;
|
const count = a.count + b.count;
|
||||||
|
|
||||||
@@ -78,14 +77,12 @@ export function mergeBucketPeriods(
|
|||||||
if (!existing) {
|
if (!existing) {
|
||||||
map.set(p.id, {
|
map.set(p.id, {
|
||||||
...p,
|
...p,
|
||||||
expenses: { ...p.expenses },
|
metric: { ...p.metric },
|
||||||
incomes: { ...p.incomes },
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
map.set(p.id, {
|
map.set(p.id, {
|
||||||
...existing,
|
...existing,
|
||||||
expenses: mergeMetric(existing.expenses, p.expenses),
|
metric: mergeMetric(existing.metric, p.metric),
|
||||||
incomes: mergeMetric(existing.incomes, p.incomes),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,7 +123,7 @@ export function matchesGroupKey(
|
|||||||
selected: GroupKey
|
selected: GroupKey
|
||||||
): boolean {
|
): boolean {
|
||||||
for (const [dim, values] of Object.entries(selected)) {
|
for (const [dim, values] of Object.entries(selected)) {
|
||||||
const bucketValues = bucket.group_key[dim as keyof GroupKey];
|
const bucketValues = bucket.group_key[dim];
|
||||||
if (!bucketValues) return false;
|
if (!bucketValues) return false;
|
||||||
if (!(values as string[]).every((v) => bucketValues.includes(v)))
|
if (!(values as string[]).every((v) => bucketValues.includes(v)))
|
||||||
return false;
|
return false;
|
||||||
@@ -145,3 +142,89 @@ export function filterBuckets(
|
|||||||
if (!selectedGroupKey) return buckets;
|
if (!selectedGroupKey) return buckets;
|
||||||
return buckets.filter((b) => matchesGroupKey(b, selectedGroupKey));
|
return buckets.filter((b) => matchesGroupKey(b, selectedGroupKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function extractFilteredTransactions(
|
||||||
|
reportData: ReportData,
|
||||||
|
selectedPeriodId: string | null | undefined,
|
||||||
|
selectedGroupKey: GroupKey | null | undefined
|
||||||
|
): Transaction[] {
|
||||||
|
let txns: Transaction[] = [];
|
||||||
|
|
||||||
|
if (selectedPeriodId) {
|
||||||
|
const key = periodIdToKey(selectedPeriodId);
|
||||||
|
const periods = mergeBucketPeriods(reportData.buckets, key);
|
||||||
|
const selected = periods.find((p) => p.id === selectedPeriodId);
|
||||||
|
txns = selected?.metric.transactions || [];
|
||||||
|
} else {
|
||||||
|
const periods = mergeBucketPeriods(reportData.buckets, "all");
|
||||||
|
if (periods.length > 0) {
|
||||||
|
const period = periods.reduce((latest, p) =>
|
||||||
|
new Date(p.start).getTime() > new Date(latest.start).getTime()
|
||||||
|
? p
|
||||||
|
: latest
|
||||||
|
, periods[0]);
|
||||||
|
txns = period?.metric.transactions || [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedGroupKey) {
|
||||||
|
txns = txns.filter((txn) => {
|
||||||
|
let match = true;
|
||||||
|
if (selectedGroupKey.tags && selectedGroupKey.tags.length > 0) {
|
||||||
|
if (!txn.tags) {
|
||||||
|
match = false;
|
||||||
|
} else {
|
||||||
|
const txnTags = txn.tags.map((t: any) =>
|
||||||
|
typeof t === "string" ? t : t.name
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
!selectedGroupKey.tags.every((selectedTag) =>
|
||||||
|
txnTags.includes(selectedTag)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
match = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (match && selectedGroupKey.payee && selectedGroupKey.payee.length > 0) {
|
||||||
|
if (!txn.payee || !txn.payee.name) {
|
||||||
|
match = false;
|
||||||
|
} else {
|
||||||
|
if (!selectedGroupKey.payee.includes(txn.payee.name)) {
|
||||||
|
match = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return txns;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function aggregateTransactions(
|
||||||
|
transactions: Transaction[],
|
||||||
|
keyExtractor: (txn: Transaction) => string[],
|
||||||
|
limit = 4
|
||||||
|
): { items: { name: string; amount: number }[]; total: number } {
|
||||||
|
const map = new Map<string, number>();
|
||||||
|
|
||||||
|
for (const txn of transactions) {
|
||||||
|
const keys = keyExtractor(txn);
|
||||||
|
for (const key of keys) {
|
||||||
|
map.set(key, (map.get(key) || 0) + txn.amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = Array.from(map.entries()).map(([name, amount]) => ({
|
||||||
|
name,
|
||||||
|
amount,
|
||||||
|
}));
|
||||||
|
|
||||||
|
items.sort((a, b) => b.amount - a.amount);
|
||||||
|
|
||||||
|
const top = items.slice(0, limit);
|
||||||
|
const total = top.reduce((sum, item) => sum + item.amount, 0);
|
||||||
|
|
||||||
|
return { items: top, total };
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import HistoryChart from "./components/HistoryChart";
|
|||||||
import LatestItems from "./components/LatestItems";
|
import LatestItems from "./components/LatestItems";
|
||||||
import { DashboardConfig } from "./components/Dashboard";
|
import { DashboardConfig } from "./components/Dashboard";
|
||||||
import TopTags from "./components/ProgressCard/TopTags";
|
import TopTags from "./components/ProgressCard/TopTags";
|
||||||
|
import TopPayees from "./components/ProgressCard/TopPayees";
|
||||||
|
|
||||||
export const configuration: DashboardConfig = {
|
export const configuration: DashboardConfig = {
|
||||||
sections: [
|
sections: [
|
||||||
@@ -12,10 +13,6 @@ export const configuration: DashboardConfig = {
|
|||||||
component: HistoryChart,
|
component: HistoryChart,
|
||||||
settings: {
|
settings: {
|
||||||
tabs: ["Weekly", "Monthly"],
|
tabs: ["Weekly", "Monthly"],
|
||||||
// tabs: ["Weekly", "Monthly", "Yearly", "Financial Year", "All Time"],
|
|
||||||
},
|
|
||||||
style: {
|
|
||||||
size: 12,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -25,21 +22,24 @@ export const configuration: DashboardConfig = {
|
|||||||
settings: {
|
settings: {
|
||||||
compact: true,
|
compact: true,
|
||||||
},
|
},
|
||||||
style: {
|
},
|
||||||
size: 12,
|
{
|
||||||
|
id: "top-payees",
|
||||||
|
title: 'Top Payees',
|
||||||
|
component: TopPayees,
|
||||||
|
settings: {
|
||||||
|
compact: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "items",
|
id: "items",
|
||||||
|
title: 'Recent Transactions',
|
||||||
component: LatestItems,
|
component: LatestItems,
|
||||||
style: {
|
|
||||||
size: 12,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
style: {
|
style: {
|
||||||
palette: {
|
palette: {
|
||||||
expense: {
|
outflows: {
|
||||||
light: {
|
light: {
|
||||||
primary: "#d32f2f",
|
primary: "#d32f2f",
|
||||||
background: "#fdecea",
|
background: "#fdecea",
|
||||||
@@ -51,7 +51,7 @@ export const configuration: DashboardConfig = {
|
|||||||
text: "#ffcdd2"
|
text: "#ffcdd2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
income: {
|
inflows: {
|
||||||
light: {
|
light: {
|
||||||
primary: "#2e7d32",
|
primary: "#2e7d32",
|
||||||
background: "#e8f5e9",
|
background: "#e8f5e9",
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ export type {
|
|||||||
ReportData,
|
ReportData,
|
||||||
ReportBucket,
|
ReportBucket,
|
||||||
ReportPeriod,
|
ReportPeriod,
|
||||||
|
ReportQuery,
|
||||||
GroupKey,
|
GroupKey,
|
||||||
|
PeriodType,
|
||||||
} from './report.models'
|
} from './report.models'
|
||||||
export {
|
export {
|
||||||
prepareReport
|
prepareReport
|
||||||
|
|||||||
@@ -1,29 +1,40 @@
|
|||||||
export interface Payor {
|
export interface Payor {
|
||||||
|
id?: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
username: string;
|
||||||
|
email: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Payee {
|
export interface Payee {
|
||||||
|
type: "merchant" | "person" | "transfer" | "other";
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Account {
|
export interface Account {
|
||||||
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
number: string;
|
number: string;
|
||||||
|
type: "cash" | "bank" | "credit_card" | "wallet" | "other";
|
||||||
|
currency: string;
|
||||||
|
is_active?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Tag {
|
export interface Tag {
|
||||||
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
icon: string;
|
icon: string;
|
||||||
description: string;
|
parent_id?: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Transaction {
|
export interface Transaction {
|
||||||
|
id: string;
|
||||||
payor: Payor;
|
payor: Payor;
|
||||||
payee: Payee;
|
payee: Payee;
|
||||||
amount: number;
|
amount: number;
|
||||||
account: Account;
|
account: Account;
|
||||||
tags: Tag[];
|
tags: Tag[];
|
||||||
occurred_at: Date;
|
occurred_at: string;
|
||||||
|
created_at: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
@@ -41,12 +52,12 @@ export interface ReportMetric {
|
|||||||
// Period
|
// Period
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
export interface ReportPeriod {
|
export type PeriodType = "daily" | "weekly" | "monthly" | "all";
|
||||||
start: Date;
|
|
||||||
end: Date;
|
|
||||||
|
|
||||||
expenses: ReportMetric;
|
export interface ReportPeriod {
|
||||||
incomes: ReportMetric;
|
start: string;
|
||||||
|
end: string;
|
||||||
|
metric: ReportMetric;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
@@ -54,46 +65,48 @@ export interface ReportPeriod {
|
|||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
export type GroupKey = {
|
export type GroupKey = {
|
||||||
payee?: string[];
|
[dimension: string]: string[];
|
||||||
tags?: string[];
|
|
||||||
flow?: string[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface ReportBucket {
|
export interface ReportBucket {
|
||||||
group_key: GroupKey;
|
group_key: GroupKey;
|
||||||
|
|
||||||
periods: {
|
periods: {
|
||||||
|
daily?: ReportPeriod[];
|
||||||
weekly?: ReportPeriod[];
|
weekly?: ReportPeriod[];
|
||||||
monthly?: ReportPeriod[];
|
monthly?: ReportPeriod[];
|
||||||
yearly?: ReportPeriod[];
|
all?: ReportPeriod[];
|
||||||
fyly?: ReportPeriod[];
|
|
||||||
full?: ReportPeriod[];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// Report Query
|
||||||
|
// -----------------------------
|
||||||
|
|
||||||
|
export interface ReportQuery {
|
||||||
|
accounts?: string[] | null;
|
||||||
|
ignore_self?: boolean | null;
|
||||||
|
start_date?: string | null;
|
||||||
|
end_date?: string | null;
|
||||||
|
min_amount?: number | null;
|
||||||
|
max_amount?: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// Final Report
|
// Final Report
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
|
|
||||||
export interface ReportData {
|
export interface ReportData {
|
||||||
periods: ("weekly" | "monthly" | "yearly" | "fyly" | "full")[];
|
snapshot_id?: string | null;
|
||||||
|
|
||||||
rolling: boolean;
|
flow?: "inflows" | "outflows" | null;
|
||||||
report_date?: string;
|
|
||||||
|
|
||||||
group_by: ("payee" | "tags")[];
|
periods: PeriodType[];
|
||||||
|
|
||||||
ignore_self: boolean;
|
|
||||||
include_transactions: boolean;
|
|
||||||
|
|
||||||
start_date?: string | null;
|
|
||||||
end_date?: string | null;
|
|
||||||
flow?: "expense" | "income" | null;
|
|
||||||
payee?: string[] | null;
|
|
||||||
account?: string[] | null;
|
|
||||||
tags?: string[] | null;
|
tags?: string[] | null;
|
||||||
min_amount?: number | null;
|
payee?: string[] | null;
|
||||||
max_amount?: number | null;
|
|
||||||
|
|
||||||
buckets: ReportBucket[];
|
buckets: ReportBucket[];
|
||||||
|
|
||||||
|
query: ReportQuery;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
ReportData,
|
ReportData,
|
||||||
ReportPeriod
|
ReportPeriod,
|
||||||
|
PeriodType,
|
||||||
} from "./report.models";
|
} from "./report.models";
|
||||||
|
|
||||||
/* ---------- ID BUILDING ---------- */
|
/* ---------- ID BUILDING ---------- */
|
||||||
@@ -13,7 +14,7 @@ function formatDate(d: Date): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildPeriodId(
|
function buildPeriodId(
|
||||||
type: "weekly" | "monthly" | "yearly" | "fyly" | "full",
|
type: PeriodType,
|
||||||
start: Date,
|
start: Date,
|
||||||
end: Date
|
end: Date
|
||||||
): string {
|
): string {
|
||||||
@@ -21,16 +22,14 @@ function buildPeriodId(
|
|||||||
const e = formatDate(end);
|
const e = formatDate(end);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case "daily":
|
||||||
|
return `D:${s}_${e}`;
|
||||||
case "weekly":
|
case "weekly":
|
||||||
return `W:${s}_${e}`;
|
return `W:${s}_${e}`;
|
||||||
case "monthly":
|
case "monthly":
|
||||||
return `M:${s}_${e}`;
|
return `M:${s}_${e}`;
|
||||||
case "yearly":
|
case "all":
|
||||||
return `Y:${s}_${e}`;
|
return `ALL:${s}_${e}`;
|
||||||
case "fyly":
|
|
||||||
return `FY:${s}_${e}`;
|
|
||||||
case "full":
|
|
||||||
return `FULL:${s}_${e}`;
|
|
||||||
default:
|
default:
|
||||||
return `${s}_${e}`;
|
return `${s}_${e}`;
|
||||||
}
|
}
|
||||||
@@ -60,19 +59,15 @@ const yearFmt = new Intl.DateTimeFormat("en-GB", {
|
|||||||
timeZone: "UTC",
|
timeZone: "UTC",
|
||||||
});
|
});
|
||||||
|
|
||||||
function sameMonth(a: Date, b: Date) {
|
|
||||||
return (
|
|
||||||
a.getUTCFullYear() === b.getUTCFullYear() &&
|
|
||||||
a.getUTCMonth() === b.getUTCMonth()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildLabel(
|
function buildLabel(
|
||||||
type: "weekly" | "monthly" | "yearly" | "fyly" | "full",
|
type: PeriodType,
|
||||||
start: Date,
|
start: Date,
|
||||||
end: Date
|
end: Date
|
||||||
): string {
|
): string {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case "daily":
|
||||||
|
return dayFmt.format(start);
|
||||||
|
|
||||||
case "weekly": {
|
case "weekly": {
|
||||||
const sDay = start.getUTCDate();
|
const sDay = start.getUTCDate();
|
||||||
const m = monthFmt.format(start);
|
const m = monthFmt.format(start);
|
||||||
@@ -82,15 +77,6 @@ function buildLabel(
|
|||||||
case "monthly":
|
case "monthly":
|
||||||
return `${monthFmt.format(start)} ${yearFmt.format(start)}`;
|
return `${monthFmt.format(start)} ${yearFmt.format(start)}`;
|
||||||
|
|
||||||
case "yearly":
|
|
||||||
return yearFmt.format(start);
|
|
||||||
|
|
||||||
case "fyly": {
|
|
||||||
const startY = start.getUTCFullYear();
|
|
||||||
const endY = end.getUTCFullYear();
|
|
||||||
return `FY ${startY}–${String(endY).slice(-2)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return `${monthDayFmt.format(start)} - ${monthDayFmt.format(end)}`;
|
return `${monthDayFmt.format(start)} - ${monthDayFmt.format(end)}`;
|
||||||
}
|
}
|
||||||
@@ -99,7 +85,7 @@ function buildLabel(
|
|||||||
/* ---------- MAIN ---------- */
|
/* ---------- MAIN ---------- */
|
||||||
|
|
||||||
function decoratePeriods(
|
function decoratePeriods(
|
||||||
type: "weekly" | "monthly" | "yearly" | "fyly" | "full",
|
type: PeriodType,
|
||||||
periods: ReportPeriod[]
|
periods: ReportPeriod[]
|
||||||
): (ReportPeriod & { id: string; label: string })[] {
|
): (ReportPeriod & { id: string; label: string })[] {
|
||||||
return periods.map((p) => ({
|
return periods.map((p) => ({
|
||||||
|
|||||||
@@ -1,20 +1,11 @@
|
|||||||
import { useResourceByName } from "../../../react-openapi";
|
import { useResourceByName } from "../../../react-openapi";
|
||||||
|
|
||||||
export interface ReportParams {
|
export interface ReportParams {
|
||||||
periods?: ("weekly" | "monthly" | "yearly" | "fyly" | "full")[];
|
snapshot_id?: string;
|
||||||
rolling?: boolean;
|
periods?: ("daily" | "weekly" | "monthly" | "all")[];
|
||||||
report_date?: string;
|
flow?: "inflows" | "outflows";
|
||||||
group_by?: ("payee" | "tags")[];
|
|
||||||
ignore_self?: boolean;
|
|
||||||
include_transactions?: boolean;
|
|
||||||
start_date?: string;
|
|
||||||
end_date?: string;
|
|
||||||
flow?: "expense" | "income";
|
|
||||||
payee?: string[];
|
payee?: string[];
|
||||||
account?: string[];
|
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
min_amount?: number;
|
|
||||||
max_amount?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useReport(params: ReportParams) {
|
export function useReport(params: ReportParams) {
|
||||||
@@ -23,6 +14,5 @@ export function useReport(params: ReportParams) {
|
|||||||
return useList({
|
return useList({
|
||||||
...params,
|
...params,
|
||||||
periods: params.periods,
|
periods: params.periods,
|
||||||
group_by: params.group_by,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user