insomnia/app/ui/components/viewers/response-timeline-viewer.js
Gregory Schier 10564b56a2 Final prep for v5 launch (#128)
* Version number and changelog scroll

* Fixed CodeMirror tooltip css

* AUtocomplete dropdown styling

* Docker Ubuntu build and some tweaks

* Fix SSL verificatioN

* Don't show SSL data

* Update README

* Fixed URL paste handler

* Import from curl improvements

* Minor things
2017-04-04 16:06:43 -07:00

74 lines
1.7 KiB
JavaScript

import React, {PropTypes, PureComponent} from 'react';
import {shell} from 'electron';
import CodeEditor from '../codemirror/code-editor';
class ResponseTimelineViewer extends PureComponent {
_handleClickLink (link) {
shell.openExternal(link);
}
renderRow (row) {
const {name, value} = row;
let prefix = null;
switch (name) {
case 'HEADER_IN':
prefix = '< ';
break;
case 'DATA_IN':
prefix = '| ';
break;
case 'SSL_DATA_IN':
prefix = '<< ';
break;
case 'HEADER_OUT':
prefix = '> ';
break;
case 'DATA_OUT':
prefix = '| ';
break;
case 'SSL_DATA_OUT':
prefix = '>> ';
break;
case 'TEXT':
prefix = '* ';
break;
}
if (prefix !== null) {
const lines = (value + '').replace(/\n$/, '').split('\n');
const newLines = lines
.filter(l => !l.match(/^\s*$/))
.map(l => `${prefix}${l}`);
return newLines.join('\n');
} else {
return null;
}
}
render () {
const {timeline, editorFontSize, editorLineWrapping} = this.props;
const rows = timeline.map(this.renderRow).filter(r => r !== null).join('\n');
return (
<CodeEditor
hideLineNumbers
readOnly
onClickLink={this._handleClickLink}
defaultValue={rows}
fontSize={editorFontSize}
lineWrapping={editorLineWrapping}
className="pad-left"
mode="curl"
/>
);
}
}
ResponseTimelineViewer.propTypes = {
timeline: PropTypes.array.isRequired,
editorFontSize: PropTypes.number.isRequired,
editorLineWrapping: PropTypes.bool.isRequired
};
export default ResponseTimelineViewer;