Fix blocklist-import bantime, unify filter bar, and improve config navigation
This commit is contained in:
@@ -216,7 +216,6 @@ function JailConfigDetail({
|
||||
ignore_regex: ignoreRegex,
|
||||
date_pattern: datePattern !== "" ? datePattern : null,
|
||||
dns_mode: dnsMode,
|
||||
backend,
|
||||
log_encoding: logEncoding,
|
||||
prefregex: prefRegex !== "" ? prefRegex : null,
|
||||
bantime_escalation: {
|
||||
@@ -231,7 +230,7 @@ function JailConfigDetail({
|
||||
}),
|
||||
[
|
||||
banTime, findTime, maxRetry, failRegex, ignoreRegex, datePattern,
|
||||
dnsMode, backend, logEncoding, prefRegex, escEnabled, escFactor,
|
||||
dnsMode, logEncoding, prefRegex, escEnabled, escFactor,
|
||||
escFormula, escMultipliers, escMaxTime, escRndTime, escOverallJails,
|
||||
jail.ban_time, jail.find_time, jail.max_retry,
|
||||
],
|
||||
@@ -758,7 +757,12 @@ function InactiveJailDetail({
|
||||
*
|
||||
* @returns JSX element.
|
||||
*/
|
||||
export function JailsTab(): React.JSX.Element {
|
||||
interface JailsTabProps {
|
||||
/** Jail name to pre-select when the component mounts. */
|
||||
initialJail?: string;
|
||||
}
|
||||
|
||||
export function JailsTab({ initialJail }: JailsTabProps): React.JSX.Element {
|
||||
const styles = useConfigStyles();
|
||||
const { jails, loading, error, refresh, updateJail } =
|
||||
useJailConfigs();
|
||||
@@ -819,6 +823,13 @@ export function JailsTab(): React.JSX.Element {
|
||||
return [...activeItems, ...inactiveItems];
|
||||
}, [jails, inactiveJails]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!initialJail || selectedName) return;
|
||||
if (listItems.some((item) => item.name === initialJail)) {
|
||||
setSelectedName(initialJail);
|
||||
}
|
||||
}, [initialJail, listItems, selectedName]);
|
||||
|
||||
const activeJailMap = useMemo(
|
||||
() => new Map(jails.map((j) => [j.name, j])),
|
||||
[jails],
|
||||
|
||||
77
frontend/src/components/config/__tests__/JailsTab.test.tsx
Normal file
77
frontend/src/components/config/__tests__/JailsTab.test.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { render } from "@testing-library/react";
|
||||
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 { useConfigActiveStatus } from "../../../hooks/useConfigActiveStatus";
|
||||
|
||||
vi.mock("../../../hooks/useAutoSave");
|
||||
vi.mock("../../../hooks/useConfig");
|
||||
vi.mock("../../../hooks/useConfigActiveStatus");
|
||||
vi.mock("../../../api/config", () => ({
|
||||
fetchInactiveJails: vi.fn().mockResolvedValue({ jails: [] }),
|
||||
deactivateJail: vi.fn(),
|
||||
deleteJailLocalOverride: vi.fn(),
|
||||
addLogPath: vi.fn(),
|
||||
deleteLogPath: vi.fn(),
|
||||
fetchJailConfigFileContent: vi.fn(),
|
||||
updateJailConfigFile: vi.fn(),
|
||||
validateJailConfig: vi.fn(),
|
||||
}));
|
||||
|
||||
const mockUseAutoSave = vi.mocked(useAutoSave);
|
||||
const mockUseJailConfigs = vi.mocked(useJailConfigs);
|
||||
const mockUseConfigActiveStatus = vi.mocked(useConfigActiveStatus);
|
||||
|
||||
const basicJail: JailConfig = {
|
||||
name: "sshd",
|
||||
ban_time: 600,
|
||||
max_retry: 5,
|
||||
find_time: 600,
|
||||
fail_regex: [],
|
||||
ignore_regex: [],
|
||||
log_paths: [],
|
||||
date_pattern: null,
|
||||
log_encoding: "auto",
|
||||
backend: "polling",
|
||||
use_dns: "warn",
|
||||
prefregex: "",
|
||||
actions: [],
|
||||
bantime_escalation: null,
|
||||
};
|
||||
|
||||
describe("JailsTab", () => {
|
||||
it("does not include backend in auto-save payload", () => {
|
||||
const autoSavePayloads: Array<Record<string, unknown>> = [];
|
||||
mockUseAutoSave.mockImplementation((value) => {
|
||||
autoSavePayloads.push(value as Record<string, unknown>);
|
||||
return { status: "idle", errorText: null, retry: vi.fn() };
|
||||
});
|
||||
|
||||
mockUseJailConfigs.mockReturnValue({
|
||||
jails: [basicJail],
|
||||
total: 1,
|
||||
loading: false,
|
||||
error: null,
|
||||
refresh: vi.fn(),
|
||||
updateJail: vi.fn(),
|
||||
reloadAll: vi.fn(),
|
||||
});
|
||||
|
||||
mockUseConfigActiveStatus.mockReturnValue({ activeJails: [] });
|
||||
|
||||
render(
|
||||
<FluentProvider theme={webLightTheme}>
|
||||
<JailsTab initialJail="sshd" />
|
||||
</FluentProvider>,
|
||||
);
|
||||
|
||||
expect(autoSavePayloads.length).toBeGreaterThan(0);
|
||||
const lastPayload = autoSavePayloads[autoSavePayloads.length - 1];
|
||||
|
||||
expect(lastPayload).not.toHaveProperty("backend");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user