fix(core): pass loadEntry to widgets as utility function and not redux action (#3439)
This commit is contained in:
parent
9616cdb8bb
commit
6d8765521c
@ -335,13 +335,11 @@ export function deleteLocalBackup(collection: Collection, slug: string) {
|
||||
|
||||
export function loadEntry(collection: Collection, slug: string) {
|
||||
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, 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 },
|
||||
});
|
||||
|
@ -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),
|
||||
};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user