import React from 'react'; import find from 'lodash/find'; import filter from 'lodash/filter'; import classnames from 'classnames'; import { IconHome2 } from '@tabler/icons'; import { useStore } from 'providers/Store'; import actions from 'providers/Store/actions'; import CollectionToolBar from './CollectionToolBar'; import StyledWrapper from './StyledWrapper'; const RequestTabs = () => { const [store, storeDispatch] = useStore(); const { collections, requestTabs, activeRequestTabUid } = store; const getTabClassname = (tab, index) => { return classnames("request-tab select-none", { 'active': tab.uid === activeRequestTabUid, 'last-tab': requestTabs && requestTabs.length && (index === requestTabs.length - 1) }); }; const getMethodColor = (method) => { let color = ''; switch(method) { case 'GET': { color = 'rgb(5, 150, 105)'; break; } case 'POST': { color = '#8e44ad'; break; } } return color; }; const handleClick = (tab) => { storeDispatch({ type: actions.REQUEST_TAB_CLICK, requestTab: tab }); }; const handleCloseClick = (event, tab) => { event.stopPropagation(); event.preventDefault(); storeDispatch({ type: actions.REQUEST_TAB_CLOSE, requestTab: tab }); }; const createNewTab = () => { storeDispatch({ type: actions.ADD_NEW_HTTP_REQUEST }); }; if(!activeRequestTabUid) { return null; } const activeRequestTab = find(requestTabs, (t) => t.uid === activeRequestTabUid); if(!activeRequestTab) { return ( Something went wrong! ); } const activeCollection = find(collections, (c) => c.uid === activeRequestTab.collectionUid); const collectionRequestTabs = filter(requestTabs, (t) => t.collectionUid === activeRequestTab.collectionUid); return ( {collectionRequestTabs && collectionRequestTabs.length ? ( <> {collectionRequestTabs && collectionRequestTabs.length ? collectionRequestTabs.map((rt, index) => { return handleClick(rt)}> {rt.method} {rt.name} handleCloseClick(e, rt)}> {!rt.hasChanges ? ( ) : ( ) } }) : null} > ) : null} ); }; export default RequestTabs;