refactor: replace custom no integration selected logic with existing error (#1166)
This commit is contained in:
@@ -532,10 +532,6 @@ export default {
|
|||||||
},
|
},
|
||||||
beta: "Beta",
|
beta: "Beta",
|
||||||
error: "Error",
|
error: "Error",
|
||||||
errors: {
|
|
||||||
noData: "No data to show",
|
|
||||||
noIntegration: "No integration selected",
|
|
||||||
},
|
|
||||||
action: {
|
action: {
|
||||||
add: "Add",
|
add: "Add",
|
||||||
apply: "Apply",
|
apply: "Apply",
|
||||||
@@ -1098,6 +1094,7 @@ export default {
|
|||||||
logs: "Check logs for more details",
|
logs: "Check logs for more details",
|
||||||
},
|
},
|
||||||
noIntegration: "No integration selected",
|
noIntegration: "No integration selected",
|
||||||
|
noData: "No integration data available",
|
||||||
},
|
},
|
||||||
option: {},
|
option: {},
|
||||||
},
|
},
|
||||||
|
|||||||
19
packages/widgets/src/errors/no-data-integration.tsx
Normal file
19
packages/widgets/src/errors/no-data-integration.tsx
Normal file
@@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,5 @@
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import {
|
import { ActionIcon, Anchor, Avatar, Badge, Card, Group, Image, ScrollArea, Stack, Text, Tooltip } from "@mantine/core";
|
||||||
ActionIcon,
|
|
||||||
Anchor,
|
|
||||||
Avatar,
|
|
||||||
Badge,
|
|
||||||
Card,
|
|
||||||
Center,
|
|
||||||
Group,
|
|
||||||
Image,
|
|
||||||
ScrollArea,
|
|
||||||
Stack,
|
|
||||||
Text,
|
|
||||||
Tooltip,
|
|
||||||
} from "@mantine/core";
|
|
||||||
import { IconThumbDown, IconThumbUp } from "@tabler/icons-react";
|
import { IconThumbDown, IconThumbUp } from "@tabler/icons-react";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
@@ -21,6 +8,8 @@ import type { ScopedTranslationFunction } from "@homarr/translation";
|
|||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import type { WidgetComponentProps } from "../../definition";
|
import type { WidgetComponentProps } from "../../definition";
|
||||||
|
import { NoIntegrationSelectedError } from "../../errors";
|
||||||
|
import { NoIntegrationDataError } from "../../errors/no-data-integration";
|
||||||
|
|
||||||
export default function MediaServerWidget({
|
export default function MediaServerWidget({
|
||||||
integrationIds,
|
integrationIds,
|
||||||
@@ -30,7 +19,6 @@ export default function MediaServerWidget({
|
|||||||
itemId,
|
itemId,
|
||||||
}: WidgetComponentProps<"mediaRequests-requestList">) {
|
}: WidgetComponentProps<"mediaRequests-requestList">) {
|
||||||
const t = useScopedI18n("widget.mediaRequests-requestList");
|
const t = useScopedI18n("widget.mediaRequests-requestList");
|
||||||
const tCommon = useScopedI18n("common");
|
|
||||||
const isQueryEnabled = Boolean(itemId);
|
const isQueryEnabled = Boolean(itemId);
|
||||||
const { data: mediaRequests, isError: _isError } = clientApi.widget.mediaRequests.getLatestRequests.useQuery(
|
const { data: mediaRequests, isError: _isError } = clientApi.widget.mediaRequests.getLatestRequests.useQuery(
|
||||||
{
|
{
|
||||||
@@ -67,9 +55,9 @@ export default function MediaServerWidget({
|
|||||||
|
|
||||||
const { mutate: mutateRequestAnswer } = clientApi.widget.mediaRequests.answerRequest.useMutation();
|
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 (
|
return (
|
||||||
<ScrollArea
|
<ScrollArea
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from "react";
|
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 { useElementSize } from "@mantine/hooks";
|
||||||
import type { Icon } from "@tabler/icons-react";
|
import type { Icon } from "@tabler/icons-react";
|
||||||
import {
|
import {
|
||||||
@@ -16,10 +16,12 @@ import {
|
|||||||
import combineClasses from "clsx";
|
import combineClasses from "clsx";
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
|
import type { RequestStats } from "@homarr/integrations/types";
|
||||||
import { useScopedI18n } from "@homarr/translation/client";
|
import { useScopedI18n } from "@homarr/translation/client";
|
||||||
|
|
||||||
import type { RequestStats } from "../../../../integrations/src/interfaces/media-requests/media-request";
|
|
||||||
import type { WidgetComponentProps } from "../../definition";
|
import type { WidgetComponentProps } from "../../definition";
|
||||||
|
import { NoIntegrationSelectedError } from "../../errors";
|
||||||
|
import { NoIntegrationDataError } from "../../errors/no-data-integration";
|
||||||
import classes from "./component.module.css";
|
import classes from "./component.module.css";
|
||||||
|
|
||||||
export default function MediaServerWidget({
|
export default function MediaServerWidget({
|
||||||
@@ -64,19 +66,9 @@ export default function MediaServerWidget({
|
|||||||
[baseData],
|
[baseData],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (integrationIds.length === 0)
|
if (integrationIds.length === 0) throw new NoIntegrationSelectedError();
|
||||||
return (
|
|
||||||
<Center ref={ref} h="100%">
|
|
||||||
{tCommon("errors.noIntegration")}
|
|
||||||
</Center>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (users.length === 0 || stats.length === 0)
|
if (users.length === 0 || stats.length === 0) throw new NoIntegrationDataError();
|
||||||
return (
|
|
||||||
<Center ref={ref} h="100%">
|
|
||||||
{tCommon("errors.noData")}
|
|
||||||
</Center>
|
|
||||||
);
|
|
||||||
|
|
||||||
//Add processing and available
|
//Add processing and available
|
||||||
const data = [
|
const data = [
|
||||||
|
|||||||
Reference in New Issue
Block a user