feat: reuse authentication for all HTTP integrations
This commit is contained in:
1 parent
879a4ae23c
commit
901fd3d940
36 files changed
+830
-295
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { SourceSetupPanel } from "~/components/custom-widgets/source-setup-panel";
|
||||
import { SourceSetupPanel } from "~/components/custom-widgets/integration-source-select";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { SourceSetupPanel } from "~/components/custom-widgets/source-setup-panel";
|
||||
import { SourceSetupPanel } from "~/components/custom-widgets/integration-source-select";
|
||||
import type { ModalProps } from "@mantine/core";
|
||||
|
||||
import type { HomarrCustomWidgetV2 } from "@homarr/custom-widgets/core";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { SourceSetupPanel } from "~/components/custom-widgets/source-setup-panel";
|
||||
import { SourceSetupPanel } from "~/components/custom-widgets/integration-source-select";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Button, Center, Group, Loader, Modal, Stack, Text } from "@mantine/core";
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
|
||||
import { Alert, Select, Stack, Text } from "@mantine/core";
|
||||
|
||||
import { CustomWidgetSourceSetupPanel } from "@homarr/custom-widgets/workbench";
|
||||
import type { CustomWidgetSourceSetupPanelProps } from "@homarr/custom-widgets/workbench";
|
||||
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import type { CustomWidgetIntegrationSource } from "@homarr/custom-widgets/core";
|
||||
import { customWidgetIntegrationKinds } from "@homarr/custom-widgets/core";
|
||||
import { integrationDefs } from "@homarr/definitions";
|
||||
import { integrationDefs, integrationKinds, isHttpIntegrationKind } from "@homarr/definitions";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
const httpIntegrationKinds = integrationKinds.filter(isHttpIntegrationKind);
|
||||
|
||||
interface IntegrationSourceSelectProps {
|
||||
kind: CustomWidgetIntegrationSource["integrationKind"];
|
||||
integrationId?: string;
|
||||
@@ -27,18 +31,18 @@ export function IntegrationSourceSelect({ kind, integrationId, onChange, onKindC
|
||||
{onKindChange && (
|
||||
<Select
|
||||
label={t("integrationType")}
|
||||
data={customWidgetIntegrationKinds.map((value) => ({ value, label: integrationDefs[value].name }))}
|
||||
data={httpIntegrationKinds.map((value) => ({ value, label: integrationDefs[value].name }))}
|
||||
value={kind}
|
||||
allowDeselect={false}
|
||||
onChange={(value) => {
|
||||
const selected = customWidgetIntegrationKinds.find((candidate) => candidate === value);
|
||||
const selected = httpIntegrationKinds.find((candidate) => candidate === value);
|
||||
if (selected) onKindChange(selected);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Select
|
||||
label={t("selectIntegration")}
|
||||
description={integrationDefs[kind].name}
|
||||
description={isHttpIntegrationKind(kind) ? integrationDefs[kind].name : kind}
|
||||
data={integrations.map(({ id, name }) => ({ value: id, label: name }))}
|
||||
value={integrationId ?? null}
|
||||
searchable
|
||||
@@ -55,3 +59,22 @@ export function IntegrationSourceSelect({ kind, integrationId, onChange, onKindC
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
export function SourceSetupPanel(props: CustomWidgetSourceSetupPanelProps) {
|
||||
return (
|
||||
<CustomWidgetSourceSetupPanel
|
||||
{...props}
|
||||
renderIntegrationSource={(setup, value) => {
|
||||
const kind = httpIntegrationKinds.find((candidate) => candidate === setup.integrationKind);
|
||||
if (!kind) return null;
|
||||
return (
|
||||
<IntegrationSourceSelect
|
||||
kind={kind}
|
||||
integrationId={value.integrationId}
|
||||
onChange={(integrationId) => props.onChange(setup.sourceId, { ...value, integrationId })}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { customWidgetIntegrationKinds } from "@homarr/custom-widgets/core";
|
||||
import { CustomWidgetSourceSetupPanel } from "@homarr/custom-widgets/workbench";
|
||||
import type { CustomWidgetSourceSetupPanelProps } from "@homarr/custom-widgets/workbench";
|
||||
|
||||
import { IntegrationSourceSelect } from "./integration-source-select";
|
||||
|
||||
export function SourceSetupPanel(props: CustomWidgetSourceSetupPanelProps) {
|
||||
return (
|
||||
<CustomWidgetSourceSetupPanel
|
||||
{...props}
|
||||
renderIntegrationSource={(setup, value) => {
|
||||
const kind = customWidgetIntegrationKinds.find((candidate) => candidate === setup.integrationKind);
|
||||
if (!kind) return null;
|
||||
return (
|
||||
<IntegrationSourceSelect
|
||||
kind={kind}
|
||||
integrationId={value.integrationId}
|
||||
onChange={(integrationId) => props.onChange(setup.sourceId, { ...value, integrationId })}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user