feat: allow no secrets for integration (#856)

This commit is contained in:
Manuel
2024-07-22 21:00:14 +02:00
committed by GitHub
parent b2860ffbd3
commit 508fcb9861
2 changed files with 21 additions and 3 deletions

View File

@@ -3,7 +3,8 @@
import { useCallback } from "react"; import { useCallback } from "react";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { Button, Fieldset, Group, SegmentedControl, Stack, TextInput } from "@mantine/core"; import { Alert, Button, Fieldset, Group, SegmentedControl, Stack, Text, TextInput } from "@mantine/core";
import { IconInfoCircle } from "@tabler/icons-react";
import { clientApi } from "@homarr/api/client"; import { clientApi } from "@homarr/api/client";
import type { IntegrationKind, IntegrationSecretKind } from "@homarr/definitions"; import type { IntegrationKind, IntegrationSecretKind } from "@homarr/definitions";
@@ -95,6 +96,11 @@ export const NewIntegrationForm = ({ searchParams }: NewIntegrationFormProps) =>
{...form.getInputProps(`secrets.${index}.value`)} {...form.getInputProps(`secrets.${index}.value`)}
/> />
))} ))}
{form.values.secrets.length === 0 && (
<Alert icon={<IconInfoCircle size={"1rem"} />} color={"blue"}>
<Text c={"blue"}>{t("integration.secrets.noSecretsRequired.text")}</Text>
</Alert>
)}
</Stack> </Stack>
</Fieldset> </Fieldset>
@@ -120,12 +126,20 @@ const SecretKindsSegmentedControl = ({ secretKinds, form }: SecretKindsSegmented
const t = useScopedI18n("integration.secrets"); const t = useScopedI18n("integration.secrets");
const secretKindGroups = secretKinds.map((kinds) => ({ const secretKindGroups = secretKinds.map((kinds) => ({
label: kinds.map((kind) => t(`kind.${kind}.label`)).join(" & "), label:
value: kinds.join("-"), kinds.length === 0
? t("noSecretsRequired.segmentTitle")
: kinds.map((kind) => t(`kind.${kind}.label`)).join(" & "),
value: kinds.length === 0 ? "empty" : kinds.join("-"),
})); }));
const onChange = useCallback( const onChange = useCallback(
(value: string) => { (value: string) => {
if (value === "empty") {
form.setFieldValue("secrets", []);
return;
}
const kinds = value.split("-") as IntegrationSecretKind[]; const kinds = value.split("-") as IntegrationSecretKind[];
const secrets = kinds.map((kind) => ({ const secrets = kinds.map((kind) => ({
kind, kind,

View File

@@ -470,6 +470,10 @@ export default {
title: "Reset secret", title: "Reset secret",
message: "Are you sure you want to reset this secret?", message: "Are you sure you want to reset this secret?",
}, },
noSecretsRequired: {
segmentTitle: "No secrets",
text: "No secrets required for this integration",
},
kind: { kind: {
username: { username: {
label: "Username", label: "Username",