diff --git a/packages/netlify-cms-core/src/actions/editorialWorkflow.js b/packages/netlify-cms-core/src/actions/editorialWorkflow.js index c1b91c50..8f264c62 100644 --- a/packages/netlify-cms-core/src/actions/editorialWorkflow.js +++ b/packages/netlify-cms-core/src/actions/editorialWorkflow.js @@ -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( diff --git a/packages/netlify-cms-core/src/components/Collection/Entries/EntriesCollection.js b/packages/netlify-cms-core/src/components/Collection/Entries/EntriesCollection.js index 2a923ab1..277dda42 100644 --- a/packages/netlify-cms-core/src/components/Collection/Entries/EntriesCollection.js +++ b/packages/netlify-cms-core/src/components/Collection/Entries/EntriesCollection.js @@ -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 = { diff --git a/packages/netlify-cms-core/src/components/Editor/Editor.js b/packages/netlify-cms-core/src/components/Editor/Editor.js index be0607b8..1d55f530 100644 --- a/packages/netlify-cms-core/src/components/Editor/Editor.js +++ b/packages/netlify-cms-core/src/components/Editor/Editor.js @@ -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); } }; diff --git a/packages/netlify-cms-core/src/reducers/__tests__/entries.spec.js b/packages/netlify-cms-core/src/reducers/__tests__/entries.spec.js index b2211c37..8ee7e7ab 100644 --- a/packages/netlify-cms-core/src/reducers/__tests__/entries.spec.js +++ b/packages/netlify-cms-core/src/reducers/__tests__/entries.spec.js @@ -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'], + }, + }, + }), + ), + ); + }); }); diff --git a/packages/netlify-cms-core/src/reducers/entries.js b/packages/netlify-cms-core/src/reducers/entries.js index ed4795ed..70bf2d2f 100644 --- a/packages/netlify-cms-core/src/reducers/entries.js +++ b/packages/netlify-cms-core/src/reducers/entries.js @@ -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);