Moved PreviewPane to a separate directory. Extracted Preview component to a separate file.

This commit is contained in:
Andrey Okonetchnikov 2016-09-30 16:25:15 +02:00
parent edf8abbc42
commit f1eb93ee7f
4 changed files with 43 additions and 41 deletions

View File

@ -1,7 +1,7 @@
import React, { Component, PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ControlPane from '../ControlPanel/ControlPane';
import PreviewPane from '../PreviewPane';
import PreviewPane from '../PreviewPane/PreviewPane';
import styles from './EntryEditor.css';
export default class EntryEditor extends Component {

View File

@ -0,0 +1,39 @@
import React, { PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { resolveWidget } from '../Widgets';
export default class Preview extends React.Component {
previewFor(field) {
const { entry, getMedia } = this.props;
const widget = resolveWidget(field.get('widget'));
return React.createElement(widget.preview, {
field: field,
value: entry.getIn(['data', field.get('name')]),
getMedia: getMedia,
});
}
render() {
const { collection } = this.props;
if (!collection) {
return null;
}
return <div>
{
collection.get('fields').map(field => (
<div key={field.get('name')}>
{this.previewFor(field)}
</div>
))
}
</div>;
}
}
Preview.propTypes = {
collection: ImmutablePropTypes.map.isRequired,
entry: ImmutablePropTypes.map.isRequired,
getMedia: PropTypes.func.isRequired,
};

View File

@ -1,48 +1,11 @@
import React, { PropTypes } from 'react';
import { render } from 'react-dom';
import ImmutablePropTypes from 'react-immutable-proptypes';
import registry from '../lib/registry';
import { resolveWidget } from './Widgets';
import registry from '../../lib/registry';
import { resolveWidget } from '../Widgets';
import Preview from './Preview';
import styles from './PreviewPane.css';
class Preview extends React.Component {
previewFor(field) {
const { entry, getMedia } = this.props;
const widget = resolveWidget(field.get('widget'));
return React.createElement(widget.preview, {
field: field,
value: entry.getIn(['data', field.get('name')]),
getMedia: getMedia,
});
}
render() {
const { collection } = this.props;
if (!collection) {
return null;
}
return <div>
{
collection.get('fields').map(field => (
<div
key={field.get('name')}
>
{this.previewFor(field)}
</div>
))
}
</div>;
}
}
Preview.propTypes = {
collection: ImmutablePropTypes.map.isRequired,
entry: ImmutablePropTypes.map.isRequired,
getMedia: PropTypes.func.isRequired,
};
export default class PreviewPane extends React.Component {
componentDidUpdate(prevProps) {