From 14bcfdba88899116ee7e708c1ff3270375561651 Mon Sep 17 00:00:00 2001 From: Maina Wycliffe Date: Wed, 25 Sep 2024 10:31:46 +0300 Subject: [PATCH] feat: add permissions tabs for connection and playbooks Fixes #2246 fix: fix minor issues related to the permissions tab --- .../Connections/ConnectionFormModal.tsx | 127 ++++++++++++------ .../Settings/PlaybookSpecFormModal.tsx | 35 ++++- src/pages/Settings/ConnectionsPage.tsx | 21 ++- 3 files changed, 128 insertions(+), 55 deletions(-) diff --git a/src/components/Connections/ConnectionFormModal.tsx b/src/components/Connections/ConnectionFormModal.tsx index 8db2a6dd4..5e4a69d00 100644 --- a/src/components/Connections/ConnectionFormModal.tsx +++ b/src/components/Connections/ConnectionFormModal.tsx @@ -1,6 +1,8 @@ +import { Tab, Tabs } from "@flanksource-ui/ui/Tabs/Tabs"; import React, { useEffect, useState } from "react"; import { Icon } from "../../ui/Icons/Icon"; import { Modal } from "../../ui/Modal"; +import PermissionsView from "../Permissions/PermissionsView"; import ConnectionForm from "./ConnectionForm"; import ConnectionListView from "./ConnectionListView"; import ConnectionSpecEditor from "./ConnectionSpecEditor"; @@ -81,6 +83,8 @@ export default function ConnectionFormModal({ ConnectionType | undefined >(() => connectionTypes.find((item) => item.title === formValue?.type)); + const [activeTab, setActiveTab] = useState<"form" | "permissions">("form"); + useEffect(() => { let connection = connectionTypes.find( (item) => item.value === formValue?.type @@ -93,35 +97,72 @@ export default function ConnectionFormModal({ connectionType; return ( -
- - {typeof connectionType?.icon === "string" ? ( - - ) : ( - connectionType.icon - )} -
- {connectionType.title} Connection Details -
+ + {typeof connectionType?.icon === "string" ? ( + + ) : ( + connectionType.icon + )} +
+ {connectionType.title} Connection Details
- ) : ( -
Select Connection Type
- ) - } - onClose={() => { - setIsOpen(false); - }} - open={isOpen} - bodyClass="flex flex-col w-full flex-1 h-full overflow-y-auto" - helpLink="reference/connections/" - > - {type ? ( +
+ ) : ( +
Select Connection Type
+ ) + } + onClose={() => { + setIsOpen(false); + }} + open={isOpen} + size="full" + bodyClass="flex flex-col w-full flex-1 h-full overflow-y-auto" + helpLink="reference/connections/" + containerClassName="h-full overflow-auto" + > + {type ? ( + formValue?.id ? ( + setActiveTab(label)} + > + + setConnectionType(undefined)} + connectionType={type} + onConnectionSubmit={onConnectionSubmit} + onConnectionDelete={onConnectionDelete} + formValue={formValue} + className={className} + isSubmitting={isSubmitting} + isDeleting={isDeleting} + /> + + + + + + + ) : ( setConnectionType(undefined)} connectionType={type} @@ -132,20 +173,20 @@ export default function ConnectionFormModal({ isSubmitting={isSubmitting} isDeleting={isDeleting} /> - ) : formValue?.id ? ( - setConnectionType(undefined)} - onConnectionSubmit={onConnectionSubmit} - onConnectionDelete={onConnectionDelete} - formValue={formValue} - className={className} - 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/Playbooks/Settings/PlaybookSpecFormModal.tsx b/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx index 56ed61354..5ddfb9848 100644 --- a/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx +++ b/src/components/Playbooks/Settings/PlaybookSpecFormModal.tsx @@ -1,5 +1,8 @@ import { PlaybookSpec } from "@flanksource-ui/api/types/playbooks"; +import PermissionsView from "@flanksource-ui/components/Permissions/PermissionsView"; import { Modal } from "@flanksource-ui/ui/Modal"; +import { Tab, Tabs } from "@flanksource-ui/ui/Tabs/Tabs"; +import { useState } from "react"; import PlaybookSpecModalTitle from "../PlaybookSpecModalTitle"; import PlaybookSpecsForm from "./PlaybookSpecsForm"; @@ -16,6 +19,8 @@ export default function PlaybookSpecFormModal({ onClose, ...props }: PlaybookSpecFormModalProps) { + const [activeTab, setActiveTab] = useState<"form" | "permissions">("form"); + return ( - + {playbook?.id ? ( + setActiveTab(label)} + > + + + + + + + + + ) : ( + + )} ); } diff --git a/src/pages/Settings/ConnectionsPage.tsx b/src/pages/Settings/ConnectionsPage.tsx index d943b4e21..edba37bb7 100644 --- a/src/pages/Settings/ConnectionsPage.tsx +++ b/src/pages/Settings/ConnectionsPage.tsx @@ -158,18 +158,17 @@ export function ConnectionsPage() { setEditedRow(val); }} /> - - deleteConnection(data)} - isSubmitting={isSubmitting} - isDeleting={isDeleting} - formValue={editedRow} - key={editedRow?.id || "connection-form"} - /> + deleteConnection(data)} + isSubmitting={isSubmitting} + isDeleting={isDeleting} + formValue={editedRow} + key={editedRow?.id || "connection-form"} + /> );