import React from 'react'; import find from 'lodash/find'; import classnames from 'classnames'; import { useSelector, useDispatch } from 'react-redux'; import { updateResponsePaneTab } from 'providers/ReduxStore/slices/tabs'; import QueryResult from './QueryResult'; import Overlay from './Overlay'; import Placeholder from './Placeholder'; import ResponseHeaders from './ResponseHeaders'; import StatusCode from './StatusCode'; import ResponseTime from './ResponseTime'; import ResponseSize from './ResponseSize'; import StyledWrapper from './StyledWrapper'; const ResponsePane = ({rightPaneWidth, item, isLoading}) => { const dispatch = useDispatch(); const tabs = useSelector((state) => state.tabs.tabs); const activeTabUid = useSelector((state) => state.tabs.activeTabUid); const selectTab = (tab) => { dispatch(updateResponsePaneTab({ uid: item.uid, responsePaneTab: tab })) }; const response = item.response || {}; const getTabPanel = (tab) => { switch(tab) { case 'response': { return ( ); } case 'headers': { return ( ); } default: { return
404 | Not found
; } } }; if(isLoading) { return ( ); } if(response.state !== 'success') { return ( ); } if(!activeTabUid) { return (
Something went wrong
); } const focusedTab = find(tabs, (t) => t.uid === activeTabUid); if(!focusedTab || !focusedTab.uid || !focusedTab.responsePaneTab) { return (
An error occured!
); } const getTabClassname = (tabName) => { return classnames(`tab select-none ${tabName}`, { 'active': tabName === focusedTab.responsePaneTab }); }; return (
selectTab('response')}>Response
selectTab('headers')}>Headers
{!isLoading ? (
) : null }
{getTabPanel(focusedTab.responsePaneTab)}
) }; export default ResponsePane;