Skip to content

Commit

Permalink
Fix relation lists (regression #359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quicksaver authored and erquhart committed Jan 23, 2018
1 parent 5be7d3c commit 3c21a6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/actions/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
}

Expand Down Expand Up @@ -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.',
Expand Down
7 changes: 4 additions & 3 deletions src/components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) => {
Expand Down
11 changes: 7 additions & 4 deletions src/reducers/entryDraft.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/reducers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 3c21a6a

Please sign in to comment.