import React from 'react'; import { JSONTree, NoContent, Button, Tabs, Icon } from 'UI'; import cn from 'classnames'; import stl from './fetchDetails.module.css'; import Headers from './components/Headers'; import AnimatedSVG, { ICONS } from 'Shared/AnimatedSVG/AnimatedSVG'; import { TYPES } from 'Types/session/resource'; import { formatBytes } from 'App/utils'; import CopyText from 'Shared/CopyText'; const HEADERS = 'HEADERS'; const REQUEST = 'REQUEST'; const RESPONSE = 'RESPONSE'; const TABS = [HEADERS, REQUEST, RESPONSE].map((tab) => ({ text: tab, key: tab })); export default class FetchDetailsModal extends React.PureComponent { state = { activeTab: REQUEST, tabs: [] }; onTabClick = (activeTab) => this.setState({ activeTab }); componentDidMount() { this.checkTabs(); } renderActiveTab = (tab) => { const { resource: { payload, response = this.props.resource.body }, } = this.props; let jsonPayload, jsonResponse, requestHeaders, responseHeaders = undefined; try { jsonPayload = typeof payload === 'string' ? JSON.parse(payload) : payload; requestHeaders = jsonPayload.headers; jsonPayload.body = typeof jsonPayload.body === 'string' ? JSON.parse(jsonPayload.body) : jsonPayload.body; delete jsonPayload.headers; } catch (e) {} try { jsonResponse = typeof response === 'string' ? JSON.parse(response) : response; responseHeaders = jsonResponse.headers; jsonResponse.body = typeof jsonResponse.body === 'string' ? JSON.parse(jsonResponse.body) : jsonResponse.body; delete jsonResponse.headers; } catch (e) {} switch (tab) { case REQUEST: return (
Body is Empty.
} size="small" show={!payload} // animatedIcon="no-results" >
{jsonPayload === undefined ? (
{payload}
) : ( )}
); case RESPONSE: return (
Body is Empty.
} size="small" show={!response} // animatedIcon="no-results" >
{jsonResponse === undefined ? (
{response}
) : ( )}
); case HEADERS: return ; } }; componentDidUpdate(prevProps) { if (prevProps.resource.index === this.props.resource.index) return; this.checkTabs(); } checkTabs() { const { resource: { payload, response, body }, isResult, } = this.props; const _tabs = TABS; // const _tabs = TABS.filter(t => { // if (t.key == REQUEST && !!payload) { // return true // } // if (t.key == RESPONSE && !!response) { // return true; // } // return false; // }) this.setState({ tabs: _tabs, activeTab: _tabs.length > 0 ? _tabs[0].key : null }); } render() { const { resource, fetchPresented, nextClick, prevClick, first = false, last = false, } = this.props; const { method, url, duration } = resource; const { activeTab, tabs } = this.state; const _duration = parseInt(duration); return (
Network Request
Name
{resource.name}
Type
{resource.type}
{!!resource.decodedBodySize && (
Size
{formatBytes(resource.decodedBodySize)}
)} {method && (
Request Method
{resource.method}
)} {resource.status && (
Status
{resource.status === '200' && (
)} {resource.status}
)} {!!_duration && (
Time
{_duration} ms
)} {resource.type === TYPES.XHR && !fetchPresented && (
Get more out of network requests
  • Integrate{' '} Fetch plugin {' '} to capture fetch payloads.
  • Find a detailed{' '} video tutorial {' '} to understand practical example of how to use fetch plugin.
)}
{resource.type === TYPES.XHR && fetchPresented && (
{this.renderActiveTab(activeTab)}
)} {/*
*/}
); } }