Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace custom no integration selected logic with existing … #1166

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/translation/src/lang/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,6 @@ export default {
},
beta: "Beta",
error: "Error",
errors: {
noData: "No data to show",
noIntegration: "No integration selected",
},
action: {
add: "Add",
apply: "Apply",
Expand Down Expand Up @@ -1098,6 +1094,7 @@ export default {
logs: "Check logs for more details",
},
noIntegration: "No integration selected",
noData: "No integration data available",
},
option: {},
},
Expand Down
19 changes: 19 additions & 0 deletions packages/widgets/src/errors/no-data-integration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { IconDatabaseOff } from "@tabler/icons-react";

import type { TranslationFunction } from "@homarr/translation";

import { ErrorBoundaryError } from "./base";

export class NoIntegrationDataError extends ErrorBoundaryError {
constructor() {
super("No integration data available");
}

public getErrorBoundaryData() {
return {
icon: IconDatabaseOff,
message: (t: TranslationFunction) => t("widget.common.error.noData"),
showLogsLink: false,
};
}
}
22 changes: 5 additions & 17 deletions packages/widgets/src/media-requests/list/component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { useMemo } from "react";
import {
ActionIcon,
Anchor,
Avatar,
Badge,
Card,
Center,
Group,
Image,
ScrollArea,
Stack,
Text,
Tooltip,
} from "@mantine/core";
import { ActionIcon, Anchor, Avatar, Badge, Card, Group, Image, ScrollArea, Stack, Text, Tooltip } from "@mantine/core";
import { IconThumbDown, IconThumbUp } from "@tabler/icons-react";

import { clientApi } from "@homarr/api/client";
Expand All @@ -21,6 +8,8 @@ import type { ScopedTranslationFunction } from "@homarr/translation";
import { useScopedI18n } from "@homarr/translation/client";

import type { WidgetComponentProps } from "../../definition";
import { NoIntegrationSelectedError } from "../../errors";
import { NoIntegrationDataError } from "../../errors/no-data-integration";

export default function MediaServerWidget({
integrationIds,
Expand All @@ -30,7 +19,6 @@ export default function MediaServerWidget({
itemId,
}: WidgetComponentProps<"mediaRequests-requestList">) {
const t = useScopedI18n("widget.mediaRequests-requestList");
const tCommon = useScopedI18n("common");
const isQueryEnabled = Boolean(itemId);
const { data: mediaRequests, isError: _isError } = clientApi.widget.mediaRequests.getLatestRequests.useQuery(
{
Expand Down Expand Up @@ -67,9 +55,9 @@ export default function MediaServerWidget({

const { mutate: mutateRequestAnswer } = clientApi.widget.mediaRequests.answerRequest.useMutation();

if (integrationIds.length === 0) return <Center h="100%">{tCommon("errors.noIntegration")}</Center>;
if (integrationIds.length === 0) throw new NoIntegrationSelectedError();

if (sortedMediaRequests.length === 0) return <Center h="100%">{tCommon("errors.noData")}</Center>;
if (sortedMediaRequests.length === 0) throw new NoIntegrationDataError();

return (
<ScrollArea
Expand Down
20 changes: 6 additions & 14 deletions packages/widgets/src/media-requests/stats/component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMemo } from "react";
import { ActionIcon, Avatar, Card, Center, Grid, Group, Space, Stack, Text, Tooltip } from "@mantine/core";
import { ActionIcon, Avatar, Card, Grid, Group, Space, Stack, Text, Tooltip } from "@mantine/core";
import { useElementSize } from "@mantine/hooks";
import type { Icon } from "@tabler/icons-react";
import {
Expand All @@ -16,10 +16,12 @@ import {
import combineClasses from "clsx";

import { clientApi } from "@homarr/api/client";
import type { RequestStats } from "@homarr/integrations/types";
import { useScopedI18n } from "@homarr/translation/client";

import type { RequestStats } from "../../../../integrations/src/interfaces/media-requests/media-request";
import type { WidgetComponentProps } from "../../definition";
import { NoIntegrationSelectedError } from "../../errors";
import { NoIntegrationDataError } from "../../errors/no-data-integration";
import classes from "./component.module.css";

export default function MediaServerWidget({
Expand Down Expand Up @@ -64,19 +66,9 @@ export default function MediaServerWidget({
[baseData],
);

if (integrationIds.length === 0)
return (
<Center ref={ref} h="100%">
{tCommon("errors.noIntegration")}
</Center>
);
if (integrationIds.length === 0) throw new NoIntegrationSelectedError();

if (users.length === 0 || stats.length === 0)
return (
<Center ref={ref} h="100%">
{tCommon("errors.noData")}
</Center>
);
if (users.length === 0 || stats.length === 0) throw new NoIntegrationDataError();

//Add processing and available
const data = [
Expand Down