Delete hook barrel files and switch to direct hook imports

This commit is contained in:
2026-04-21 20:02:50 +02:00
parent 1ba82d56e7
commit b6d9c649ca
24 changed files with 35 additions and 48 deletions

View File

@@ -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 {

View File

@@ -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";

View File

@@ -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();

View File

@@ -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 {

View File

@@ -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");
});
});

View File

@@ -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();

View File

@@ -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({