From 729c75112b3590dba3f616b65afd2332e7d04379 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Tue, 23 Apr 2024 10:26:41 +0800 Subject: [PATCH] adjustment: deleted unused reference select component --- .../v2/SecretInput/SecretReferenceSelect.tsx | 211 ------------------ 1 file changed, 211 deletions(-) delete mode 100644 frontend/src/components/v2/SecretInput/SecretReferenceSelect.tsx diff --git a/frontend/src/components/v2/SecretInput/SecretReferenceSelect.tsx b/frontend/src/components/v2/SecretInput/SecretReferenceSelect.tsx deleted file mode 100644 index da8cff98f..000000000 --- a/frontend/src/components/v2/SecretInput/SecretReferenceSelect.tsx +++ /dev/null @@ -1,211 +0,0 @@ -import React, { useEffect, useState } from "react"; -import { - faCaretDown, - faCaretUp, - faChevronRight, - faFolder, - faKey, - faRecycle -} from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import * as SelectPrimitive from "@radix-ui/react-select"; -import { twMerge } from "tailwind-merge"; - -import { useWorkspace } from "@app/context"; -import { useGetUserWsKey } from "@app/hooks/api"; -import { useGetFoldersByEnv } from "@app/hooks/api/secretFolders/queries"; -import { useGetProjectSecrets } from "@app/hooks/api/secrets/queries"; - -type ReferenceType = "environment" | "folder" | "secret"; - -type Props = { - open: boolean; - reference?: string; - secretPath?: string; - environment?: string; - handleOpenChange: (params: boolean) => void; - onEscapeKeyDown: () => void; - onSelect: (params: { type: ReferenceType; name: string; slug?: string }) => void; -}; - -type ReferenceItem = { - name: string; - type: "folder" | "secret"; - slug?: string; -}; - -export default function SecretReferenceSelect({ - open, - secretPath: propSecretPath, - environment: propEnvironment, - handleOpenChange, - reference, - onSelect, - onEscapeKeyDown -}: Props) { - const { currentWorkspace } = useWorkspace(); - const [listReference, setListReference] = useState([]); - const [secretPath, setSecretPath] = useState(propSecretPath || "/"); - const [environment, setEnvironment] = useState(propEnvironment); - const workspaceId = currentWorkspace?.id || ""; - const { data: decryptFileKey } = useGetUserWsKey(workspaceId); - const { data: secrets } = useGetProjectSecrets({ - decryptFileKey: decryptFileKey!, - environment: environment || currentWorkspace?.environments?.[0].slug!, - secretPath, - workspaceId - }); - const { folderNames: folders } = useGetFoldersByEnv({ - path: secretPath, - environments: [environment || currentWorkspace?.environments?.[0].slug!], - projectId: workspaceId - }); - - useEffect(() => { - let currentEnvironment = propEnvironment; - let currentSecretPath = propSecretPath || "/"; - - if (!reference) { - setSecretPath(currentSecretPath); - setEnvironment(currentEnvironment!); - return; - } - - const isNested = reference.includes("."); - - if (isNested) { - const [envSlug, ...folderPaths] = reference.split("."); - const isValidEnvSlug = currentWorkspace?.environments.find((e) => e.slug === envSlug); - currentEnvironment = isValidEnvSlug ? envSlug : undefined; - currentSecretPath = `/${folderPaths?.join("/")}` || "/"; - } - - setSecretPath(currentSecretPath); - setEnvironment(currentEnvironment); - }, [reference]); - - useEffect(() => { - const currentListReference: ReferenceItem[] = []; - const isNested = reference?.includes("."); - - if (!environment) { - setListReference(currentListReference); - return; - } - - if (isNested) { - folders?.forEach((folder) => { - currentListReference.unshift({ name: folder, type: "folder" }); - }); - } - - secrets?.forEach((secret) => { - currentListReference.unshift({ name: secret.key, type: "secret" }); - }); - - setListReference(currentListReference); - }, [secrets, environment, reference]); - - return ( - onSelect(JSON.parse(str))} - > - - -
- - - - - - -
- -
-
- - - {listReference.map((e, i) => { - return ( - - -
-
-
- -
-
{e.name}
-
- {e.type === "folder" && ( -
- -
- )} -
-
-
- ); - })} - - {listReference.length !== 0 && ( - - )} -
- - - - All Secrets - - - {currentWorkspace?.environments.map((env, i) => ( - - -
-
-
- -
-
{env.name}
-
-
- -
-
-
-
- ))} -
-
- -
- -
-
-
-
- - ); -}