2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-28 22:45:23 +00:00
|
|
|
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;
|
|
|
|
|
2017-03-29 02:21:49 +00:00
|
|
|
let prefix = null;
|
2017-03-28 22:45:23 +00:00
|
|
|
switch (name) {
|
|
|
|
case 'HEADER_IN':
|
2017-03-29 02:21:49 +00:00
|
|
|
prefix = '< ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
case 'DATA_IN':
|
2017-03-29 02:21:49 +00:00
|
|
|
prefix = '| ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
case 'SSL_DATA_IN':
|
2017-04-04 23:06:43 +00:00
|
|
|
prefix = '<< ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
case 'HEADER_OUT':
|
2017-03-29 02:21:49 +00:00
|
|
|
prefix = '> ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
case 'DATA_OUT':
|
2017-03-29 02:21:49 +00:00
|
|
|
prefix = '| ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
case 'SSL_DATA_OUT':
|
2017-04-04 23:06:43 +00:00
|
|
|
prefix = '>> ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
case 'TEXT':
|
2017-03-29 02:21:49 +00:00
|
|
|
prefix = '* ';
|
2017-03-28 22:45:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-29 02:21:49 +00:00
|
|
|
if (prefix !== null) {
|
2017-03-28 22:45:23 +00:00
|
|
|
const lines = (value + '').replace(/\n$/, '').split('\n');
|
|
|
|
const newLines = lines
|
|
|
|
.filter(l => !l.match(/^\s*$/))
|
2017-03-29 02:21:49 +00:00
|
|
|
.map(l => `${prefix}${l}`);
|
2017-03-28 22:45:23 +00:00
|
|
|
return newLines.join('\n');
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-04-14 21:47:15 +00:00
|
|
|
const {timeline, editorFontSize, editorIndentSize, editorLineWrapping} = this.props;
|
2017-03-28 22:45:23 +00:00
|
|
|
const rows = timeline.map(this.renderRow).filter(r => r !== null).join('\n');
|
|
|
|
return (
|
|
|
|
<CodeEditor
|
|
|
|
hideLineNumbers
|
|
|
|
readOnly
|
|
|
|
onClickLink={this._handleClickLink}
|
|
|
|
defaultValue={rows}
|
|
|
|
fontSize={editorFontSize}
|
2017-04-14 21:47:15 +00:00
|
|
|
indentSize={editorIndentSize}
|
2017-03-28 22:45:23 +00:00
|
|
|
lineWrapping={editorLineWrapping}
|
|
|
|
className="pad-left"
|
|
|
|
mode="curl"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ResponseTimelineViewer.propTypes = {
|
|
|
|
timeline: PropTypes.array.isRequired,
|
|
|
|
editorFontSize: PropTypes.number.isRequired,
|
2017-04-14 21:47:15 +00:00
|
|
|
editorIndentSize: PropTypes.number.isRequired,
|
2017-03-28 22:45:23 +00:00
|
|
|
editorLineWrapping: PropTypes.bool.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ResponseTimelineViewer;
|