import * as React from "react"; import { Box, Container, CircularProgress, Alert, TextField, Paper, Autocomplete, Button } from "@mui/material"; import ConfigurableDashboard from "./components/Dashboard"; import { DashboardState } from "./components/Dashboard"; import { configuration } from "./dashboard-config"; import { useReport, prepareReport, } from "./features/report"; export default function Dashboard() { const [flow, setFlow] = React.useState<"outflows" | "inflows">("outflows"); const [appliedPayees, setAppliedPayees] = React.useState([]); const [appliedTags, setAppliedTags] = React.useState([]); const [payeeInput, setPayeeInput] = React.useState([]); const [tagsInput, setTagsInput] = React.useState([]); const [loadedPayees, setLoadedPayees] = React.useState([]); const [loadedTags, setLoadedTags] = React.useState([]); const report = useReport({ periods: ["daily", "weekly", "monthly", "all"], flow: flow, payee: appliedPayees.length > 0 ? appliedPayees : undefined, tags: appliedTags.length > 0 ? appliedTags : undefined, }); React.useEffect(() => { if (report.data?.data) { setLoadedPayees(prev => { const pSet = new Set(prev); report.data.data.buckets.forEach((b: any) => { Object.values(b.periods).forEach((periodArray: any) => { periodArray?.forEach((p: any) => { p.metric?.transactions?.forEach((t: any) => { if (t.payee?.name) pSet.add(t.payee.name); }); }); }); }); return Array.from(pSet).sort(); }); setLoadedTags(prev => { const tSet = new Set(prev); report.data.data.buckets.forEach((b: any) => { Object.values(b.periods).forEach((periodArray: any) => { periodArray?.forEach((p: any) => { p.metric?.transactions?.forEach((t: any) => { t.tags?.forEach((tag: any) => tSet.add(tag.name || tag)); }); }); }); }); return Array.from(tSet).sort(); }); } }, [report.data?.data]); const isLoading = report.isLoading; const error = report.error; /** Callback for the ConfigurableDashboard's flow toggle */ const handleFlowChange = React.useCallback((newState: DashboardState) => { setFlow(newState.flow); }, []); if (isLoading && !report.data) { return ( ); } if (error) { return ( {String(error)} ); } if (!report.data) { return null; } const data = prepareReport(report.data.data); return ( Filter by Payee setPayeeInput(val as string[])} renderInput={(params) => } sx={{ '& .MuiOutlinedInput-root': { height: 'auto', minHeight: '2.5rem', py: 0.5 } }} /> Filter by Tags setTagsInput(val as string[])} renderInput={(params) => } sx={{ '& .MuiOutlinedInput-root': { height: 'auto', minHeight: '2.5rem', py: 0.5 } }} /> ); }