mirror of
https://github.com/prymitive/karma
synced 2026-05-17 04:16:42 +00:00
fix(ui): fix eslint errors
This commit is contained in:
committed by
Łukasz Mierzwa
parent
3bb39f07fd
commit
a67fc1dea5
@@ -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">
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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])),
|
||||
|
||||
Reference in New Issue
Block a user