fix(ui): fix eslint errors

This commit is contained in:
Lukasz Mierzwa
2026-04-29 11:01:21 +01:00
committed by Łukasz Mierzwa
parent 3bb39f07fd
commit a67fc1dea5
7 changed files with 95 additions and 2229 deletions

View File

@@ -1,4 +1,4 @@
import { Fragment, FC } from "react";
import { Fragment, FC, useState } from "react";
import { observer } from "mobx-react-lite";
@@ -18,7 +18,8 @@ import { StaticLabels } from "Common/Query";
const SilenceProgress: FC<{
silence: APISilenceT;
}> = ({ silence }) => {
const diff = differenceInSeconds(parseISO(silence.endsAt), new Date());
const [now] = useState(() => new Date());
const diff = differenceInSeconds(parseISO(silence.endsAt), now);
if (diff <= 0) {
return (
<span className="badge bg-danger components-label">

View File

@@ -244,7 +244,7 @@ const MassDeleteProgress: FC<{
const ams = readWriteAlertmanagers.filter(
(u) => u.cluster === silence.cluster,
);
// eslint-disable-next-line @eslint-react/web-api/no-leaked-timeout -- false positive: timers are collected and cleared in the useEffect cleanup below
// eslint-disable-next-line @eslint-react/web-api-no-leaked-timeout -- false positive: timers are collected and cleared in the useEffect cleanup below
const timer = setTimeout(
() => deleteSilence(silence.cluster, silence.id, ams),
50 * index,

View File

@@ -75,7 +75,7 @@ const Browser: FC<{
const [showExpired, setShowExpired] = useState<boolean>(false);
const [searchTerm, setSearchTerm] = useState<string>("");
const [activePage, setActivePage] = useState<number>(1);
const [currentTime, setCurrentTime] = useState<number>(
const [currentTime, setCurrentTime] = useState<number>(() =>
Math.floor(Date.now() / 1000),
);

View File

@@ -9,6 +9,26 @@ import { useFetchGet } from "./useFetchGet";
jest.unmock("./useFetchGet");
const FetchGetTestComponent = ({
url,
fetcher,
}: {
url: string;
fetcher?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
}) => {
const { response, error, isLoading } = useFetchGet<string>(
url,
fetcher ? { fetcher } : undefined,
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
describe("useFetchGet", () => {
beforeEach(() => {
jest.useFakeTimers();
@@ -354,21 +374,10 @@ describe("useFetchGet", () => {
body: JSON.stringify({ status: "ok" }),
});
const Component = () => {
const { response, error, isLoading } = useFetchGet<string>(
"http://localhost/slow/ok",
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
act(() => {
const { unmount } = render(<Component />);
const { unmount } = render(
<FetchGetTestComponent url="http://localhost/slow/ok" />,
);
unmount();
});
@@ -385,21 +394,10 @@ describe("useFetchGet", () => {
body: JSON.stringify({ status: "error" }),
});
const Component = () => {
const { response, error, isLoading } = useFetchGet<string>(
"http://localhost/slow/500",
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
act(() => {
const { unmount } = render(<Component />);
const { unmount } = render(
<FetchGetTestComponent url="http://localhost/slow/500" />,
);
unmount();
});
@@ -415,21 +413,10 @@ describe("useFetchGet", () => {
throws: new TypeError("failed to fetch"),
});
const Component = () => {
const { response, error, isLoading } = useFetchGet<string>(
"http://localhost/slow/error",
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
act(() => {
const { unmount } = render(<Component />);
const { unmount } = render(
<FetchGetTestComponent url="http://localhost/slow/error" />,
);
unmount();
});
@@ -446,21 +433,10 @@ describe("useFetchGet", () => {
body: "this is not a valid JSON body",
});
const Component = () => {
const { response, error, isLoading } = useFetchGet<string>(
"http://localhost/slow/json/invalid",
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
act(() => {
const { unmount } = render(<Component />);
const { unmount } = render(
<FetchGetTestComponent url="http://localhost/slow/json/invalid" />,
);
unmount();
});
@@ -474,21 +450,10 @@ describe("useFetchGet", () => {
body: "ok",
});
const Component = () => {
const { response, error, isLoading } = useFetchGet<string>(
"http://localhost/slow/text",
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
act(() => {
const { unmount } = render(<Component />);
const { unmount } = render(
<FetchGetTestComponent url="http://localhost/slow/text" />,
);
unmount();
});
@@ -514,22 +479,13 @@ describe("useFetchGet", () => {
} as unknown as Response);
jest.useRealTimers();
const Component = () => {
const { response, error, isLoading } = useFetchGet<string>(
"http://localhost/slow/body",
{ fetcher: fetcher },
);
return (
<span>
<span>{response}</span>
<span>{error}</span>
<span>{isLoading}</span>
</span>
);
};
act(() => {
const { unmount } = render(<Component />);
const { unmount } = render(
<FetchGetTestComponent
url="http://localhost/slow/body"
fetcher={fetcher}
/>,
);
unmountFn = unmount;
});
});

View File

@@ -128,6 +128,7 @@ const MatchersFromAlerts = (
// add matchers for all shared labels in this group
for (const [key, value] of Object.entries(
// eslint-disable-next-line @eslint-react/purity -- false positive: called from MobX action, not from render
Object.assign(
{},
Object.fromEntries(group.labels.map((l) => [l.name, l.value])),