Delete hook barrel files and switch to direct hook imports
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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";
|
||||
|
||||
/**
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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: [] }),
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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";
|
||||
@@ -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";
|
||||
@@ -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";
|
||||
@@ -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";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -31,7 +31,7 @@ vi.mock("../../hooks/useServerStatus", () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("../../hooks/useBlocklist", () => ({
|
||||
vi.mock("../../hooks/useBlocklistStatus", () => ({
|
||||
useBlocklistStatus: () => ({ hasErrors: false }),
|
||||
}));
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user