Filter movements by label

This commit is contained in:
Pierre HUBERT 2025-05-05 20:53:25 +02:00
parent 42f2014936
commit 485fe6ae53

View File

@ -6,6 +6,7 @@ import {
IconButton, IconButton,
ListItemIcon, ListItemIcon,
ListItemText, ListItemText,
TextField,
Tooltip, Tooltip,
Typography, Typography,
} from "@mui/material"; } from "@mui/material";
@ -110,6 +111,14 @@ function MovementsTable(p: {
const chooseAccount = useSelectAccount(); const chooseAccount = useSelectAccount();
const [labelFilter, setLabelFilter] = React.useState("");
const filteredList = React.useMemo(() => {
return p.movements.filter((m) =>
m.label.toLowerCase().includes(labelFilter.toLowerCase())
);
}, [p.movements, labelFilter]);
const [rowSelectionModel, setRowSelectionModel] = const [rowSelectionModel, setRowSelectionModel] =
React.useState<GridRowSelectionModel>([]); React.useState<GridRowSelectionModel>([]);
@ -362,7 +371,16 @@ function MovementsTable(p: {
return ( return (
<> <>
<div style={{ display: "flex", justifyContent: "end" }}> <div style={{ display: "flex" }}>
<TextField
placeholder="Filter by label"
variant="standard"
size="small"
value={labelFilter}
onChange={(e) => setLabelFilter(e.target.value)}
style={{ padding: "0px", flex: 1 }}
/>
<span style={{ flex: 1 }}></span>
<Tooltip title="Move all the selected entries to another account"> <Tooltip title="Move all the selected entries to another account">
<IconButton <IconButton
disabled={ disabled={
@ -389,7 +407,7 @@ function MovementsTable(p: {
<div style={{ flex: 1 }}> <div style={{ flex: 1 }}>
<DataGrid<Movement> <DataGrid<Movement>
columns={columns} columns={columns}
rows={p.movements} rows={filteredList}
autoPageSize autoPageSize
checkboxSelection checkboxSelection
initialState={{ initialState={{