feat(netlify-cms-core): expose loadEntry action to Widgets (#2010)

This commit is contained in:
Leonardo Dino 2019-02-02 22:54:19 -02:00 committed by Shawn Erquhart
parent f87e66af15
commit 5d8aef1d94
2 changed files with 11 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import { colors, colorsRaw, transitions, lengths, borders } from 'netlify-cms-ui
import { resolveWidget, getEditorComponents } from 'Lib/registry';
import { addAsset } from 'Actions/media';
import { query, clearSearch } from 'Actions/search';
import { loadEntry } from 'Actions/entries';
import {
openMediaLibrary,
removeInsertedMedia,
@ -143,6 +144,7 @@ class EditorControl extends React.Component {
queryHits: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
isFetching: PropTypes.bool,
clearSearch: PropTypes.func.isRequired,
loadEntry: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
};
@ -172,6 +174,7 @@ class EditorControl extends React.Component {
queryHits,
isFetching,
clearSearch,
loadEntry,
t,
} = this.props;
const widgetName = field.get('widget');
@ -235,6 +238,7 @@ class EditorControl extends React.Component {
ref={processControlRef && partial(processControlRef, fieldName)}
editorControl={ConnectedEditorControl}
query={query}
loadEntry={loadEntry}
queryHits={queryHits}
clearSearch={clearSearch}
isFetching={isFetching}
@ -264,6 +268,10 @@ const mapDispatchToProps = {
removeInsertedMedia,
addAsset,
query,
loadEntry: (collectionName, slug) => (dispatch, getState) => {
const collection = getState().collections.get(collectionName);
return loadEntry(collection, slug)(dispatch, getState);
},
clearSearch,
};

View File

@ -49,6 +49,7 @@ export default class Widget extends Component {
queryHits: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
editorControl: PropTypes.func.isRequired,
uniqueFieldId: PropTypes.string.isRequired,
loadEntry: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
};
@ -224,6 +225,7 @@ export default class Widget extends Component {
queryHits,
clearSearch,
isFetching,
loadEntry,
t,
} = this.props;
return React.createElement(controlComponent, {
@ -256,6 +258,7 @@ export default class Widget extends Component {
queryHits,
clearSearch,
isFetching,
loadEntry,
t,
});
}