2016-06-16 19:20:36 -03:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-05-30 16:55:32 -07:00
|
|
|
import Widgets from './Widgets';
|
|
|
|
|
|
|
|
export default class PreviewPane extends React.Component {
|
|
|
|
previewFor(field) {
|
2016-06-10 00:16:01 -03:00
|
|
|
const { entry, getMedia } = this.props;
|
2016-05-30 16:55:32 -07:00
|
|
|
const widget = Widgets[field.get('widget')] || Widgets._unknown;
|
|
|
|
return React.createElement(widget.Preview, {
|
|
|
|
field: field,
|
2016-06-10 00:16:01 -03:00
|
|
|
value: entry.getIn(['data', field.get('name')]),
|
|
|
|
getMedia: getMedia,
|
2016-05-30 16:55:32 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { collection } = this.props;
|
|
|
|
if (!collection) { return null; }
|
|
|
|
|
2016-06-16 19:20:36 -03:00
|
|
|
|
2016-05-30 16:55:32 -07:00
|
|
|
return <div>
|
2016-06-16 19:20:36 -03:00
|
|
|
{collection.get('fields').map((field) => <div key={field.get('name')}>{this.previewFor(field)}</div>)}
|
2016-05-30 16:55:32 -07:00
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
2016-06-16 19:20:36 -03:00
|
|
|
|
|
|
|
PreviewPane.propTypes = {
|
|
|
|
collection: ImmutablePropTypes.map.isRequired,
|
|
|
|
entry: ImmutablePropTypes.map.isRequired,
|
|
|
|
getMedia: PropTypes.func.isRequired,
|
|
|
|
};
|