From 70ca10b423de4a57a395798aa94189ba4da7840f Mon Sep 17 00:00:00 2001 From: Clemens Date: Thu, 21 Jul 2016 19:13:16 +0200 Subject: [PATCH] moved editor to raw_view mode, add content_file_upload --- web/src/js/components/ContentView.jsx | 9 +++---- .../components/ContentView/ContentViews.jsx | 11 ++++---- web/src/js/components/FlowView/Messages.jsx | 18 +++++++++---- web/src/js/components/FlowView/ToggleEdit.jsx | 7 ++--- web/src/js/components/common/CodeEditor.jsx | 4 --- web/src/js/ducks/ui/flow.js | 26 +++++++++++++++++-- 6 files changed, 50 insertions(+), 25 deletions(-) diff --git a/web/src/js/components/ContentView.jsx b/web/src/js/components/ContentView.jsx index 93f16ec07..06272627a 100644 --- a/web/src/js/components/ContentView.jsx +++ b/web/src/js/components/ContentView.jsx @@ -18,7 +18,7 @@ ContentView.propTypes = { ContentView.isContentTooLarge = msg => msg.contentLength > 1024 * 1024 * (ContentViews.ViewImage.matches(msg) ? 10 : 0.2) function ContentView(props) { - const { flow, message, contentView, selectView, displayLarge, setDisplayLarge, onContentChange, readonly, isFlowEditorOpen } = props + const { flow, message, contentView, selectView, displayLarge, setDisplayLarge, uploadContent, onContentChange, readonly } = props if (message.contentLength === 0) { return @@ -38,10 +38,10 @@ function ContentView(props) {
{View.textView ? ( - + ) : ( - + )}
@@ -62,7 +62,7 @@ function ContentView(props) { ref={ref => ContentView.fileInput = ref} className="hidden" type="file" - onChange={e => {if(e.target.files.length > 0) onContentChange(e.target.files[0])}} + onChange={e => {if(e.target.files.length > 0) uploadContent(e.target.files[0])}} />
@@ -73,7 +73,6 @@ export default connect( state => ({ contentView: state.ui.flow.contentView, displayLarge: state.ui.flow.displayLarge, - isFlowEditorOpen : !!state.ui.flow.modifiedFlow // FIXME }), { selectView: setContentView, diff --git a/web/src/js/components/ContentView/ContentViews.jsx b/web/src/js/components/ContentView/ContentViews.jsx index 0eaf3ea81..6c7f49009 100644 --- a/web/src/js/components/ContentView/ContentViews.jsx +++ b/web/src/js/components/ContentView/ContentViews.jsx @@ -29,9 +29,8 @@ ViewRaw.propTypes = { content: React.PropTypes.string.isRequired, } -export function ViewRaw({ content, isFlowEditorOpen, readonly }) { - let showEditor = isFlowEditorOpen && !readonly - return showEditor ? alert(content)}/> :
{content}
+export function ViewRaw({ content, readonly, onChange }) { + return readonly ?
{content}
: } ViewJSON.textView = true @@ -61,12 +60,12 @@ ViewAuto.propTypes = { flow: React.PropTypes.object.isRequired, } -export function ViewAuto({ message, flow }) { +export function ViewAuto({ message, flow, readonly }) { const View = ViewAuto.findView(message) if (View.textView) { - return + return } else { - return + return } } diff --git a/web/src/js/components/FlowView/Messages.jsx b/web/src/js/components/FlowView/Messages.jsx index 505687997..0f6df8dad 100644 --- a/web/src/js/components/FlowView/Messages.jsx +++ b/web/src/js/components/FlowView/Messages.jsx @@ -9,7 +9,7 @@ import ValidateEditor from '../ValueEditor/ValidateEditor' import ValueEditor from '../ValueEditor/ValueEditor' import Headers from './Headers' -import { startEdit, updateEdit } from '../../ducks/ui/flow' +import { startEdit, updateEdit, uploadContent } from '../../ducks/ui/flow' import ToggleEdit from './ToggleEdit' function RequestLine({ flow, readonly, updateFlow }) { @@ -68,17 +68,18 @@ function ResponseLine({ flow, readonly, updateFlow }) { const Message = connect( state => ({ - flow: state.ui.flow.modifiedFlow || state.flows.byId[state.flows.selected[0]], + flow: state.flows.byId[state.flows.selected[0]], isEdit: !!state.ui.flow.modifiedFlow, }), { updateFlow: updateEdit, + uploadContent: uploadContent } ) export class Request extends Component { render() { - const { flow, isEdit, updateFlow } = this.props + const { flow, isEdit, updateFlow, uploadContent } = this.props return (
@@ -94,7 +95,12 @@ export class Request extends Component { />
- + updateFlow({ request: {content}})} + uploadContent={content => uploadContent(flow, content, "request")} + message={flow.request}/>
) } @@ -129,7 +135,7 @@ Request = Message(Request) export class Response extends Component { render() { - const { flow, isEdit, updateFlow } = this.props + const { flow, isEdit, updateFlow, uploadContent } = this.props return (
@@ -147,6 +153,8 @@ export class Response extends Component { updateFlow({ response: {content}})} + uploadContent={content => uploadContent(flow, content, "response")} message={flow.response} />
diff --git a/web/src/js/components/FlowView/ToggleEdit.jsx b/web/src/js/components/FlowView/ToggleEdit.jsx index 0c8cbbd8e..cf197998f 100644 --- a/web/src/js/components/FlowView/ToggleEdit.jsx +++ b/web/src/js/components/FlowView/ToggleEdit.jsx @@ -10,11 +10,11 @@ ToggleEdit.propTypes = { stopEdit: PropTypes.func.isRequired, } -function ToggleEdit({ isEdit, startEdit, stopEdit, flow }) { +function ToggleEdit({ isEdit, startEdit, stopEdit, flow, old_flow }) { return (
{isEdit ? - stopEdit(flow)}> + stopEdit(flow, old_flow)}> : @@ -29,7 +29,8 @@ function ToggleEdit({ isEdit, startEdit, stopEdit, flow }) { export default connect( state => ({ isEdit: !!state.ui.flow.modifiedFlow, - flow: state.ui.flow.modifiedFlow || state.flows.byId[state.flows.selected[0]] + flow: state.ui.flow.modifiedFlow || state.flows.byId[state.flows.selected[0]], + old_flow: state.flows.byId[state.flows.selected[0]] }), { startEdit, diff --git a/web/src/js/components/common/CodeEditor.jsx b/web/src/js/components/common/CodeEditor.jsx index 5b2305a86..ad7af39d0 100644 --- a/web/src/js/components/common/CodeEditor.jsx +++ b/web/src/js/components/common/CodeEditor.jsx @@ -13,10 +13,6 @@ export default class CodeEditor extends Component{ super(props) } - componentWillMount(){ - this.props.onChange(this.props.content) - } - render() { let options = { lineNumbers: true diff --git a/web/src/js/ducks/ui/flow.js b/web/src/js/ducks/ui/flow.js index c70ebfa93..e78f63731 100644 --- a/web/src/js/ducks/ui/flow.js +++ b/web/src/js/ducks/ui/flow.js @@ -88,9 +88,31 @@ export function updateEdit(update) { return { type: UPDATE_EDIT, update } } -export function stopEdit(flow) { +export function uploadContent(flow, content, type){ return (dispatch) => { - dispatch(flowsActions.update(flow, flow)).then(() => { + dispatch(flowsActions.updateContent(flow, content, type)).then( () => { + dispatch(flowsActions.updateFlow(flow)) + dispatch({ type: STOP_EDIT }) + }) + } +} + +export function stopEdit(modified_flow, old_flow) { + //make diff of modified_flow and old_flow + return (dispatch) => { + let flow = {...modified_flow} + + if (flow.response.content) { + dispatch(flowsActions.updateContent(flow, flow.response.content, "response")) + flow.response = _.omit(flow.response, "content") + } + if (flow.request.content) { + dispatch(flowsActions.updateContent(flow, flow.request.content, "request")) + flow.request = _.omit(flow.request, "content") + } + + + dispatch(flowsActions.update(flow)).then(() => { dispatch(flowsActions.updateFlow(flow)) dispatch({ type: STOP_EDIT }) })