Fix content-manager CANCEL_CHANGES action bug

This commit is contained in:
cyril lopez 2017-10-21 15:49:32 +02:00
parent b156a9fc73
commit fe56274217
2 changed files with 5 additions and 3 deletions

View File

@ -177,7 +177,7 @@ export class Edit extends React.Component {
const mainField = get(this.props.models, `${this.props.currentModelName}.info.mainField`) || primaryKey; const mainField = get(this.props.models, `${this.props.currentModelName}.info.mainField`) || primaryKey;
const pluginHeaderTitle = this.props.isCreating ? 'New entry' : templateObject({ mainField }, this.props.record.toJS()).mainField; const pluginHeaderTitle = this.props.isCreating ? 'New entry' : templateObject({ mainField }, this.props.record.toJS()).mainField;
const pluginHeaderDescription = this.props.isCreating ? 'New entry' : `#${this.props.record && this.props.record.get(primaryKey)}`; const pluginHeaderDescription = this.props.isCreating ? 'New entry' : `#${this.props.record && this.props.record.get(primaryKey)}`;
return ( return (
<div> <div>
<div className={`container-fluid ${styles.containerFluid}`}> <div className={`container-fluid ${styles.containerFluid}`}>

View File

@ -31,6 +31,7 @@ const initialState = fromJS({
currentModelName: '', currentModelName: '',
loading: false, loading: false,
record: false, record: false,
initialRecord: {},
editing: false, editing: false,
deleting: false, deleting: false,
isCreating: false, isCreating: false,
@ -61,7 +62,8 @@ function editReducer(state = initialState, action) {
case LOAD_RECORD_SUCCESS: case LOAD_RECORD_SUCCESS:
return state return state
.set('loading', false) .set('loading', false)
.set('record', fromJS(action.record)); .set('record', fromJS(action.record))
.set('initialRecord', fromJS(action.record));
case SET_RECORD_ATTRIBUTE: case SET_RECORD_ATTRIBUTE:
return state return state
.setIn(['record', action.key], fromJS(action.value)); .setIn(['record', action.key], fromJS(action.value));
@ -82,7 +84,7 @@ function editReducer(state = initialState, action) {
case TOGGLE_NULL: case TOGGLE_NULL:
return state.set('isRelationComponentNull', !state.get('isRelationComponentNull')); return state.set('isRelationComponentNull', !state.get('isRelationComponentNull'));
case CANCEL_CHANGES: case CANCEL_CHANGES:
return state.set('record', Map({})); return state.set('record', state.get('initialRecord'));
case SET_FORM_VALIDATIONS: case SET_FORM_VALIDATIONS:
return state return state
.set('formValidations', List(action.formValidations)); .set('formValidations', List(action.formValidations));