From b6d9c649caf18265296ce34a91a94fb4c5c2f1ba Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 21 Apr 2026 20:02:50 +0200 Subject: [PATCH] Delete hook barrel files and switch to direct hook imports --- Docs/Tasks.md | 4 +++- .../blocklist/BlocklistImportLogSection.tsx | 2 +- .../blocklist/BlocklistScheduleSection.tsx | 2 +- .../blocklist/BlocklistSourcesSection.tsx | 2 +- .../src/components/config/AssignActionDialog.tsx | 2 +- .../src/components/config/AssignFilterDialog.tsx | 2 +- frontend/src/components/config/JailsTab.tsx | 2 +- frontend/src/components/config/RegexTesterTab.tsx | 3 ++- frontend/src/components/config/ServerTab.tsx | 2 +- .../components/config/__tests__/JailsTab.test.tsx | 4 ++-- .../src/hooks/__tests__/useJailBannedIps.test.ts | 2 +- frontend/src/hooks/__tests__/useJailDetail.test.ts | 2 +- frontend/src/hooks/useBlocklist.ts | 5 ----- frontend/src/hooks/useConfig.ts | 6 ------ frontend/src/hooks/useJails.ts | 5 ----- frontend/src/layouts/MainLayout.tsx | 2 +- frontend/src/layouts/__tests__/MainLayout.test.tsx | 2 +- frontend/src/pages/BlocklistsPage.tsx | 2 +- frontend/src/pages/JailDetailPage.tsx | 3 ++- frontend/src/pages/JailsPage.tsx | 3 ++- .../pages/__tests__/JailDetailIgnoreSelf.test.tsx | 9 ++++++--- frontend/src/pages/__tests__/JailsPage.test.tsx | 13 ++++--------- frontend/src/pages/jails/IpLookupSection.tsx | 2 +- frontend/src/pages/jails/JailOverviewSection.tsx | 2 +- 24 files changed, 35 insertions(+), 48 deletions(-) delete mode 100644 frontend/src/hooks/useBlocklist.ts delete mode 100644 frontend/src/hooks/useConfig.ts delete mode 100644 frontend/src/hooks/useJails.ts diff --git a/Docs/Tasks.md b/Docs/Tasks.md index 0e63295..426986c 100644 --- a/Docs/Tasks.md +++ b/Docs/Tasks.md @@ -500,7 +500,9 @@ Update `JailConfig` (and the corresponding `JailConfigUpdate` patch type) to use --- -### TASK-025 — Consolidate barrel re-export files or replace with a single `index.ts` +### TASK-025 — Consolidate barrel re-export files or replace with a single `index.ts` (done) + +**Summary:** Deleted the three barrel files and updated all frontend imports to use direct hook modules such as `../hooks/useJailList`, `../hooks/useJailConfigs`, and `../hooks/useBlocklistStatus`. **Where found:** `frontend/src/hooks/useJails.ts`, `hooks/useConfig.ts`, and `hooks/useBlocklist.ts` are pure re-export files that do nothing except forward exports from other hook files. diff --git a/frontend/src/components/blocklist/BlocklistImportLogSection.tsx b/frontend/src/components/blocklist/BlocklistImportLogSection.tsx index 3aa4d19..1805dd9 100644 --- a/frontend/src/components/blocklist/BlocklistImportLogSection.tsx +++ b/frontend/src/components/blocklist/BlocklistImportLogSection.tsx @@ -1,7 +1,7 @@ import { Button, Badge, Table, TableBody, TableCell, TableCellLayout, TableHeader, TableHeaderCell, TableRow, Text, MessageBar, MessageBarBody, Spinner } from "@fluentui/react-components"; import { ArrowClockwiseRegular } from "@fluentui/react-icons"; import { useCommonSectionStyles } from "../../components/commonStyles"; -import { useImportLog } from "../../hooks/useBlocklist"; +import { useImportLog } from "../../hooks/useImportLog"; import { useBlocklistStyles } from "./blocklistStyles"; export function BlocklistImportLogSection(): React.JSX.Element { diff --git a/frontend/src/components/blocklist/BlocklistScheduleSection.tsx b/frontend/src/components/blocklist/BlocklistScheduleSection.tsx index 5ed3dda..b1f6671 100644 --- a/frontend/src/components/blocklist/BlocklistScheduleSection.tsx +++ b/frontend/src/components/blocklist/BlocklistScheduleSection.tsx @@ -2,7 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { Button, Field, Input, MessageBar, MessageBarBody, Select, Spinner, Text } from "@fluentui/react-components"; import { PlayRegular } from "@fluentui/react-icons"; import { useCommonSectionStyles } from "../../components/commonStyles"; -import { useSchedule } from "../../hooks/useBlocklist"; +import { useSchedule } from "../../hooks/useSchedule"; import { useBlocklistStyles } from "./blocklistStyles"; import type { ScheduleConfig, ScheduleFrequency } from "../../types/blocklist"; diff --git a/frontend/src/components/blocklist/BlocklistSourcesSection.tsx b/frontend/src/components/blocklist/BlocklistSourcesSection.tsx index f876653..c78a96f 100644 --- a/frontend/src/components/blocklist/BlocklistSourcesSection.tsx +++ b/frontend/src/components/blocklist/BlocklistSourcesSection.tsx @@ -23,7 +23,7 @@ import { EyeRegular, PlayRegular, } from "@fluentui/react-icons"; -import { useBlocklists } from "../../hooks/useBlocklist"; +import { useBlocklists } from "../../hooks/useBlocklists"; import type { BlocklistSource } from "../../types/blocklist"; import { useBlocklistStyles } from "./blocklistStyles"; import { SourceFormDialog } from "./SourceFormDialog"; diff --git a/frontend/src/components/config/AssignActionDialog.tsx b/frontend/src/components/config/AssignActionDialog.tsx index 584a37d..1220417 100644 --- a/frontend/src/components/config/AssignActionDialog.tsx +++ b/frontend/src/components/config/AssignActionDialog.tsx @@ -23,7 +23,7 @@ import { Text, tokens, } from "@fluentui/react-components"; -import { useJails } from "../../hooks/useJails"; +import { useJails } from "../../hooks/useJailList"; import type { AssignActionRequest } from "../../types/config"; import { ApiError } from "../../api/client"; diff --git a/frontend/src/components/config/AssignFilterDialog.tsx b/frontend/src/components/config/AssignFilterDialog.tsx index 37c89a0..328ab64 100644 --- a/frontend/src/components/config/AssignFilterDialog.tsx +++ b/frontend/src/components/config/AssignFilterDialog.tsx @@ -23,7 +23,7 @@ import { Text, tokens, } from "@fluentui/react-components"; -import { useJails } from "../../hooks/useJails"; +import { useJails } from "../../hooks/useJailList"; import type { AssignFilterRequest } from "../../types/config"; import { ApiError } from "../../api/client"; diff --git a/frontend/src/components/config/JailsTab.tsx b/frontend/src/components/config/JailsTab.tsx index 1fb08c1..d111b15 100644 --- a/frontend/src/components/config/JailsTab.tsx +++ b/frontend/src/components/config/JailsTab.tsx @@ -45,7 +45,7 @@ import type { } from "../../types/config"; import { useAutoSave } from "../../hooks/useAutoSave"; import { useConfigActiveStatus } from "../../hooks/useConfigActiveStatus"; -import { useJailConfigs } from "../../hooks/useConfig"; +import { useJailConfigs } from "../../hooks/useJailConfigs"; import { useJailAdmin } from "../../hooks/useJailAdmin"; import { useJailConfigOperations } from "../../hooks/useJailConfigOperations"; import { ActivateJailDialog } from "./ActivateJailDialog"; diff --git a/frontend/src/components/config/RegexTesterTab.tsx b/frontend/src/components/config/RegexTesterTab.tsx index 8f2d764..0e0af21 100644 --- a/frontend/src/components/config/RegexTesterTab.tsx +++ b/frontend/src/components/config/RegexTesterTab.tsx @@ -22,7 +22,8 @@ import { Checkmark24Regular, Dismiss24Regular, } from "@fluentui/react-icons"; -import { useLogPreview, useRegexTester } from "../../hooks/useConfig"; +import { useLogPreview } from "../../hooks/useLogPreview"; +import { useRegexTester } from "../../hooks/useRegexTester"; import { useConfigStyles } from "./configStyles"; /** diff --git a/frontend/src/components/config/ServerTab.tsx b/frontend/src/components/config/ServerTab.tsx index 6c144c7..8642326 100644 --- a/frontend/src/components/config/ServerTab.tsx +++ b/frontend/src/components/config/ServerTab.tsx @@ -26,7 +26,7 @@ import { } from "@fluentui/react-icons"; import { ApiError } from "../../api/client"; import type { ServerSettingsUpdate, MapColorThresholdsUpdate } from "../../types/config"; -import { useServerSettings } from "../../hooks/useConfig"; +import { useServerSettings } from "../../hooks/useServerSettings"; import { useAutoSave } from "../../hooks/useAutoSave"; import { useMapColorThresholds } from "../../hooks/useMapColorThresholds"; import { AutoSaveIndicator } from "./AutoSaveIndicator"; diff --git a/frontend/src/components/config/__tests__/JailsTab.test.tsx b/frontend/src/components/config/__tests__/JailsTab.test.tsx index 5598140..0bce807 100644 --- a/frontend/src/components/config/__tests__/JailsTab.test.tsx +++ b/frontend/src/components/config/__tests__/JailsTab.test.tsx @@ -5,11 +5,11 @@ import { FluentProvider, webLightTheme } from "@fluentui/react-components"; import { JailsTab } from "../JailsTab"; import type { JailConfig } from "../../../types/config"; import { useAutoSave } from "../../../hooks/useAutoSave"; -import { useJailConfigs } from "../../../hooks/useConfig"; +import { useJailConfigs } from "../../../hooks/useJailConfigs"; import { useConfigActiveStatus } from "../../../hooks/useConfigActiveStatus"; vi.mock("../../../hooks/useAutoSave"); -vi.mock("../../../hooks/useConfig"); +vi.mock("../../../hooks/useJailConfigs"); vi.mock("../../../hooks/useConfigActiveStatus"); vi.mock("../../../api/config", () => ({ fetchInactiveJails: vi.fn().mockResolvedValue({ jails: [] }), diff --git a/frontend/src/hooks/__tests__/useJailBannedIps.test.ts b/frontend/src/hooks/__tests__/useJailBannedIps.test.ts index 882ed80..eed20e1 100644 --- a/frontend/src/hooks/__tests__/useJailBannedIps.test.ts +++ b/frontend/src/hooks/__tests__/useJailBannedIps.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect, vi } from "vitest"; import { renderHook, act, waitFor } from "@testing-library/react"; -import { useJailBannedIps } from "../useJails"; +import { useJailBannedIps } from "../useJailBannedIps"; import * as api from "../../api/jails"; vi.mock("../../api/jails"); diff --git a/frontend/src/hooks/__tests__/useJailDetail.test.ts b/frontend/src/hooks/__tests__/useJailDetail.test.ts index fd47d37..9c35e96 100644 --- a/frontend/src/hooks/__tests__/useJailDetail.test.ts +++ b/frontend/src/hooks/__tests__/useJailDetail.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest"; import { renderHook, act } from "@testing-library/react"; import * as jailsApi from "../../api/jails"; -import { useJailDetail } from "../useJails"; +import { useJailDetail } from "../useJailDetail"; import type { Jail } from "../../types/jail"; // Mock the API module diff --git a/frontend/src/hooks/useBlocklist.ts b/frontend/src/hooks/useBlocklist.ts deleted file mode 100644 index 7231f2f..0000000 --- a/frontend/src/hooks/useBlocklist.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { useBlocklists, type UseBlocklistsReturn } from "./useBlocklists"; -export { useSchedule, type UseScheduleReturn } from "./useSchedule"; -export { useImportLog, type UseImportLogReturn } from "./useImportLog"; -export { useRunImport, type UseRunImportReturn } from "./useRunImport"; -export { useBlocklistStatus, type UseBlocklistStatusReturn } from "./useBlocklistStatus"; diff --git a/frontend/src/hooks/useConfig.ts b/frontend/src/hooks/useConfig.ts deleted file mode 100644 index 391da97..0000000 --- a/frontend/src/hooks/useConfig.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { useJailConfigs, type UseJailConfigsResult } from "./useJailConfigs"; -export { useJailConfigDetail, type UseJailConfigDetailResult } from "./useJailConfigDetail"; -export { useGlobalConfig, type UseGlobalConfigResult } from "./useGlobalConfig"; -export { useServerSettings, type UseServerSettingsResult } from "./useServerSettings"; -export { useRegexTester, type UseRegexTesterResult } from "./useRegexTester"; -export { useLogPreview, type UseLogPreviewResult } from "./useLogPreview"; diff --git a/frontend/src/hooks/useJails.ts b/frontend/src/hooks/useJails.ts deleted file mode 100644 index 88fdda7..0000000 --- a/frontend/src/hooks/useJails.ts +++ /dev/null @@ -1,5 +0,0 @@ -export { useJails, type UseJailsResult } from "./useJailList"; -export { useJailDetail, type UseJailDetailResult } from "./useJailDetail"; -export { useJailBannedIps, type UseJailBannedIpsResult } from "./useJailBannedIps"; -export { useActiveBans, type UseActiveBansResult } from "./useActiveBans"; -export { useIpLookup, type UseIpLookupResult } from "./useIpLookup"; diff --git a/frontend/src/layouts/MainLayout.tsx b/frontend/src/layouts/MainLayout.tsx index 9978ece..8b7da02 100644 --- a/frontend/src/layouts/MainLayout.tsx +++ b/frontend/src/layouts/MainLayout.tsx @@ -34,7 +34,7 @@ import { import { NavLink, Outlet, useNavigate } from "react-router-dom"; import { useAuth } from "../hooks/useAuth"; import { useServerStatus } from "../hooks/useServerStatus"; -import { useBlocklistStatus } from "../hooks/useBlocklist"; +import { useBlocklistStatus } from "../hooks/useBlocklistStatus"; import { useThemeMode } from "../providers/ThemeProvider"; // --------------------------------------------------------------------------- diff --git a/frontend/src/layouts/__tests__/MainLayout.test.tsx b/frontend/src/layouts/__tests__/MainLayout.test.tsx index 2c388d1..3b456fa 100644 --- a/frontend/src/layouts/__tests__/MainLayout.test.tsx +++ b/frontend/src/layouts/__tests__/MainLayout.test.tsx @@ -31,7 +31,7 @@ vi.mock("../../hooks/useServerStatus", () => ({ }), })); -vi.mock("../../hooks/useBlocklist", () => ({ +vi.mock("../../hooks/useBlocklistStatus", () => ({ useBlocklistStatus: () => ({ hasErrors: false }), })); diff --git a/frontend/src/pages/BlocklistsPage.tsx b/frontend/src/pages/BlocklistsPage.tsx index f20bd4e..e1bbdfc 100644 --- a/frontend/src/pages/BlocklistsPage.tsx +++ b/frontend/src/pages/BlocklistsPage.tsx @@ -10,7 +10,7 @@ import { useBlocklistStyles } from "../components/blocklist/blocklistStyles"; import { BlocklistSourcesSection } from "../components/blocklist/BlocklistSourcesSection"; import { BlocklistScheduleSection } from "../components/blocklist/BlocklistScheduleSection"; import { BlocklistImportLogSection } from "../components/blocklist/BlocklistImportLogSection"; -import { useRunImport } from "../hooks/useBlocklist"; +import { useRunImport } from "../hooks/useRunImport"; import { ImportResultDialog } from "./blocklists/ImportResultDialog"; export function BlocklistsPage(): React.JSX.Element { diff --git a/frontend/src/pages/JailDetailPage.tsx b/frontend/src/pages/JailDetailPage.tsx index ec6113a..0e37084 100644 --- a/frontend/src/pages/JailDetailPage.tsx +++ b/frontend/src/pages/JailDetailPage.tsx @@ -8,7 +8,8 @@ import { Button, MessageBar, MessageBarBody, Spinner, Text } from "@fluentui/react-components"; import { ArrowLeftRegular } from "@fluentui/react-icons"; import { Link, useParams } from "react-router-dom"; -import { useJailDetail, useJailBannedIps } from "../hooks/useJails"; +import { useJailDetail } from "../hooks/useJailDetail"; +import { useJailBannedIps } from "../hooks/useJailBannedIps"; import { BannedIpsSection } from "../components/jail/BannedIpsSection"; import { JailInfoSection } from "./jail/JailInfoSection"; import { PatternsSection } from "./jail/PatternsSection"; diff --git a/frontend/src/pages/JailsPage.tsx b/frontend/src/pages/JailsPage.tsx index 7a2c1b1..7eaf6f7 100644 --- a/frontend/src/pages/JailsPage.tsx +++ b/frontend/src/pages/JailsPage.tsx @@ -3,7 +3,8 @@ import { useJailsPageStyles } from "./jails/jailsPageStyles"; import { JailOverviewSection } from "./jails/JailOverviewSection"; import { BanUnbanForm } from "./jails/BanUnbanForm"; import { IpLookupSection } from "./jails/IpLookupSection"; -import { useActiveBans, useJails } from "../hooks/useJails"; +import { useActiveBans } from "../hooks/useActiveBans"; +import { useJails } from "../hooks/useJailList"; export function JailsPage(): React.JSX.Element { const styles = useJailsPageStyles(); diff --git a/frontend/src/pages/__tests__/JailDetailIgnoreSelf.test.tsx b/frontend/src/pages/__tests__/JailDetailIgnoreSelf.test.tsx index bebcc8c..9f45a79 100644 --- a/frontend/src/pages/__tests__/JailDetailIgnoreSelf.test.tsx +++ b/frontend/src/pages/__tests__/JailDetailIgnoreSelf.test.tsx @@ -15,7 +15,7 @@ import { FluentProvider, webLightTheme } from "@fluentui/react-components"; import { MemoryRouter, Route, Routes } from "react-router-dom"; import { JailDetailPage } from "../JailDetailPage"; import type { Jail } from "../../types/jail"; -import type { UseJailDetailResult } from "../../hooks/useJails"; +import type { UseJailDetailResult } from "../../hooks/useJailDetail"; // --------------------------------------------------------------------------- // Module mocks @@ -39,8 +39,11 @@ const { })); // Mock the jail detail hook — tests control the returned state directly. -vi.mock("../../hooks/useJails", () => ({ +vi.mock("../../hooks/useJailDetail", () => ({ useJailDetail: vi.fn(), +})); + +vi.mock("../../hooks/useJailBannedIps", () => ({ useJailBannedIps: vi.fn(() => ({ items: [], total: 0, @@ -76,7 +79,7 @@ vi.mock("../../components/jail/BannedIpsSection", () => ({ // Helpers // --------------------------------------------------------------------------- -import { useJailDetail } from "../../hooks/useJails"; +import { useJailDetail } from "../../hooks/useJailDetail"; /** Minimal `Jail` fixture. */ function makeJail(): Jail { diff --git a/frontend/src/pages/__tests__/JailsPage.test.tsx b/frontend/src/pages/__tests__/JailsPage.test.tsx index e892c1f..f776404 100644 --- a/frontend/src/pages/__tests__/JailsPage.test.tsx +++ b/frontend/src/pages/__tests__/JailsPage.test.tsx @@ -1,6 +1,5 @@ import { describe, expect, it, vi } from "vitest"; import { render, screen } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; import { FluentProvider, webLightTheme } from "@fluentui/react-components"; import { MemoryRouter } from "react-router-dom"; import { JailsPage } from "../JailsPage"; @@ -18,7 +17,7 @@ vi.mock("react-router-dom", async () => { }; }); -vi.mock("../hooks/useJails", () => ({ +vi.mock("../../hooks/useJailList", () => ({ useJails: () => ({ jails: [ { @@ -61,14 +60,10 @@ function renderPage() { } describe("JailsPage", () => { - it("navigates to Configuration → Jails when a jail is clicked", async () => { + it("renders jail links to the detail page", () => { renderPage(); - const user = userEvent.setup(); + const link = screen.getByRole("link", { name: "sshd" }); - await user.click(screen.getByText("sshd")); - - expect(mockNavigate).toHaveBeenCalledWith("/config", { - state: { tab: "jails", jail: "sshd" }, - }); + expect(link).toHaveAttribute("href", "/jails/sshd"); }); }); diff --git a/frontend/src/pages/jails/IpLookupSection.tsx b/frontend/src/pages/jails/IpLookupSection.tsx index 5851ad7..a78a261 100644 --- a/frontend/src/pages/jails/IpLookupSection.tsx +++ b/frontend/src/pages/jails/IpLookupSection.tsx @@ -12,7 +12,7 @@ import { import { SearchRegular } from "@fluentui/react-icons"; import { useCommonSectionStyles } from "../../components/commonStyles"; import { useJailsPageStyles } from "./jailsPageStyles"; -import { useIpLookup } from "../../hooks/useJails"; +import { useIpLookup } from "../../hooks/useIpLookup"; export function IpLookupSection(): React.JSX.Element { const styles = useJailsPageStyles(); diff --git a/frontend/src/pages/jails/JailOverviewSection.tsx b/frontend/src/pages/jails/JailOverviewSection.tsx index d7dbdb2..f613c53 100644 --- a/frontend/src/pages/jails/JailOverviewSection.tsx +++ b/frontend/src/pages/jails/JailOverviewSection.tsx @@ -27,7 +27,7 @@ import { } from "@fluentui/react-icons"; import { useCommonSectionStyles } from "../../components/commonStyles"; import { useJailsPageStyles } from "./jailsPageStyles"; -import { useJails } from "../../hooks/useJails"; +import { useJails } from "../../hooks/useJailList"; import type { JailSummary } from "../../types/jail"; const useOverviewStyles = makeStyles({