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

View File

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