fix(netlify-cms-core): avoid partially loaded collection list (#1964)
This commit is contained in:
parent
42d6478117
commit
cedcbf89a5
@ -445,6 +445,7 @@ export function deleteUnpublishedEntry(collection, slug) {
|
||||
export function publishUnpublishedEntry(collection, slug) {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const collections = state.collections;
|
||||
const backend = currentBackend(state.config);
|
||||
const transactionID = uuid();
|
||||
dispatch(unpublishedEntryPublishRequest(collection, slug, transactionID));
|
||||
@ -459,6 +460,7 @@ export function publishUnpublishedEntry(collection, slug) {
|
||||
}),
|
||||
);
|
||||
dispatch(unpublishedEntryPublished(collection, slug, transactionID));
|
||||
dispatch(loadEntry(collections.get(collection), slug));
|
||||
})
|
||||
.catch(error => {
|
||||
dispatch(
|
||||
|
@ -25,15 +25,15 @@ class EntriesCollection extends React.Component {
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
const { collection, loadEntries } = this.props;
|
||||
if (collection) {
|
||||
const { collection, entriesLoaded, loadEntries } = this.props;
|
||||
if (collection && !entriesLoaded) {
|
||||
loadEntries(collection);
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const { collection, loadEntries } = this.props;
|
||||
if (collection !== prevProps.collection) {
|
||||
const { collection, entriesLoaded, loadEntries } = this.props;
|
||||
if (collection !== prevProps.collection && !entriesLoaded) {
|
||||
loadEntries(collection);
|
||||
}
|
||||
}
|
||||
@ -68,12 +68,13 @@ function mapStateToProps(state, ownProps) {
|
||||
const page = state.entries.getIn(['pages', collection.get('name'), 'page']);
|
||||
|
||||
const entries = selectEntries(state, collection.get('name'));
|
||||
const entriesLoaded = !!state.entries.getIn(['pages', collection.get('name')]);
|
||||
const isFetching = state.entries.getIn(['pages', collection.get('name'), 'isFetching'], false);
|
||||
|
||||
const rawCursor = selectCollectionEntriesCursor(state.cursors, collection.get('name'));
|
||||
const cursor = Cursor.create(rawCursor).clearData();
|
||||
|
||||
return { publicFolder, collection, page, entries, isFetching, viewStyle, cursor };
|
||||
return { publicFolder, collection, page, entries, entriesLoaded, isFetching, viewStyle, cursor };
|
||||
}
|
||||
|
||||
const mapDispatchToProps = {
|
||||
|
@ -227,15 +227,7 @@ class Editor extends React.Component {
|
||||
|
||||
handlePublishEntry = async (opts = {}) => {
|
||||
const { createNew = false } = opts;
|
||||
const {
|
||||
publishUnpublishedEntry,
|
||||
entryDraft,
|
||||
collection,
|
||||
slug,
|
||||
currentStatus,
|
||||
loadEntry,
|
||||
t,
|
||||
} = this.props;
|
||||
const { publishUnpublishedEntry, entryDraft, collection, slug, currentStatus, t } = this.props;
|
||||
if (currentStatus !== status.last()) {
|
||||
window.alert(t('editor.editor.onPublishingNotReady'));
|
||||
return;
|
||||
@ -250,8 +242,6 @@ class Editor extends React.Component {
|
||||
|
||||
if (createNew) {
|
||||
navigateToNewEntry(collection.get('name'));
|
||||
} else {
|
||||
loadEntry(collection, slug);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -42,4 +42,23 @@ describe('entries', () => {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle loaded entry', () => {
|
||||
const entry = { slug: 'a', path: '' };
|
||||
expect(reducer(initialState, actions.entryLoaded(Map({ name: 'posts' }), entry))).toEqual(
|
||||
OrderedMap(
|
||||
fromJS({
|
||||
posts: { name: 'posts' },
|
||||
entities: {
|
||||
'posts.a': { slug: 'a', path: '' },
|
||||
},
|
||||
pages: {
|
||||
posts: {
|
||||
ids: ['a'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ let collection;
|
||||
let loadedEntries;
|
||||
let append;
|
||||
let page;
|
||||
let slug;
|
||||
|
||||
const entries = (state = Map({ entities: Map(), pages: Map() }), action) => {
|
||||
switch (action.type) {
|
||||
@ -25,10 +26,15 @@ const entries = (state = Map({ entities: Map(), pages: Map() }), action) => {
|
||||
);
|
||||
|
||||
case ENTRY_SUCCESS:
|
||||
return state.setIn(
|
||||
['entities', `${action.payload.collection}.${action.payload.entry.slug}`],
|
||||
fromJS(action.payload.entry),
|
||||
);
|
||||
collection = action.payload.collection;
|
||||
slug = action.payload.entry.slug;
|
||||
return state.withMutations(map => {
|
||||
map.setIn(['entities', `${collection}.${slug}`], fromJS(action.payload.entry));
|
||||
const ids = map.getIn(['pages', collection, 'ids'], List());
|
||||
if (!ids.includes(slug)) {
|
||||
map.setIn(['pages', collection, 'ids'], ids.unshift(slug));
|
||||
}
|
||||
});
|
||||
|
||||
case ENTRIES_REQUEST:
|
||||
return state.setIn(['pages', action.payload.collection, 'isFetching'], true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user