mirror of
https://github.com/gethomepage/homepage.git
synced 2026-10-01 00:11:18 -07:00
Chore: full react hooks eslint compliance (#7040)
This commit is contained in:
@@ -3,8 +3,12 @@ import Container from "components/services/widget/container";
|
||||
import { useTranslation } from "next-i18next/pages";
|
||||
|
||||
import useWidgetAPI from "utils/proxy/use-widget-api";
|
||||
import withWidgetFields from "utils/widget-fields";
|
||||
|
||||
export default function Component({ service }) {
|
||||
const DEFAULT_FIELDS = ["map", "currentPlayers", "ping"];
|
||||
|
||||
export default function Component({ service: configuredService }) {
|
||||
const service = withWidgetFields(configuredService, DEFAULT_FIELDS);
|
||||
const { widget } = service;
|
||||
const { data: serverData, error: serverError } = useWidgetAPI(widget, "status");
|
||||
const { t } = useTranslation();
|
||||
@@ -13,16 +17,6 @@ export default function Component({ service }) {
|
||||
return <Container service={service} error={serverError} />;
|
||||
}
|
||||
|
||||
// Default fields
|
||||
if (widget.fields == null || widget.fields.length === 0) {
|
||||
widget.fields = ["map", "currentPlayers", "ping"];
|
||||
}
|
||||
const MAX_ALLOWED_FIELDS = 4;
|
||||
// Limits max number of displayed fields
|
||||
if (widget.fields != null && widget.fields.length > MAX_ALLOWED_FIELDS) {
|
||||
widget.fields = widget.fields.slice(0, MAX_ALLOWED_FIELDS);
|
||||
}
|
||||
|
||||
if (!serverData) {
|
||||
return (
|
||||
<Container service={service}>
|
||||
|
||||
@@ -22,7 +22,7 @@ describe("widgets/gamedig/component", () => {
|
||||
const service = { widget: { type: "gamedig", url: "http://x" } };
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(["map", "currentPlayers", "ping"]);
|
||||
expect(service.widget.fields).toBeUndefined();
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(3);
|
||||
expect(screen.getByText("gamedig.map")).toBeInTheDocument();
|
||||
expect(screen.getByText("gamedig.currentPlayers")).toBeInTheDocument();
|
||||
@@ -54,7 +54,7 @@ describe("widgets/gamedig/component", () => {
|
||||
|
||||
const { container } = renderWithProviders(<Component service={service} />, { settings: { hideErrors: false } });
|
||||
|
||||
expect(service.widget.fields).toEqual(["status", "name", "map", "currentPlayers"]);
|
||||
expect(service.widget.fields).toEqual(["status", "name", "map", "currentPlayers", "ping"]);
|
||||
expect(container.querySelectorAll(".service-block")).toHaveLength(4);
|
||||
|
||||
expectBlockValue(container, "gamedig.status", "gamedig.online");
|
||||
|
||||
Reference in New Issue
Block a user