From 12a2c0ee70514c2e616f3a367783a2e9c904b811 Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Tue, 16 Oct 2018 03:53:50 -0700 Subject: [PATCH] Add option to display network response as copyable json Summary: This is meant to reduce the friction of getting network response payloads. Simple switch allows developers to go to "formatted" body ui which shows the json in a text blob. Reviewed By: passy Differential Revision: D10378877 fbshipit-source-id: 87aeff5318f0c2c6d3d91d7e3b491595794e69bf --- src/plugins/network/RequestDetails.js | 122 +++++++++++++++++++++++--- 1 file changed, 111 insertions(+), 11 deletions(-) diff --git a/src/plugins/network/RequestDetails.js b/src/plugins/network/RequestDetails.js index 4ada6bdf5..e186b84cf 100644 --- a/src/plugins/network/RequestDetails.js +++ b/src/plugins/network/RequestDetails.js @@ -12,10 +12,12 @@ import type {Request, Response, Header} from './index.js'; import { Component, FlexColumn, + FlexRow, ManagedTable, ManagedDataInspector, Text, Panel, + Select, styled, colors, } from 'flipper'; @@ -51,6 +53,10 @@ type RequestDetailsProps = { response: ?Response, }; +type RequestDetailsState = { + bodyFormat: string, +}; + function decodeBody(container: Request | Response): string { if (!container.data) { return ''; @@ -83,11 +89,20 @@ function decompress(body: string): string { return String.fromCharCode.apply(null, new Uint8Array(data)); } -export default class RequestDetails extends Component { +export default class RequestDetails extends Component< + RequestDetailsProps, + RequestDetailsState, +> { static Container = styled(FlexColumn)({ height: '100%', overflow: 'auto', }); + static BodyOptions = { + formatted: 'formatted', + parsed: 'parsed', + }; + + state: RequestDetailsState = {bodyFormat: RequestDetails.BodyOptions.parsed}; urlColumns = (url: URL) => { return [ @@ -134,10 +149,17 @@ export default class RequestDetails extends Component { ]; }; + onSelectFormat = (bodyFormat: string) => { + this.setState(() => ({bodyFormat})); + }; + render() { const {request, response} = this.props; const url = new URL(request.url); + const {bodyFormat} = this.state; + const formattedText = bodyFormat == RequestDetails.BodyOptions.formatted; + return ( @@ -168,11 +190,16 @@ export default class RequestDetails extends Component { ) : null} {request.data != null ? ( - - + + ) : null} - {response ? [ response.headers.length > 0 ? ( @@ -183,11 +210,28 @@ export default class RequestDetails extends Component { ) : null, - - + + , ] : null} + + + Body: +