From 6cbfc2bee308760f557adc30d100dec2f4094651 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Wed, 4 Sep 2024 17:15:11 +0300 Subject: [PATCH] fix: show connections that aren't found in a code editor as the default Fixes #2230 fix: show message when connection type isn't found Fixes #2230 chore: show spec editor if connection isn't found --- .../Connections/ConnectionFormModal.tsx | 11 ++ .../Connections/ConnectionSpecEditor.tsx | 118 ++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 src/components/Connections/ConnectionSpecEditor.tsx diff --git a/src/components/Connections/ConnectionFormModal.tsx b/src/components/Connections/ConnectionFormModal.tsx index 3502a6f3e..b4134ec37 100644 --- a/src/components/Connections/ConnectionFormModal.tsx +++ b/src/components/Connections/ConnectionFormModal.tsx @@ -3,6 +3,7 @@ import { Icon } from "../../ui/Icons/Icon"; import { Modal } from "../../ui/Modal"; import ConnectionForm from "./ConnectionForm"; import ConnectionListView from "./ConnectionListView"; +import ConnectionSpecEditor from "./ConnectionSpecEditor"; import { ConnectionType, ConnectionValueType, @@ -130,6 +131,16 @@ export default function ConnectionFormModal({ isSubmitting={isSubmitting} isDeleting={isDeleting} /> + ) : formValue?.id ? ( + setConnectionType(undefined)} + onConnectionSubmit={onConnectionSubmit} + onConnectionDelete={onConnectionDelete} + formValue={formValue} + className={className} + isSubmitting={isSubmitting} + isDeleting={isDeleting} + /> ) : ( )} diff --git a/src/components/Connections/ConnectionSpecEditor.tsx b/src/components/Connections/ConnectionSpecEditor.tsx new file mode 100644 index 000000000..55bae98ea --- /dev/null +++ b/src/components/Connections/ConnectionSpecEditor.tsx @@ -0,0 +1,118 @@ +import { tables } from "@flanksource-ui/context/UserAccessContext/permissions"; +import clsx from "clsx"; +import { Form, Formik } from "formik"; +import { useMemo } from "react"; +import { FaSpinner, FaTrash } from "react-icons/fa"; +import { Button } from "../../ui/Buttons/Button"; +import { FormikCodeEditor } from "../Forms/Formik/FormikCodeEditor"; +import { AuthorizationAccessCheck } from "../Permissions/AuthorizationAccessCheck"; +import { Connection } from "./ConnectionFormModal"; +import { TestConnection } from "./TestConnection"; + +interface ConnectionSpecEditorProps { + onConnectionSubmit?: (data: Connection) => void; + onConnectionDelete?: (data: Connection) => void; + className?: string; + formValue?: Connection; + handleBack?: () => void; + isSubmitting?: boolean; + isDeleting?: boolean; +} + +export default function ConnectionSpecEditor({ + formValue, + onConnectionSubmit, + onConnectionDelete, + className, + handleBack = () => {}, + isSubmitting = false, + isDeleting = false, + ...props +}: ConnectionSpecEditorProps) { + const handleSubmit = (value: { values: Connection }) => { + onConnectionSubmit?.({ + ...value.values + }); + }; + + const formInitialValue = useMemo(() => { + return { + values: formValue + }; + }, [formValue]); + + const handleDelete = () => { + onConnectionDelete?.(formValue!); + }; + + if (!formValue) { + return null; + } + + return ( + + {() => ( +
+
+ +
+
+ {formValue?.id && ( + + + )} +
+ {formValue?.id && } + +
+
+
+ )} +
+ ); +}