import React, { useState, forwardRef, useRef } from 'react'; import get from 'lodash/get'; import classnames from 'classnames'; import { IconChevronRight, IconDots } from '@tabler/icons'; import Dropdown from 'components/Dropdown'; import actions from 'providers/Store/actions' import { useStore } from 'providers/Store'; import AddFolder from 'components/Sidebar/AddFolder'; import CollectionItem from './CollectionItem'; import StyledWrapper from './StyledWrapper'; const Collection = ({collection}) => { const [showAddFolderModal, setShowAddFolderModal] = useState(false); const [store, storeDispatch] = useStore(); const { activeRequestTabId } = store; const menuDropdownTippyRef = useRef(); const onMenuDropdownCreate = (ref) => menuDropdownTippyRef.current = ref; const MenuIcon = forwardRef((props, ref) => { return (
); }); const iconClassName = classnames({ 'rotate-90': collection.collapsed }); const handleClick = (event) => { let envTippyEl = get(menuDropdownTippyRef, 'current.reference'); if(envTippyEl && envTippyEl.contains && envTippyEl.contains(event.target)) { return; } storeDispatch({ type: actions.SIDEBAR_COLLECTION_CLICK, collectionUid: collection.uid }); }; const hideAddFolderModal = () => setShowAddFolderModal(false); const collectionItems = get(collection, 'current.items'); return ( {showAddFolderModal && ( )}
{collection.current.name}
} placement='bottom-start'>
{ menuDropdownTippyRef.current.hide(); }}> Add Request
{ menuDropdownTippyRef.current.hide(); setShowAddFolderModal(true) }}> Add Folder
{collection.collapsed ? (
{collectionItems && collectionItems.length ? collectionItems.map((i) => { return }) : null}
) : null}
); }; export default Collection;