From 8055129dd2cc95e1cbaf184860b8db1952788c3a Mon Sep 17 00:00:00 2001 From: Helder Sepulveda Date: Thu, 3 May 2018 20:33:21 -0400 Subject: [PATCH] Improve downloadable HighlightCode filename (#4508) * Update highlight-code.jsx * improve filename no more response.txt * use new `fileName` prop for file names * use template strings for `fileName` prop values * fall back to old "response.txt" file name if none is provided --- src/core/components/highlight-code.jsx | 5 +++-- src/core/components/response-body.jsx | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/components/highlight-code.jsx b/src/core/components/highlight-code.jsx index bbdda2d0..c0feb7f9 100644 --- a/src/core/components/highlight-code.jsx +++ b/src/core/components/highlight-code.jsx @@ -7,7 +7,8 @@ export default class HighlightCode extends Component { static propTypes = { value: PropTypes.string.isRequired, className: PropTypes.string, - downloadable: PropTypes.bool + downloadable: PropTypes.bool, + fileName: PropTypes.string } componentDidMount() { @@ -23,7 +24,7 @@ export default class HighlightCode extends Component { } downloadText = () => { - saveAs(this.props.value, "response.txt") + saveAs(this.props.value, this.props.fileName || "response.txt") } preventYScrollingBeyondElement = (e) => { diff --git a/src/core/components/response-body.jsx b/src/core/components/response-body.jsx index fd5eaa94..cce5773f 100644 --- a/src/core/components/response-body.jsx +++ b/src/core/components/response-body.jsx @@ -52,6 +52,7 @@ export default class ResponseBody extends React.PureComponent { let { content, contentType, url, headers={}, getComponent } = this.props const { parsedContent } = this.state const HighlightCode = getComponent("highlightCode") + const downloadName = "response_" + new Date().getTime() let body, bodyEl url = url || "" @@ -100,7 +101,7 @@ export default class ResponseBody extends React.PureComponent { body = "can't parse JSON. Raw result:\n\n" + content } - bodyEl = + bodyEl = // XML } else if (/xml/i.test(contentType)) { @@ -108,11 +109,11 @@ export default class ResponseBody extends React.PureComponent { textNodesOnSameLine: true, indentor: " " }) - bodyEl = + bodyEl = // HTML or Plain Text } else if (lowerCase(contentType) === "text/html" || /text\/plain/.test(contentType)) { - bodyEl = + bodyEl = // Image } else if (/^image\//i.test(contentType)) { @@ -126,7 +127,7 @@ export default class ResponseBody extends React.PureComponent { } else if (/^audio\//i.test(contentType)) { bodyEl =
} else if (typeof content === "string") { - bodyEl = + bodyEl = } else if ( content.size > 0 ) { // We don't know the contentType, but there was some content returned if(parsedContent) { @@ -136,7 +137,7 @@ export default class ResponseBody extends React.PureComponent {

Unrecognized response type; displaying content as text.

- + } else {