## MR: Fetch Request Pipeline, Report Snapshots, and Admin Filtering
### Summary
Adds fetch request pipeline UI, report snapshot manager, snapshot selector on dashboard, and client-side in-memory filtering for the admin panel. Also overhauls the Home page with feature cards and adds navigation links.
### Changes
**New Pages**
- `/fetch-requests` — Upload bank statements (two-step: upload file, then configure source) or configure email ingestion. Table shows fingerprint (with copy), source type, account, status (color-coded chip), and created date.
- `/reports` — Generate cached report snapshots with filters (ignore self, date range, amount range). Table shows snapshot ID (with copy), creation time, and query summary chips.
**Dashboard**
- Snapshot selector autocomplete dropdown (formatted "Snapshot from {date}"), passes `snapshot_id` to `useReport`
- Styled to match other filter controls (caption above, auto-height)
**Admin — In-Memory Filtering**
- `FilterBar` component: collapsible, Dashboard-style column layout with caption + autocomplete/range/date inputs per filterable field
- `FilterAutocomplete` component: multi-select, free solo, checkmark ticks, selected-first sort frozen while dropdown open (prevents scroll reset)
- `applyClientFilters` in `ResourceView`: handles number range, datetime range, array (object/string elements), non-relation objects, boolean, primitive exact match
- Config-driven via `filterOptions: { mode: "client", fields: [...] }` in `openapi-config.ts`
- Mobile view: each filter takes full width (`flex: "0 0 100%"`), no horizontal squeeze
- `rowCount` omitted in client pagination mode (suppresses MUI X warning)
**Navigation & Home**
- Header nav links: Dashboard, Fetch, Reports
- Home page redesign: gradient hero, "Import Data" CTA, 4 feature cards (Dashboard, Fetch Requests, Report Snapshots, Admin) with accent-colored hover effects
**React-OpenAPI Library**
- `filterOptions` (mode + fields) on `ResourceOverride` and `ResourceConfig` types
- `EnhancedTable` mobile pagination (10 per page with Prev/Next, prevents browser hang with 10000 records)
- `useResource` accepts `filterOptions` from loader
**Misc**
- `public/favicon.png` added, proper `image/png` type in index.html
- 24 files changed, ~1541 insertions, ~100 deletions
### Files Changed (24)
| File | Change |
|------|--------|
| `src/FetchRequests.tsx` | +336 — new page |
| `src/ReportSnapshots.tsx` | +273 — new page |
| `src/features/fetch-requests/` | +96 — models, hooks, index |
| `src/features/report-snapshots/` | +40 — models, hooks, index |
| `src/Dashboard.tsx` | +58 — snapshot selector |
| `src/Home.tsx` | +224 — redesign with feature cards |
| `src/Header.tsx` | +26 — nav links |
| `src/main.jsx` | +4 — routes |
| `react-openapi/components/FilterBar.tsx` | +313 — new component |
| `react-openapi/components/ResourceView.tsx` | +151 — client filtering |
| `react-openapi/components/EnhancedTable.tsx` | +62 — mobile pagination |
| `react-openapi/types/config.ts` | +7 — filterOptions type |
| `react-openapi/types/overrides.ts` | +5 — filterOptions type |
| `react-openapi/utils/openapi_loader.ts` | +8 — load filterOptions |
| `react-openapi/hooks/useResource.ts` | +6 — filterOptions passthrough |
| `react-openapi/index.ts` | +3 — exports |
| `src/openapi-config.ts` | +15 — expenses config |
| `src/features/report/useReport.ts` | +13 — snapshot_id support |
| `index.html` | +1 — favicon link |
| `public/favicon.png` | +2910 bytes |
Reviewed-on: #7
Co-authored-by: Vishesh 'ironeagle' Bangotra <aetoskia@gmail.com>
Co-committed-by: Vishesh 'ironeagle' Bangotra <aetoskia@gmail.com>
165 lines
4.2 KiB
TypeScript
165 lines
4.2 KiB
TypeScript
import * as React from "react";
|
|
import {
|
|
useLocation,
|
|
matchPath
|
|
} from "react-router-dom";
|
|
import {
|
|
AppBar,
|
|
Toolbar,
|
|
Typography,
|
|
IconButton,
|
|
Tooltip,
|
|
Button,
|
|
Box,
|
|
useMediaQuery,
|
|
useTheme,
|
|
} from "@mui/material";
|
|
import MenuIcon from "@mui/icons-material/Menu";
|
|
import LogoutIcon from "@mui/icons-material/Logout";
|
|
import DarkModeIcon from "@mui/icons-material/DarkMode";
|
|
import LightModeIcon from "@mui/icons-material/LightMode";
|
|
import { useNavigate } from "react-router-dom";
|
|
import { useAuth } from "../react-auth";
|
|
import { ColorModeContext } from "./shared-theme/AppTheme";
|
|
|
|
interface HeaderProps {
|
|
routerMapping: {
|
|
path: string;
|
|
headerTitle: string;
|
|
}[];
|
|
onDrawerToggle?: () => void;
|
|
}
|
|
|
|
export default function Header({
|
|
routerMapping,
|
|
onDrawerToggle,
|
|
}: HeaderProps) {
|
|
const location = useLocation();
|
|
const matchedRoute = routerMapping.find((route) =>
|
|
matchPath({ path: route.path, end: false }, location.pathname)
|
|
);
|
|
const headerTitle = matchedRoute?.headerTitle ?? "Khata";
|
|
|
|
const navigate = useNavigate();
|
|
const { currentUser, logout } = useAuth();
|
|
const { mode, toggleColorMode } = React.useContext(ColorModeContext);
|
|
|
|
const theme = useTheme();
|
|
const isMobile = useMediaQuery(theme.breakpoints.down("md"));
|
|
|
|
const isAuthenticated = !!currentUser;
|
|
|
|
return (
|
|
<AppBar
|
|
position="fixed"
|
|
color="default"
|
|
sx={{
|
|
zIndex: (theme) => theme.zIndex.drawer + 1,
|
|
backdropFilter: "blur(8px)",
|
|
boxShadow: "none",
|
|
borderBottom: "1px solid",
|
|
borderColor: "divider",
|
|
}}
|
|
>
|
|
<Toolbar>
|
|
{/* MOBILE MENU BUTTON */}
|
|
{isMobile && onDrawerToggle && (
|
|
<IconButton
|
|
color="inherit"
|
|
edge="start"
|
|
onClick={onDrawerToggle}
|
|
sx={{ mr: 2 }}
|
|
>
|
|
<MenuIcon />
|
|
</IconButton>
|
|
)}
|
|
|
|
{/* THEME TOGGLE */}
|
|
<IconButton onClick={toggleColorMode} color="inherit" sx={{ mr: 2 }}>
|
|
{mode === 'dark' ? <LightModeIcon /> : <DarkModeIcon />}
|
|
</IconButton>
|
|
|
|
{/* TITLE */}
|
|
<Typography
|
|
variant="h6"
|
|
noWrap
|
|
sx={{ fontWeight: "bold", cursor: "pointer" }}
|
|
onClick={() => navigate("/")}
|
|
>
|
|
{headerTitle}
|
|
</Typography>
|
|
|
|
<span style={{ flexGrow: 1 }} />
|
|
|
|
{/* NAV LINKS */}
|
|
<Box
|
|
sx={{
|
|
display: { xs: "none", md: "flex" },
|
|
alignItems: "center",
|
|
mr: 2,
|
|
gap: 1,
|
|
}}
|
|
>
|
|
{[
|
|
{ label: "Dashboard", path: "/dashboard" },
|
|
{ label: "Fetch", path: "/fetch-requests" },
|
|
{ label: "Reports", path: "/reports" },
|
|
].map(({ label, path }) => (
|
|
<Button
|
|
key={path}
|
|
color="inherit"
|
|
onClick={() => navigate(path)}
|
|
sx={{ textTransform: "none", fontWeight: 500, px: 1.5 }}
|
|
size="small"
|
|
>
|
|
{label}
|
|
</Button>
|
|
))}
|
|
</Box>
|
|
|
|
{/* AUTH SECTION */}
|
|
{isAuthenticated ? (
|
|
<>
|
|
<Box
|
|
sx={{
|
|
display: { xs: "none", sm: "flex" },
|
|
alignItems: "center",
|
|
mr: 2,
|
|
}}
|
|
>
|
|
<Button
|
|
color="inherit"
|
|
onClick={() => navigate("/admin")}
|
|
sx={{ textTransform: "none", fontWeight: 500 }}
|
|
>
|
|
Admin
|
|
</Button>
|
|
<Button
|
|
color="inherit"
|
|
onClick={() => navigate("/admin/profile")}
|
|
sx={{ textTransform: "none", fontWeight: 500 }}
|
|
>
|
|
{currentUser.username}
|
|
</Button>
|
|
</Box>
|
|
|
|
<Tooltip title="Logout">
|
|
<IconButton color="inherit" onClick={logout}>
|
|
<LogoutIcon />
|
|
</IconButton>
|
|
</Tooltip>
|
|
</>
|
|
) : (
|
|
<Button
|
|
color="inherit"
|
|
variant="outlined"
|
|
onClick={() => navigate("/admin")}
|
|
sx={{ textTransform: "none" }}
|
|
>
|
|
Login
|
|
</Button>
|
|
)}
|
|
</Toolbar>
|
|
</AppBar>
|
|
);
|
|
} |