import React from 'react'; import find from 'lodash/find'; import classnames from 'classnames'; import { useDispatch, useSelector } from 'react-redux'; import { getContentType, formatResponse } from 'utils/common'; 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 Timeline from './Timeline'; import TestResults from './TestResults'; import TestResultsLabel from './TestResultsLabel'; import StyledWrapper from './StyledWrapper'; const ResponsePane = ({ rightPaneWidth, item, collection }) => { const dispatch = useDispatch(); const tabs = useSelector((state) => state.tabs.tabs); const activeTabUid = useSelector((state) => state.tabs.activeTabUid); const isLoading = ['queued', 'sending'].includes(item.requestState); 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 ; } case 'timeline': { return ; } case 'tests': { 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 occurred!
; } const getTabClassname = (tabName) => { return classnames(`tab select-none ${tabName}`, { active: tabName === focusedTab.responsePaneTab }); }; return (
selectTab('response')}> Response
selectTab('headers')}> Headers
selectTab('timeline')}> Timeline
selectTab('tests')}>
{!isLoading ? (
) : null}
{getTabPanel(focusedTab.responsePaneTab)}
); }; export default ResponsePane;