import { useEffect } from "react"; import { subject } from "@casl/ability"; import { useSortable } from "@dnd-kit/sortable"; import { faFileImport, faFolder, faKey, faUpDown, faXmark } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { ProjectPermissionCan } from "@app/components/permissions"; import { EmptyState, IconButton, SecretInput, TableContainer, Tooltip } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context"; import { useToggle } from "@app/hooks"; type Props = { onDelete: (environment: string, secretPath: string) => void; environment: string; secretPath: string; importedEnv: string; importedSecPath: string; importedSecrets: { key: string; value: string; overriden: { env: string; secretPath: string } }[]; searchTerm: string; }; // to show the environment and folder icon export const EnvFolderIcon = ({ env, secretPath }: { env: string; secretPath: string }) => (
{env || "-"}
{secretPath && (
{secretPath}
)}
); export const SecretImportItem = ({ importedEnv, importedSecPath, onDelete, importedSecrets = [], searchTerm = "", secretPath, environment }: Props) => { const [isExpanded, setIsExpanded] = useToggle(); const { attributes, listeners, transform, transition, setNodeRef, isDragging } = useSortable({ id: `${importedEnv}-${importedSecPath}` }); const { currentWorkspace } = useWorkspace(); const rowEnv = currentWorkspace?.environments?.find(({ slug }) => slug === importedEnv); useEffect(() => { const filteredSecrets = importedSecrets.filter((secret) => secret.key.toUpperCase().includes(searchTerm.toUpperCase()) ); if (filteredSecrets.length > 0 && searchTerm) { setIsExpanded.on(); } else { setIsExpanded.off(); } }, [searchTerm]); useEffect(() => { if (isDragging) { setIsExpanded.off(); } }, [isDragging]); const style = { transform: transform ? `translateY(${transform.y ? Math.round(transform.y) : 0}px)` : "", transition }; return ( <> setIsExpanded.toggle()} >
{(isAllowed) => (
{ evt.stopPropagation(); onDelete(importedEnv, importedSecPath); }} >
)}
{isExpanded && !isDragging && (
{importedSecrets?.length === 0 && ( )} {importedSecrets .filter((secret) => secret.key.toUpperCase().includes(searchTerm.toUpperCase()) ) .map(({ key, value, overriden }, index) => ( ))}
Key Value Override
{key}
)} ); };