From ee6afa8983e26599658567a30c47801cb01cc395 Mon Sep 17 00:00:00 2001 From: Vladyslav Matsiiako Date: Sun, 8 Oct 2023 17:05:26 -0700 Subject: [PATCH] allowed creating multiple github integrations to different apps at once --- .../components/v2/SecretInput/SecretInput.tsx | 2 +- .../src/pages/integrations/github/create.tsx | 107 +++++++++++------- .../SecretApprovalPage/SecretApprovalPage.tsx | 2 +- 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/frontend/src/components/v2/SecretInput/SecretInput.tsx b/frontend/src/components/v2/SecretInput/SecretInput.tsx index c09061c4f..314dada0c 100644 --- a/frontend/src/components/v2/SecretInput/SecretInput.tsx +++ b/frontend/src/components/v2/SecretInput/SecretInput.tsx @@ -22,7 +22,7 @@ const sanitizeConf = { const syntaxHighlight = (content?: string | null, isVisible?: boolean) => { if (content === "") return "EMPTY"; - if (!content) return "missing"; + if (!content) return "EMPTY"; if (!isVisible) return replaceContentWithDot(content); const sanitizedContent = sanitizeHtml( diff --git a/frontend/src/pages/integrations/github/create.tsx b/frontend/src/pages/integrations/github/create.tsx index bdc1579f7..ce0ec7858 100644 --- a/frontend/src/pages/integrations/github/create.tsx +++ b/frontend/src/pages/integrations/github/create.tsx @@ -3,7 +3,7 @@ import Head from "next/head"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/router"; -import { faArrowUpRightFromSquare, faBookOpen, faBugs, faCircleInfo } from "@fortawesome/free-solid-svg-icons"; +import { faAngleDown, faArrowUpRightFromSquare, faBookOpen, faBugs, faCheckCircle, faCircleInfo } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { motion } from "framer-motion"; import queryString from "query-string"; @@ -16,6 +16,10 @@ import { Button, Card, CardTitle, + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, FormControl, Input, Select, @@ -50,7 +54,7 @@ export default function GitHubCreateIntegrationPage() { const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState(""); const [secretPath, setSecretPath] = useState("/"); - const [targetAppId, setTargetAppId] = useState(""); + const [targetAppIds, setTargetAppIds] = useState([]); const [secretSuffix, setSecretSuffix] = useState(""); const [isLoading, setIsLoading] = useState(false); @@ -64,9 +68,9 @@ export default function GitHubCreateIntegrationPage() { useEffect(() => { if (integrationAuthApps) { if (integrationAuthApps.length > 0) { - setTargetAppId(integrationAuthApps[0].appId as string); + setTargetAppIds([String(integrationAuthApps[0].appId)]); } else { - setTargetAppId("none"); + setTargetAppIds(["none"]); } } }, [integrationAuthApps]); @@ -77,23 +81,27 @@ export default function GitHubCreateIntegrationPage() { if (!integrationAuth?._id) return; - const targetApp = integrationAuthApps?.find( - (integrationAuthApp) => integrationAuthApp.appId === targetAppId + const targetApps = integrationAuthApps?.filter( + (integrationAuthApp) => targetAppIds.includes(String(integrationAuthApp.appId)) ); - if (!targetApp || !targetApp.owner) return; + if (!targetApps) return; - await mutateAsync({ - integrationAuthId: integrationAuth?._id, - isActive: true, - app: targetApp.name, - sourceEnvironment: selectedSourceEnvironment, - owner: targetApp.owner, - secretPath, - metadata: { - secretSuffix - } - }); + await Promise.all( + targetApps.map(async (targetApp) => { + await mutateAsync({ + integrationAuthId: integrationAuth?._id, + isActive: true, + app: targetApp.name, + sourceEnvironment: selectedSourceEnvironment, + owner: targetApp.owner, + secretPath, + metadata: { + secretSuffix + } + }) + }) + ); setIsLoading(false); router.push(`/integrations/${localStorage.getItem("projectData.id")}`); @@ -106,7 +114,7 @@ export default function GitHubCreateIntegrationPage() { workspace && selectedSourceEnvironment && integrationAuthApps && - targetAppId ? ( + targetAppIds ? (
Set Up GitHub Integration @@ -177,27 +185,42 @@ export default function GitHubCreateIntegrationPage() { /> - + + + {(integrationAuthApps.length > 0) ?
+ {targetAppIds.length === 1 ? integrationAuthApps?.find( + (integrationAuthApp) => targetAppIds[0] === String(integrationAuthApp.appId) + )?.name : `${targetAppIds.length} repositories selected`} + +
:
+ No repositories found +
} +
+ + {(integrationAuthApps.length > 0) ? ( + integrationAuthApps.map((integrationAuthApp) => { + const isSelected = targetAppIds.includes(String(integrationAuthApp.appId)); + + return ( + { + if (targetAppIds.includes(String(integrationAuthApp.appId))) { + setTargetAppIds(targetAppIds.filter((appId) => appId !== String(integrationAuthApp.appId))); + } else { + setTargetAppIds([...targetAppIds, String(integrationAuthApp.appId)]); + } + }} + key={integrationAuthApp.appId} + icon={isSelected ? :
} + iconPos="left" + className="w-[28.4rem] text-sm" + > + {integrationAuthApp.name} + + )}) + ) :
} + + @@ -223,9 +246,9 @@ export default function GitHubCreateIntegrationPage() { onClick={handleButtonClick} color="mineshaft" variant="outline_bg" - className="mt-2 mb-6 ml-auto mr-6" + className="mb-6 ml-auto mr-6" isLoading={isLoading} - isDisabled={integrationAuthApps.length === 0} + isDisabled={integrationAuthApps.length === 0 || targetAppIds.length === 0} > Create Integration diff --git a/frontend/src/views/SecretApprovalPage/SecretApprovalPage.tsx b/frontend/src/views/SecretApprovalPage/SecretApprovalPage.tsx index c6e229970..c2c05310c 100644 --- a/frontend/src/views/SecretApprovalPage/SecretApprovalPage.tsx +++ b/frontend/src/views/SecretApprovalPage/SecretApprovalPage.tsx @@ -14,7 +14,7 @@ export const SecretApprovalPage = () => { const workspaceId = currentWorkspace?._id || ""; return ( -
+

Secret Approvals