diff --git a/src/components/Connections/ConnectionForm.tsx b/src/components/Connections/ConnectionForm.tsx index ad0267f77..ec7eb0c7f 100644 --- a/src/components/Connections/ConnectionForm.tsx +++ b/src/components/Connections/ConnectionForm.tsx @@ -6,10 +6,11 @@ import { useMemo } from "react"; import { FaSpinner, FaTrash } from "react-icons/fa"; import { Button } from "../../ui/Buttons/Button"; import { AuthorizationAccessCheck } from "../Permissions/AuthorizationAccessCheck"; +import CanEditResource from "../Settings/CanEditResource"; import { Connection } from "./ConnectionFormModal"; +import { ConnectionType, connectionTypes } from "./connectionTypes"; import RenderConnectionFormFields from "./RenderConnectionFormFields"; import { TestConnection } from "./TestConnection"; -import { ConnectionType, connectionTypes } from "./connectionTypes"; interface ConnectionFormProps { connectionType: ConnectionType; @@ -138,44 +139,74 @@ export function ConnectionForm({
- {formValue?.id && ( - +
+ {connectionType && !formValue?.id && ( - )} -
- {formValue?.id && } + )} + + {formValue?.id && ( + + +
diff --git a/src/components/Connections/ConnectionFormModal.tsx b/src/components/Connections/ConnectionFormModal.tsx index b4134ec37..8db2a6dd4 100644 --- a/src/components/Connections/ConnectionFormModal.tsx +++ b/src/components/Connections/ConnectionFormModal.tsx @@ -54,6 +54,7 @@ export type Connection = { properties?: Record; ref?: string; namespace?: string; + source?: string; }; type ConnectionFormProps = React.HTMLProps & { diff --git a/src/components/Forms/SpecEditorForm.tsx b/src/components/Forms/SpecEditorForm.tsx index f7f68d126..187770f95 100644 --- a/src/components/Forms/SpecEditorForm.tsx +++ b/src/components/Forms/SpecEditorForm.tsx @@ -219,7 +219,15 @@ export default function SpecEditorForm({ agentId={initialValues.agent_details?.id} agentName={initialValues.agent_details?.name} source={initialValues.source} - onBack={onBack} + extraButtons={ + onBack && ( +
-
- {!!notification && ( - - )} - {(notification?.source === "UI" || !notification?.source) && ( -
+ +
+ {!!notification && ( + + )} +
+ {(notification?.source === "UI" || !notification?.source) && ( +
+
)} diff --git a/src/components/Settings/CRDSource.tsx b/src/components/Settings/CRDSource.tsx index 0f6a792c8..64cb7f21c 100644 --- a/src/components/Settings/CRDSource.tsx +++ b/src/components/Settings/CRDSource.tsx @@ -2,11 +2,12 @@ import { Link } from "react-router-dom"; import { Icon } from "../../ui/Icons/Icon"; type CRDSourceProps = { - id: string; - namespace: string; - name: string; + id?: string; + namespace?: string; + name?: string; source?: string; showMinimal?: boolean; + hideSourceLink?: boolean; }; export default function CRDSource({ @@ -14,9 +15,17 @@ export default function CRDSource({ name, namespace, source, - showMinimal = false + showMinimal = false, + hideSourceLink = false }: CRDSourceProps) { - if (source?.toLowerCase() !== "KubernetesCRD".toLowerCase()) { + if ( + source?.toLowerCase() !== "KubernetesCRD".toLowerCase() && + !source?.toLowerCase().startsWith("kubernetes") + ) { + return null; + } + + if (hideSourceLink) { return null; } @@ -33,16 +42,27 @@ export default function CRDSource({ ) : ( <> - CRD linked to{" "} - - - {namespace ? <>{namespace}/ : ""} - {name} - - + {name ? ( + <> + CRD linked to{" "} + + + {namespace ? <>{namespace}/ : ""} + {name} + + + + ) : ( + + Linked to CRD + + )} )}
diff --git a/src/components/Settings/CanEditResource.tsx b/src/components/Settings/CanEditResource.tsx index 5d84423f6..b4155bb7b 100644 --- a/src/components/Settings/CanEditResource.tsx +++ b/src/components/Settings/CanEditResource.tsx @@ -1,4 +1,3 @@ -import { Button } from "@flanksource-ui/ui/Buttons/Button"; import { Link } from "react-router-dom"; import { SchemaResourceType } from "../SchemaResourcePage/resourceTypes"; import CRDSource from "./CRDSource"; @@ -11,9 +10,11 @@ type CanEditResourceProps = { agentId?: string; agentName?: string; children: React.ReactNode; - id: string; - namespace: string; - name: string; + id?: string; + namespace?: string; + name?: string; + // do not render alternate content, if crd + hideSourceLink?: boolean; }; export function CanEditResourceInner({ @@ -22,6 +23,7 @@ export function CanEditResourceInner({ agentId, agentName, children, + hideSourceLink = false, ...props }: CanEditResourceProps) { // if Agent isn't local, we can't edit it @@ -29,6 +31,10 @@ export function CanEditResourceInner({ agentId !== "00000000-0000-0000-0000-000000000000" && agentId !== undefined ) { + if (hideSourceLink) { + return null; + } + return (
Linked to {" "} @@ -43,14 +49,23 @@ export function CanEditResourceInner({ } if (source?.startsWith("component")) { + if (hideSourceLink) { + return null; + } return ; } if (source?.startsWith("kubernetes")) { + if (hideSourceLink) { + return null; + } return ; } if (source === "ConfigFile") { + if (hideSourceLink) { + return null; + } return (
@@ -61,7 +76,9 @@ export function CanEditResourceInner({ } if (source && source !== "UI") { - return ; + return ( + + ); } // eslint-disable-next-line react/jsx-no-useless-fragment @@ -69,23 +86,16 @@ export function CanEditResourceInner({ } export default function CanEditResource({ - onBack, + extraButtons, + className = "flex flex-1 flex-row justify-end gap-2", ...props }: CanEditResourceProps & { - onBack?: () => void; + className?: string; + extraButtons?: React.ReactNode; }) { return ( -
-
- {onBack && ( -
+
+ {extraButtons &&
{extraButtons}
}
);