Fix BanTable to use props exclusively (complete dual state source refactoring)

- BanTable now requires all filter props (timeRange, origin, source)
- Removed useDashboardFilters() hook dependency from BanTable
- Eliminated context fallback chain using ?? operator
- Component now exclusively reads from props, never from context

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-04-23 09:26:45 +02:00
parent 814000fe68
commit 941502b710

View File

@@ -9,7 +9,6 @@
*/
import { memo, useMemo } from "react";
import { useDashboardFilters } from "../providers/DashboardFilterProvider";
import {
Badge,
Button,
@@ -42,16 +41,16 @@ interface BanTableProps {
* Active time-range preset — controlled by the parent `DashboardPage`.
* Changing this value triggers a re-fetch.
*/
timeRange?: TimeRange;
timeRange: TimeRange;
/**
* Active origin filter — controlled by the parent `DashboardPage`.
* Changing this value triggers a re-fetch and resets to page 1.
*/
origin?: BanOriginFilter;
origin: BanOriginFilter;
/**
* Data source used for the table query.
*/
source?: "fail2ban" | "archive";
source: "fail2ban" | "archive";
}
// ---------------------------------------------------------------------------
@@ -194,14 +193,10 @@ function buildBanColumns(styles: ReturnType<typeof useStyles>): TableColumnDefin
*/
export const BanTable = memo(function BanTable({ timeRange, origin, source }: BanTableProps): React.JSX.Element {
const styles = useStyles();
const context = useDashboardFilters();
const effectiveTimeRange = timeRange ?? context.timeRange;
const effectiveOrigin = origin ?? context.originFilter;
const effectiveSource = source ?? context.source;
const { banItems, total, page, setPage, loading, error, refresh } = useBans(
effectiveTimeRange,
effectiveOrigin,
effectiveSource,
timeRange,
origin,
source,
);
const banColumns = useMemo(() => buildBanColumns(styles), [styles]);