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