simplify stop edit

This commit is contained in:
Maximilian Hils 2016-07-25 17:45:42 -07:00
parent 67bfc1df14
commit 03a596d1d9
3 changed files with 22 additions and 19 deletions

View File

@ -45,12 +45,12 @@ export default View => class extends React.Component {
this.state.request.abort()
}
// We have a few special cases where we do not need to make an HTTP request.
if(props.message.contentLength === 0 || props.message.contentLength === null){
return this.setState({request: undefined, content: ""})
}
if(props.message.content !== undefined) {
return this.setState({request: undefined, content: props.message.content})
}
if(props.message.contentLength === 0 || props.message.contentLength === null){
return this.setState({request: undefined, content: ""})
}
let requestUrl = MessageUtils.getContentURL(props.flow, props.message)

View File

@ -59,7 +59,7 @@ export default class ValueEditor extends Component {
return (
<div
ref={input => this.input = input}
tabIndex={!this.props.readonly && "0"}
tabIndex={this.props.readonly ? undefined : 0}
className={className}
contentEditable={this.state.editable || undefined}
onFocus={this.onFocus}

View File

@ -8,7 +8,6 @@ export const SET_CONTENT_VIEW = 'UI_FLOWVIEW_SET_CONTENT_VIEW',
SET_TAB = "UI_FLOWVIEW_SET_TAB",
START_EDIT = 'UI_FLOWVIEW_START_EDIT',
UPDATE_EDIT = 'UI_FLOWVIEW_UPDATE_EDIT',
STOP_EDIT = 'UI_FLOWVIEW_STOP_EDIT',
UPLOAD_CONTENT = 'UI_FLOWVIEW_UPLOAD_CONTENT'
@ -34,12 +33,6 @@ export default function reducer(state = defaultState, action) {
modifiedFlow: _.merge({}, state.modifiedFlow, action.update)
}
case STOP_EDIT:
return {
...state,
modifiedFlow: false
}
case flowsActions.SELECT:
return {
...state,
@ -47,6 +40,21 @@ export default function reducer(state = defaultState, action) {
displayLarge: false,
}
case flowsActions.UPDATE:
// There is no explicit "stop edit" event.
// We stop editing when we receive an update for
// the currently edited flow from the server
if (action.item.id === state.modifiedFlow.id) {
return {
...state,
modifiedFlow: false,
displayLarge: false,
}
} else {
return state
}
case SET_TAB:
return {
...state,
@ -90,12 +98,7 @@ export function updateEdit(update) {
return { type: UPDATE_EDIT, update }
}
export function stopEdit(flow, modified_flow) {
let diff = getDiff(flow, modified_flow)
return (dispatch) => {
dispatch(flowsActions.update(flow, diff)).then(() => {
dispatch(flowsActions.updateFlow(modified_flow))
dispatch({ type: STOP_EDIT })
})
}
export function stopEdit(flow, modifiedFlow) {
let diff = getDiff(flow, modifiedFlow)
return flowsActions.update(flow, diff)
}