diff --git a/packages/netlify-cms-core/src/actions/entries.ts b/packages/netlify-cms-core/src/actions/entries.ts index 2afc881b..e0804178 100644 --- a/packages/netlify-cms-core/src/actions/entries.ts +++ b/packages/netlify-cms-core/src/actions/entries.ts @@ -335,13 +335,11 @@ export function deleteLocalBackup(collection: Collection, slug: string) { export function loadEntry(collection: Collection, slug: string) { return async (dispatch: ThunkDispatch, getState: () => State) => { - const state = getState(); - const backend = currentBackend(state.config); await waitForMediaLibraryToLoad(dispatch, getState()); dispatch(entryLoading(collection, slug)); try { - const loadedEntry = await backend.getEntry(getState(), collection, slug); + const loadedEntry = await tryLoadEntry(getState(), collection, slug); dispatch(entryLoaded(collection, loadedEntry)); dispatch(createDraftFromEntry(loadedEntry)); } catch (error) { @@ -361,6 +359,12 @@ export function loadEntry(collection: Collection, slug: string) { }; } +export async function tryLoadEntry(state: State, collection: Collection, slug: string) { + const backend = currentBackend(state.config); + const loadedEntry = await backend.getEntry(state, collection, slug); + return loadedEntry; +} + const appendActions = fromJS({ ['append_next']: { action: 'next', append: true }, }); diff --git a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js index d6d93864..149343e4 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js @@ -9,7 +9,7 @@ import { partial, uniqueId } from 'lodash'; import { connect } from 'react-redux'; import { FieldLabel, colors, transitions, lengths, borders } from 'netlify-cms-ui-default'; import { resolveWidget, getEditorComponents } from 'Lib/registry'; -import { clearFieldErrors, loadEntry } from 'Actions/entries'; +import { clearFieldErrors, tryLoadEntry } from 'Actions/entries'; import { addAsset, boundGetAsset } from 'Actions/media'; import { selectIsLoadingAsset } from 'Reducers/medias'; import { query, clearSearch } from 'Actions/search'; @@ -269,6 +269,16 @@ const mapStateToProps = state => { const collection = collections.get(entryDraft.getIn(['entry', 'collection'])); const isLoadingAsset = selectIsLoadingAsset(state.medias); + const loadEntry = async (collectionName, slug) => { + const targetCollection = collections.get(collectionName); + if (targetCollection) { + const loadedEntry = await tryLoadEntry(state, targetCollection, slug); + return loadedEntry; + } else { + throw new Error(`Can't find collection '${collectionName}'`); + } + }; + return { mediaPaths: state.mediaLibrary.get('controlMedia'), isFetching: state.search.get('isFetching'), @@ -276,6 +286,7 @@ const mapStateToProps = state => { collection, entry, isLoadingAsset, + loadEntry, }; }; @@ -295,10 +306,6 @@ const mapDispatchToProps = dispatch => { ); return { ...creators, - loadEntry: (collectionName, slug) => (dispatch, getState) => { - const collection = getState().collections.get(collectionName); - return loadEntry(collection, slug)(dispatch, getState); - }, boundGetAsset: (collection, entry) => boundGetAsset(dispatch, collection, entry), }; };