import React, {PropTypes, PureComponent} from 'react';
import RawEditor from './RawEditor';
import UrlEncodedEditor from './UrlEncodedEditor';
import FormEditor from './FormEditor';
import FileEditor from './FileEditor';
import {getContentTypeFromHeaders, CONTENT_TYPE_FORM_URLENCODED, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FILE} from '../../../../common/constants';
import {newBodyRaw, newBodyFormUrlEncoded, newBodyForm, newBodyFile} from '../../../../models/request';
class BodyEditor extends PureComponent {
_handleRawChange = (rawValue) => {
const {onChange, request} = this.props;
const contentType = getContentTypeFromHeaders(request.headers);
const newBody = newBodyRaw(rawValue, contentType || '');
onChange(newBody);
};
_handleFormUrlEncodedChange = (parameters) => {
const {onChange} = this.props;
const newBody = newBodyFormUrlEncoded(parameters);
onChange(newBody);
};
_handleFormChange = (parameters) => {
const {onChange} = this.props;
const newBody = newBodyForm(parameters);
onChange(newBody);
};
_handleFileChange = (path) => {
const {onChange} = this.props;
const newBody = newBodyFile(path);
onChange(newBody);
};
render () {
const {keyMap, fontSize, lineWrapping, request} = this.props;
const fileName = request.body.fileName;
const mimeType = request.body.mimeType;
const isBodyEmpty = typeof mimeType !== 'string' && !request.body.text;
if (mimeType === CONTENT_TYPE_FORM_URLENCODED) {
return (
Select a body type from above