feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com> Co-authored-by: arturict <arturict@users.noreply.github.com> Co-authored-by: Thomas <thomas@ajnart.fr> Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com> Co-authored-by: Danura30082 <danura30082+github@gmail.com> Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com> Co-authored-by: ajnart <thomas@ajnart.fr> Co-authored-by: ajnart <thomas@ajnart.dev> Co-authored-by: chenjun <chenjun@foxmail.com> Co-authored-by: Wikibear <wikibear@users.noreply.github.com> Co-authored-by: Bergasha <bergasha@gmail.com> Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com> Co-authored-by: Lucas Araujo <lucas.lra@gmail.com> Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com> Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social> Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com> Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com> Co-authored-by: thrawnx <tight.bulb9384@fastmail.com> Co-authored-by: Chris <58918656+nordada@users.noreply.github.com> Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com> Co-authored-by: Yanis <naamaneyanis@gmail.com> Co-authored-by: Wikibear <me@sej.de> Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386
-139176
No files matched your search
@@ -1,7 +1,62 @@
|
||||
[data-mantine-color-scheme="light"] .card {
|
||||
background-color: var(--mantine-color-gray-1);
|
||||
.card {
|
||||
background-color: light-dark(var(--mantine-color-gray-1), var(--mantine-color-dark-7));
|
||||
}
|
||||
|
||||
[data-mantine-color-scheme="dark"] .card {
|
||||
background-color: var(--mantine-color-dark-7);
|
||||
.advancedCard {
|
||||
background-color: transparent;
|
||||
border: 1px solid rgb(from var(--mantine-color-secondaryColor-filled) r g b / calc(var(--opacity, 1) * 0.38));
|
||||
}
|
||||
|
||||
.root {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.testAction {
|
||||
margin-inline-start: auto;
|
||||
flex-shrink: 0;
|
||||
opacity: 0;
|
||||
transition: opacity 120ms ease;
|
||||
}
|
||||
|
||||
.root:hover .testAction,
|
||||
.root:focus-within .testAction {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.indexerRow {
|
||||
min-height: 24px;
|
||||
padding: 2px 4px;
|
||||
border-radius: var(--mantine-radius-xs);
|
||||
|
||||
&:hover,
|
||||
&:focus-within {
|
||||
background-color: transparent;
|
||||
}
|
||||
}
|
||||
|
||||
.indexerLink {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-self: stretch;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@media (any-pointer: coarse) {
|
||||
.testAction {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.indexerRow {
|
||||
min-height: 44px;
|
||||
padding-block: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.testAction {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
@@ -1,121 +1,269 @@
|
||||
"use client";
|
||||
|
||||
import { ActionIcon, Anchor, Button, Card, Flex, Group, ScrollArea, Stack, Text } from "@mantine/core";
|
||||
import { IconCircleCheck, IconCircleX, IconReportSearch, IconTestPipe } from "@tabler/icons-react";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import {
|
||||
ActionIcon,
|
||||
Anchor,
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Flex,
|
||||
Group,
|
||||
ScrollArea,
|
||||
Stack,
|
||||
Text,
|
||||
Tooltip,
|
||||
VisuallyHidden,
|
||||
} from "@mantine/core";
|
||||
import { IconCircleCheck, IconCircleX, IconHelpCircle, IconReportSearch, IconTestPipe } from "@tabler/icons-react";
|
||||
import combineClasses from "clsx";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { useIntegrationsWithInteractAccess } from "@homarr/auth/client";
|
||||
import { useRequiredBoard } from "@homarr/boards/context";
|
||||
import { showErrorNotification } from "@homarr/notifications";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { iconSizes } from "@homarr/ui";
|
||||
|
||||
import { WidgetQueryLoadingState } from "../common/query-state-indicator";
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import { useWidgetRuntimeActions } from "../runtime-hooks";
|
||||
import { getSafeApplicationUrl, SAFE_NEW_TAB_REL } from "../common/application-url";
|
||||
import { WidgetEmptyState } from "../common/empty-state";
|
||||
import { getUsableWidgetQueryData, isInitialWidgetQueryPending } from "../common/query-state";
|
||||
import actionTargetClasses from "../common/action-target.module.css";
|
||||
import classes from "./component.module.css";
|
||||
import { getIndexerDisplayStatus } from "./status";
|
||||
|
||||
const statusPresentation = {
|
||||
healthy: { color: "green" },
|
||||
unhealthy: { color: "red" },
|
||||
disabled: { color: "gray" },
|
||||
unknown: { color: "gray" },
|
||||
} as const;
|
||||
|
||||
export default function IndexerManagerWidget({
|
||||
options,
|
||||
integrationIds,
|
||||
width,
|
||||
height,
|
||||
isEditMode,
|
||||
widgetRuntimeRef,
|
||||
displayMode,
|
||||
}: WidgetComponentProps<"indexerManager">) {
|
||||
const t = useI18n();
|
||||
const { data: indexersData = [] } = clientApi.widget.indexerManager.getIndexersStatus.useQuery({ integrationIds });
|
||||
const t = useI18n("widget.indexerManager");
|
||||
const tCommon = useI18n("common");
|
||||
const indexersQuery = clientApi.widget.indexerManager.getIndexersStatus.useQuery({ integrationIds });
|
||||
const isInitialPending = isInitialWidgetQueryPending(indexersQuery);
|
||||
const indexersData = getUsableWidgetQueryData(indexersQuery) ?? [];
|
||||
|
||||
const utils = clientApi.useUtils();
|
||||
const { mutate: testAll, isPending } = clientApi.widget.indexerManager.testAllIndexers.useMutation({
|
||||
const {
|
||||
mutate: testAll,
|
||||
isPending,
|
||||
error: testAllError,
|
||||
} = clientApi.widget.indexerManager.testAllIndexers.useMutation({
|
||||
onError: () =>
|
||||
showErrorNotification({
|
||||
title: tCommon("error"),
|
||||
message: t("error.testAll"),
|
||||
}),
|
||||
onSettled: () => void utils.widget.indexerManager.getIndexersStatus.invalidate(),
|
||||
});
|
||||
const interactIntegrationIds = new Set(useIntegrationsWithInteractAccess().map(({ id }) => id));
|
||||
const canInteract = integrationIds.length > 0 && integrationIds.every((id) => interactIntegrationIds.has(id));
|
||||
const board = useRequiredBoard();
|
||||
const hasSmallWidth = width < 256;
|
||||
const hasSmallHeight = height < 256;
|
||||
const isAdvanced = displayMode === "advanced";
|
||||
const hasSmallWidth = !isAdvanced && width < 256;
|
||||
const hasSmallHeight = !isAdvanced && height < 256;
|
||||
const allIndexers = indexersData.flatMap((entry) => entry.indexers);
|
||||
const hasSourceError = indexersData.some((entry) => Boolean(entry.error));
|
||||
const healthyCount = allIndexers.filter((indexer) => getIndexerDisplayStatus(indexer) === "healthy").length;
|
||||
const unknownCount = allIndexers.filter((indexer) => getIndexerDisplayStatus(indexer) === "unknown").length;
|
||||
const unavailableCount = allIndexers.filter(
|
||||
(indexer) => indexer.status === false || indexer.enabled === false,
|
||||
).length;
|
||||
|
||||
const testAllIndexers = useCallback(() => {
|
||||
if (!canInteract || isPending) return;
|
||||
testAll({ integrationIds });
|
||||
}, [canInteract, integrationIds, isPending, testAll]);
|
||||
|
||||
const runtimeActions = useMemo(() => ({ testAllIndexers }), [testAllIndexers]);
|
||||
useWidgetRuntimeActions(widgetRuntimeRef, runtimeActions);
|
||||
|
||||
return (
|
||||
<Flex className="indexer-manager-container" h="100%" direction="column" gap="sm" p="sm" align="center">
|
||||
<Group className="indexer-manager-title" align="center" gap="xs" wrap="nowrap">
|
||||
<IconReportSearch
|
||||
className="indexer-manager-title-icon"
|
||||
size={hasSmallWidth ? 16 : 20}
|
||||
style={{ minWidth: hasSmallWidth ? 16 : 20 }}
|
||||
/>
|
||||
<Text size={hasSmallWidth ? "xs" : "md"} fw="bold">
|
||||
{t("widget.indexerManager.title")}
|
||||
<Flex
|
||||
className={`indexer-manager-container ${classes.root}`}
|
||||
h="100%"
|
||||
direction="column"
|
||||
gap={isAdvanced ? "xs" : "sm"}
|
||||
p="sm"
|
||||
align={isAdvanced ? undefined : "center"}
|
||||
>
|
||||
<Group
|
||||
className="indexer-manager-title"
|
||||
align="center"
|
||||
gap="xs"
|
||||
wrap="nowrap"
|
||||
w={isAdvanced ? "100%" : undefined}
|
||||
>
|
||||
{testAllError && <VisuallyHidden role="alert">{tCommon("error")}</VisuallyHidden>}
|
||||
<Tooltip label={t("title")} disabled={!hasSmallWidth}>
|
||||
<IconReportSearch
|
||||
className="indexer-manager-title-icon"
|
||||
style={hasSmallWidth ? iconSizes.md : iconSizes.xl}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Text
|
||||
size={hasSmallWidth ? "xs" : isAdvanced ? "sm" : "md"}
|
||||
fw={isAdvanced ? 600 : "bold"}
|
||||
truncate={isAdvanced ? "end" : undefined}
|
||||
>
|
||||
{t("title")}
|
||||
</Text>
|
||||
{hasSmallHeight && (
|
||||
<ActionIcon
|
||||
className="indexer-manager-test-action-icon"
|
||||
size="sm"
|
||||
radius={board.itemRadius}
|
||||
variant="light"
|
||||
loading={isPending}
|
||||
loaderProps={{ type: "dots" }}
|
||||
onClick={() => {
|
||||
testAll({ integrationIds });
|
||||
}}
|
||||
>
|
||||
<IconTestPipe size={12} />
|
||||
</ActionIcon>
|
||||
{isAdvanced && (
|
||||
<Group gap={4} wrap="nowrap">
|
||||
<Badge size="xs" color="green" variant="light">
|
||||
{healthyCount}
|
||||
</Badge>
|
||||
{unknownCount > 0 && (
|
||||
<Badge size="xs" color="gray" variant="light" aria-label={t("status.unknown")}>
|
||||
{unknownCount}
|
||||
</Badge>
|
||||
)}
|
||||
{unavailableCount > 0 && (
|
||||
<Badge size="xs" color="red" variant="light">
|
||||
{unavailableCount}
|
||||
</Badge>
|
||||
)}
|
||||
</Group>
|
||||
)}
|
||||
{(isAdvanced || hasSmallHeight) && (
|
||||
<Tooltip label={testAllError ? tCommon("error") : t("testAll")}>
|
||||
<ActionIcon
|
||||
className={combineClasses(
|
||||
"indexer-manager-test-action-icon",
|
||||
isAdvanced && classes.testAction,
|
||||
actionTargetClasses.root,
|
||||
)}
|
||||
size="sm"
|
||||
radius={board.itemRadius}
|
||||
variant="light"
|
||||
color={testAllError ? "red" : undefined}
|
||||
loading={isPending}
|
||||
disabled={isEditMode || !canInteract}
|
||||
loaderProps={{ type: "dots" }}
|
||||
onClick={() => {
|
||||
testAllIndexers();
|
||||
}}
|
||||
aria-label={t("testAll")}
|
||||
>
|
||||
<IconTestPipe style={isAdvanced ? iconSizes.sm : iconSizes.xs} />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Group>
|
||||
<Card
|
||||
className={combineClasses("indexer-manager-list-container", classes.card)}
|
||||
className={combineClasses("indexer-manager-list-container", classes.card, isAdvanced && classes.advancedCard)}
|
||||
w="100%"
|
||||
p="xs"
|
||||
radius={board.itemRadius}
|
||||
flex={1}
|
||||
>
|
||||
<ScrollArea className="indexer-manager-list-scroll-area" h="100%" scrollbars="y">
|
||||
{indexersData.map(({ integrationId, indexers }) => (
|
||||
<Stack gap={4} className={`indexer-manager-${integrationId}-list-container`} p={0} key={integrationId}>
|
||||
{indexers.map((indexer) => (
|
||||
<Group
|
||||
className={`indexer-manager-line indexer-manager-${indexer.name}`}
|
||||
key={indexer.id}
|
||||
justify="space-between"
|
||||
gap="xs"
|
||||
wrap="nowrap"
|
||||
>
|
||||
<Anchor
|
||||
className="indexer-manager-line-anchor"
|
||||
href={indexer.url}
|
||||
target={options.openIndexerSiteInNewTab ? "_blank" : "_self"}
|
||||
>
|
||||
<Text className="indexer-manager-line-anchor-text" c="dimmed" size={hasSmallWidth ? "xs" : "sm"}>
|
||||
{indexer.name}
|
||||
{isInitialPending ? (
|
||||
<WidgetQueryLoadingState />
|
||||
) : allIndexers.length === 0 && !hasSourceError ? (
|
||||
<WidgetEmptyState />
|
||||
) : (
|
||||
<ScrollArea className="indexer-manager-list-scroll-area" h="100%" scrollbars="y">
|
||||
{indexersData.map(({ integrationId, integrationName, indexers, error }) => (
|
||||
<Stack gap={4} className={`indexer-manager-${integrationId}-list-container`} p={0} key={integrationId}>
|
||||
{(isAdvanced || error) && (
|
||||
<Group justify="space-between" wrap="nowrap" py={4}>
|
||||
<Text size="xs" fw={600} truncate="end">
|
||||
{integrationName}
|
||||
</Text>
|
||||
</Anchor>
|
||||
{indexer.status === false || indexer.enabled === false ? (
|
||||
<IconCircleX
|
||||
className="indexer-manager-line-status-icon indexer-manager-line-icon-disabled"
|
||||
color="#d9534f"
|
||||
size={hasSmallWidth ? 12 : 16}
|
||||
/>
|
||||
) : (
|
||||
<IconCircleCheck
|
||||
className="indexer-manager-line-status-icon indexer-manager-line-icon-enabled"
|
||||
color="#2ecc71"
|
||||
size={hasSmallWidth ? 12 : 16}
|
||||
/>
|
||||
)}
|
||||
</Group>
|
||||
))}
|
||||
</Stack>
|
||||
))}
|
||||
</ScrollArea>
|
||||
{error && (
|
||||
<Badge size="xs" color="red" variant="light">
|
||||
{tCommon("error")}
|
||||
</Badge>
|
||||
)}
|
||||
</Group>
|
||||
)}
|
||||
{indexers.map((indexer) => {
|
||||
const href = getSafeApplicationUrl(indexer.url);
|
||||
const displayStatus = getIndexerDisplayStatus(indexer);
|
||||
const presentation = statusPresentation[displayStatus];
|
||||
let StatusIcon = IconCircleX;
|
||||
if (displayStatus === "healthy") StatusIcon = IconCircleCheck;
|
||||
if (displayStatus === "unknown") StatusIcon = IconHelpCircle;
|
||||
return (
|
||||
<Group
|
||||
className={combineClasses(
|
||||
"indexer-manager-line",
|
||||
`indexer-manager-${indexer.name}`,
|
||||
isAdvanced && classes.indexerRow,
|
||||
)}
|
||||
key={indexer.id}
|
||||
justify="space-between"
|
||||
gap="xs"
|
||||
wrap="nowrap"
|
||||
>
|
||||
<Anchor
|
||||
className={combineClasses("indexer-manager-line-anchor", isAdvanced && classes.indexerLink)}
|
||||
component={href ? "a" : "span"}
|
||||
href={href}
|
||||
target={href ? (options.openIndexerSiteInNewTab ? "_blank" : "_self") : undefined}
|
||||
rel={href && options.openIndexerSiteInNewTab ? SAFE_NEW_TAB_REL : undefined}
|
||||
title={href}
|
||||
>
|
||||
<Text
|
||||
className="indexer-manager-line-anchor-text"
|
||||
c="dimmed"
|
||||
size={hasSmallWidth ? "xs" : "sm"}
|
||||
truncate={isAdvanced ? "end" : undefined}
|
||||
>
|
||||
{indexer.name}
|
||||
</Text>
|
||||
</Anchor>
|
||||
{isAdvanced ? (
|
||||
<Badge size="xs" color={presentation.color} variant="light">
|
||||
{t(`status.${displayStatus}` as never)}
|
||||
</Badge>
|
||||
) : (
|
||||
<StatusIcon
|
||||
className="indexer-manager-line-status-icon"
|
||||
color={`var(--mantine-color-${presentation.color}-6)`}
|
||||
style={hasSmallWidth ? iconSizes.xs : iconSizes.md}
|
||||
aria-label={t(`status.${displayStatus}` as never)}
|
||||
/>
|
||||
)}
|
||||
</Group>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
))}
|
||||
</ScrollArea>
|
||||
)}
|
||||
</Card>
|
||||
{!hasSmallHeight && (
|
||||
{!isAdvanced && !hasSmallHeight && (
|
||||
<Button
|
||||
className="indexer-manager-test-button"
|
||||
w="100%"
|
||||
size="xs"
|
||||
radius={board.itemRadius}
|
||||
variant="light"
|
||||
leftSection={<IconTestPipe size={"1rem"} />}
|
||||
color={testAllError ? "red" : undefined}
|
||||
leftSection={<IconTestPipe style={iconSizes.md} />}
|
||||
loading={isPending}
|
||||
disabled={isEditMode || !canInteract}
|
||||
loaderProps={{ type: "dots" }}
|
||||
onClick={() => {
|
||||
testAll({ integrationIds });
|
||||
testAllIndexers();
|
||||
}}
|
||||
>
|
||||
{t("widget.indexerManager.testAll")}
|
||||
{t("testAll")}
|
||||
</Button>
|
||||
)}
|
||||
</Flex>
|
||||
|
||||
@@ -1,21 +1,36 @@
|
||||
import { IconReportSearch, IconServerOff } from "@tabler/icons-react";
|
||||
import { IconReportSearch, IconServerOff, IconTestPipe } from "@tabler/icons-react";
|
||||
|
||||
import { getIntegrationKindsByCategory } from "@homarr/definitions";
|
||||
import { getWidgetIntegrationConfig } from "@homarr/definitions";
|
||||
|
||||
import { createWidgetDefinition } from "../definition";
|
||||
import { optionsBuilder } from "../options";
|
||||
|
||||
const createOptions = () =>
|
||||
optionsBuilder.from((factory) => ({
|
||||
openIndexerSiteInNewTab: factory.switch({
|
||||
defaultValue: true,
|
||||
}),
|
||||
}));
|
||||
|
||||
export const { definition, componentLoader } = createWidgetDefinition("indexerManager", {
|
||||
icon: IconReportSearch,
|
||||
contextActions: ({ widgetRuntimeRef, context }) => [
|
||||
{
|
||||
key: "test-all-indexers",
|
||||
label: "widget.indexerManager.testAll",
|
||||
icon: IconTestPipe,
|
||||
disabled:
|
||||
context.isEditMode ||
|
||||
!context.canInteractWithSelectedIntegrations ||
|
||||
typeof widgetRuntimeRef.current.actions.testAllIndexers !== "function",
|
||||
onClick: () => {
|
||||
widgetRuntimeRef.current.actions.testAllIndexers?.();
|
||||
},
|
||||
},
|
||||
],
|
||||
refetchInterval: null,
|
||||
createOptions() {
|
||||
return optionsBuilder.from((factory) => ({
|
||||
openIndexerSiteInNewTab: factory.switch({
|
||||
defaultValue: true,
|
||||
}),
|
||||
}));
|
||||
},
|
||||
supportedIntegrations: getIntegrationKindsByCategory("indexerManager"),
|
||||
createOptions,
|
||||
...getWidgetIntegrationConfig("indexerManager"),
|
||||
errors: {
|
||||
INTERNAL_SERVER_ERROR: {
|
||||
icon: IconServerOff,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getIndexerDisplayStatus } from "./status";
|
||||
|
||||
describe("Indexer display status", () => {
|
||||
test("distinguishes disabled indexers from unhealthy enabled indexers", () => {
|
||||
expect(getIndexerDisplayStatus({ enabled: false, status: false })).toBe("disabled");
|
||||
expect(getIndexerDisplayStatus({ enabled: false, status: true })).toBe("disabled");
|
||||
expect(getIndexerDisplayStatus({ enabled: true, status: false })).toBe("unhealthy");
|
||||
expect(getIndexerDisplayStatus({ enabled: true, status: true })).toBe("healthy");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
export type IndexerDisplayStatus = "healthy" | "unhealthy" | "disabled" | "unknown";
|
||||
|
||||
export const getIndexerDisplayStatus = ({
|
||||
enabled,
|
||||
status,
|
||||
}: {
|
||||
enabled: boolean;
|
||||
status: boolean | null;
|
||||
}): IndexerDisplayStatus => {
|
||||
if (!enabled) return "disabled";
|
||||
if (status === null) return "unknown";
|
||||
return status ? "healthy" : "unhealthy";
|
||||
};
|
||||
Reference in new issue
Block a user