2022-01-01 10:07:34 +01:00
|
|
|
import React, { forwardRef, useRef } from 'react';
|
2022-01-01 17:56:56 +01:00
|
|
|
import { IconChevronRight, IconDots, IconWorld } from '@tabler/icons';
|
2021-12-03 20:37:38 +01:00
|
|
|
import CollectionItem from './CollectionItem';
|
2022-01-01 10:07:34 +01:00
|
|
|
import Dropdown from '../../../Dropdown';
|
|
|
|
import get from 'lodash/get';
|
2021-12-03 20:37:38 +01:00
|
|
|
import classnames from 'classnames';
|
|
|
|
|
|
|
|
import StyledWrapper from './StyledWrapper';
|
|
|
|
|
|
|
|
const Collection = ({collection, actions, dispatch, activeRequestTabId}) => {
|
2022-01-01 10:07:34 +01:00
|
|
|
const envDropdownTippyRef = useRef();
|
|
|
|
const onEnvDropdownCreate = (ref) => envDropdownTippyRef.current = ref;
|
|
|
|
const EnvIcon = forwardRef((props, ref) => {
|
|
|
|
return (
|
|
|
|
<div ref={ref} className="mr-2">
|
2022-01-01 17:56:56 +01:00
|
|
|
<IconWorld size={18} strokeWidth={1.5}/>
|
2022-01-01 10:07:34 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
const menuDropdownTippyRef = useRef();
|
|
|
|
const onMenuDropdownCreate = (ref) => menuDropdownTippyRef.current = ref;
|
|
|
|
const MenuIcon = forwardRef((props, ref) => {
|
|
|
|
return (
|
|
|
|
<div ref={ref}>
|
|
|
|
<IconDots size={22}/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
2021-12-03 20:37:38 +01:00
|
|
|
|
|
|
|
const iconClassName = classnames({
|
|
|
|
'rotate-90': collection.collapsed
|
|
|
|
});
|
|
|
|
|
2022-01-01 10:07:34 +01:00
|
|
|
const handleClick = (event) => {
|
|
|
|
let envTippyEl = get(envDropdownTippyRef, 'current.reference');
|
|
|
|
if(envTippyEl && envTippyEl.contains && envTippyEl.contains(event.target)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-03 20:37:38 +01:00
|
|
|
dispatch({
|
|
|
|
type: actions.SIDEBAR_COLLECTION_CLICK,
|
|
|
|
id: collection.id
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StyledWrapper className="flex flex-col">
|
|
|
|
<div className="flex py-1 collection-name items-center" onClick={handleClick}>
|
|
|
|
<IconChevronRight size={16} strokeWidth={2} className={iconClassName} style={{width:16, color: 'rgb(160 160 160)'}}/>
|
|
|
|
<span className="ml-1">{collection.name}</span>
|
2022-01-01 10:07:34 +01:00
|
|
|
<div className="collection-actions">
|
|
|
|
<Dropdown onCreate={onEnvDropdownCreate} icon={<EnvIcon />} placement='bottom-start'>
|
|
|
|
<div>
|
|
|
|
<div className="dropdown-item" onClick={(e) => {
|
|
|
|
envDropdownTippyRef.current.hide();
|
|
|
|
}}>
|
|
|
|
No Environment Selected
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dropdown>
|
|
|
|
|
|
|
|
<Dropdown onCreate={onMenuDropdownCreate} icon={<MenuIcon />} placement='bottom-start'>
|
|
|
|
<div>
|
|
|
|
<div className="dropdown-item" onClick={(e) => {
|
|
|
|
menuDropdownTippyRef.current.hide();
|
|
|
|
}}>
|
|
|
|
Add Request
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div className="dropdown-item" onClick={(e) => {
|
|
|
|
menuDropdownTippyRef.current.hide();
|
|
|
|
}}>
|
|
|
|
Add Folder
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
2021-12-03 20:37:38 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
{collection.collapsed ? (
|
|
|
|
<div>
|
|
|
|
{collection.items && collection.items.length ? collection.items.map((i) => {
|
|
|
|
return <CollectionItem
|
|
|
|
key={i.name}
|
|
|
|
item={i}
|
|
|
|
collectionId={collection.id}
|
|
|
|
actions={actions}
|
|
|
|
dispatch={dispatch}
|
|
|
|
activeRequestTabId={activeRequestTabId}
|
|
|
|
/>
|
|
|
|
}) : null}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</StyledWrapper>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Collection;
|