Fix relation lists (regression #359)
This commit is contained in:
parent
5be7d3c7e4
commit
3c21a6a6db
@ -177,10 +177,10 @@ export function emptyDraftCreated(entry) {
|
||||
/*
|
||||
* Exported simple Action Creators
|
||||
*/
|
||||
export function createDraftFromEntry(entry) {
|
||||
export function createDraftFromEntry(entry, metadata) {
|
||||
return {
|
||||
type: DRAFT_CREATE_FROM_ENTRY,
|
||||
payload: entry,
|
||||
payload: { entry, metadata },
|
||||
};
|
||||
}
|
||||
|
||||
@ -276,7 +276,7 @@ export function persistEntry(collection) {
|
||||
if (!fieldsErrors.isEmpty()) {
|
||||
const hasPresenceErrors = fieldsErrors
|
||||
.some(errors => errors.some(error => error.type && error.type === ValidationErrorTypes.PRESENCE));
|
||||
|
||||
|
||||
if (hasPresenceErrors) {
|
||||
dispatch(notifSend({
|
||||
message: 'Oops, you\'ve missed a required field. Please complete before saving.',
|
||||
|
@ -164,7 +164,8 @@ class Editor extends React.Component {
|
||||
*/
|
||||
const values = deserializeValues(entry.get('data'), fields);
|
||||
const deserializedEntry = entry.set('data', values);
|
||||
this.createDraft(deserializedEntry);
|
||||
const fieldsMetaData = nextProps.entryDraft && nextProps.entryDraft.get('fieldsMetaData');
|
||||
this.createDraft(deserializedEntry, fieldsMetaData);
|
||||
} else if (newEntry) {
|
||||
this.props.createEmptyDraft(collection);
|
||||
}
|
||||
@ -175,8 +176,8 @@ class Editor extends React.Component {
|
||||
window.removeEventListener('beforeunload', this.exitBlocker);
|
||||
}
|
||||
|
||||
createDraft = (entry) => {
|
||||
if (entry) this.props.createDraftFromEntry(entry);
|
||||
createDraft = (entry, metadata) => {
|
||||
if (entry) this.props.createDraftFromEntry(entry, metadata);
|
||||
};
|
||||
|
||||
handleChangeStatus = (newStatusName) => {
|
||||
|
@ -33,10 +33,13 @@ const entryDraftReducer = (state = Map(), action) => {
|
||||
case DRAFT_CREATE_FROM_ENTRY:
|
||||
// Existing Entry
|
||||
return state.withMutations((state) => {
|
||||
state.set('entry', action.payload);
|
||||
state.set('entry', action.payload.entry);
|
||||
state.setIn(['entry', 'newRecord'], false);
|
||||
state.set('mediaFiles', List());
|
||||
state.set('fieldsMetaData', Map());
|
||||
// An existing entry may already have metadata. If we surfed away and back to its
|
||||
// editor page, the metadata will have been fetched already, so we shouldn't
|
||||
// clear it as to not break relation lists.
|
||||
state.set('fieldsMetaData', action.payload.metadata || Map());
|
||||
state.set('fieldsErrors', Map());
|
||||
state.set('hasChanged', false);
|
||||
});
|
||||
@ -55,10 +58,10 @@ const entryDraftReducer = (state = Map(), action) => {
|
||||
case DRAFT_CHANGE_FIELD:
|
||||
return state.withMutations((state) => {
|
||||
state.setIn(['entry', 'data', action.payload.field], action.payload.value);
|
||||
state.mergeIn(['fieldsMetaData'], fromJS(action.payload.metadata));
|
||||
state.mergeDeepIn(['fieldsMetaData'], fromJS(action.payload.metadata));
|
||||
state.set('hasChanged', true);
|
||||
});
|
||||
|
||||
|
||||
case DRAFT_VALIDATION_ERRORS:
|
||||
if (action.payload.errors.length === 0) {
|
||||
return state.deleteIn(['fieldsErrors', action.payload.field]);
|
||||
|
@ -56,7 +56,7 @@ const entries = (state = defaultState, action) => {
|
||||
return state.withMutations((map) => {
|
||||
map.set('isFetching', false);
|
||||
map.set('term', searchTerm);
|
||||
map.set('queryHits', Map({ [action.payload.namespace]: response.hits }));
|
||||
map.mergeIn(['queryHits'], Map({ [action.payload.namespace]: response.hits }));
|
||||
});
|
||||
|
||||
default:
|
||||
|
Loading…
x
Reference in New Issue
Block a user