Skip to content

Commit

Permalink
add media library support for editor plugin controls
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Sep 19, 2017
1 parent a9dd4b1 commit 289c296
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from "react-immutable-proptypes";
import { connect } from 'react-redux';
import { Map } from 'immutable';
import { Button } from 'react-toolbox/lib/button';
import { openMediaLibrary } from '../../../../../actions/mediaLibrary';
import ToolbarPluginFormControl from './ToolbarPluginFormControl';
import styles from './ToolbarPluginForm.css';

export default class ToolbarPluginForm extends React.Component {
class ToolbarPluginForm extends React.Component {
static propTypes = {
plugin: PropTypes.object.isRequired,
onSubmit: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
onAddAsset: PropTypes.func.isRequired,
onRemoveAsset: PropTypes.func.isRequired,
getAsset: PropTypes.func.isRequired,
mediaPaths: ImmutablePropTypes.map.isRequired,
onOpenMediaLibrary: PropTypes.func.isRequired,
};

constructor(props) {
Expand All @@ -38,6 +43,8 @@ export default class ToolbarPluginForm extends React.Component {
onRemoveAsset,
getAsset,
onChange,
onOpenMediaLibrary,
mediaPaths,
} = this.props;

return (
Expand All @@ -55,6 +62,8 @@ export default class ToolbarPluginForm extends React.Component {
onChange={(val) => {
this.setState({ data: this.state.data.set(field.get('name'), val) });
}}
mediaPaths={mediaPaths}
onOpenMediaLibrary={onOpenMediaLibrary}
/>
))}
</div>
Expand All @@ -67,3 +76,13 @@ export default class ToolbarPluginForm extends React.Component {
);
}
}

const mapStateToProps = state => ({
mediaPaths: state.mediaLibrary.get('controlMedia'),
});

const mapDispatchToProps = {
onOpenMediaLibrary: openMediaLibrary,
};

export default connect(mapStateToProps, mapDispatchToProps)(ToolbarPluginForm);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import ImmutablePropTypes from "react-immutable-proptypes";
import { resolveWidget } from '../../../../Widgets';
import styles from './ToolbarPluginFormControl.css';

Expand All @@ -11,11 +12,13 @@ const ToolbarPluginFormControl = ({
onRemoveAsset,
getAsset,
onChange,
mediaPaths,
onOpenMediaLibrary,
}) => {
const widget = resolveWidget(field.get('widget') || 'string');
const key = `field-${ field.get('name') }`;
const Control = widget.control;
const controlProps = { field, value, onAddAsset, onRemoveAsset, getAsset, onChange };
const controlProps = { field, value, onAddAsset, onRemoveAsset, getAsset, onChange, mediaPaths, onOpenMediaLibrary };

return (
<div className={styles.control} key={key}>
Expand All @@ -35,6 +38,8 @@ ToolbarPluginFormControl.propTypes = {
onRemoveAsset: PropTypes.func.isRequired,
getAsset: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
mediaPaths: ImmutablePropTypes.map.isRequired,
onOpenMediaLibrary: PropTypes.func.isRequired,
};

export default ToolbarPluginFormControl;

0 comments on commit 289c296

Please sign in to comment.