import React, {Component} from 'react'; import HTTPSnippet, {availableTargets} from 'httpsnippet'; import CopyButton from '../base/CopyButton'; import Dropdown from '../base/Dropdown'; import Editor from '../base/Editor'; import Modal from '../base/Modal'; import ModalBody from '../base/ModalBody'; import ModalHeader from '../base/ModalHeader'; import ModalFooter from '../base/ModalFooter'; import {exportHar} from '../../lib/export/har'; const DEFAULT_TARGET = availableTargets().find(t => t.key === 'shell'); const DEFAULT_CLIENT = DEFAULT_TARGET.clients.find(t => t.key === 'curl'); const MODE_MAP = { c: 'clike', java: 'clike', csharp: 'clike', node: 'javascript', objc: 'clike', ocaml: 'mllike' }; class GenerateCodeModal extends Component { constructor (props) { super(props); this.state = { cmd: '', request: null, target: DEFAULT_TARGET, client: DEFAULT_CLIENT }; } _handleClientChange (client) { const {target} = this.state; this._generateCode(this.state.request, target, client); } _handleTargetChange (target) { const {target: currentTarget} = this.state; if (currentTarget.key === target.key) { // No change return; } const client = target.clients.find(c => c.key === target.default); this._generateCode(this.state.request, target, client); } _generateCode (request, target, client) { exportHar(request._id).then(har => { const snippet = new HTTPSnippet(har); const cmd = snippet.convert(target.key, client.key); this.setState({request, cmd, client, target}); }); } show (request) { this.modal.show(); this._generateCode(request, DEFAULT_TARGET, DEFAULT_CLIENT); } render () { const {cmd, target, client} = this.state; const targets = availableTargets(); return ( this.modal = m} tall={true} {...this.props}> Generate Client Code
    {targets.map(target => (
  • ))}
  
    {target.clients.map(client => (
  • ))}
  
this._editor = n} lightTheme={true} lineWrapping={true} value={cmd} />
* copy/paste this command into a Unix terminal
); } } GenerateCodeModal.propTypes = {}; export default GenerateCodeModal;