From 5d8aef1d948be0664d787cc0d5a2e7d207909ede Mon Sep 17 00:00:00 2001 From: Leonardo Dino Date: Sat, 2 Feb 2019 22:54:19 -0200 Subject: [PATCH] feat(netlify-cms-core): expose loadEntry action to Widgets (#2010) --- .../components/Editor/EditorControlPane/EditorControl.js | 8 ++++++++ .../src/components/Editor/EditorControlPane/Widget.js | 3 +++ 2 files changed, 11 insertions(+) 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 3739e5c9..96df64c9 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/EditorControl.js @@ -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, }; diff --git a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js index 5c58864c..7cab6b35 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorControlPane/Widget.js @@ -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, }); }