add object support to widgetsFor

This commit is contained in:
Shawn Erquhart 2017-03-06 13:28:11 -05:00
parent 9dca9f912a
commit 9bc80ed5e4
2 changed files with 16 additions and 9 deletions

View File

@ -98,10 +98,10 @@
h('h1', {}, title),
h('dl', {},
h('dt', {}, 'Posts on Frontpage'),
h('dd', {}, posts && posts.get('front_limit') || '0'),
h('dd', {}, this.props.widgetsFor('posts').getIn(['widgets', 'front_limit']) || 0),
h('dt', {}, 'Default Author'),
h('dd', {}, posts && posts.get('author') || 'None'),
h('dd', {}, this.props.widgetsFor('posts').getIn(['data', 'front_limit']) || 'None'),
h('dt', {}, 'Default Thumbnail'),
h('dd', {}, thumb && h('img', {src: this.props.getAsset(thumb).toString()}))

View File

@ -1,6 +1,6 @@
import React, { PropTypes } from 'react';
import ReactDOM from 'react-dom';
import { Map } from 'immutable';
import { List, Map } from 'immutable';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { ScrollSyncPane } from '../ScrollSync';
import registry from '../../lib/registry';
@ -55,22 +55,29 @@ export default class PreviewPane extends React.Component {
const { fields, entry, getAsset } = this.props;
const field = fields && fields.find(f => f.get('name') === name);
const nestedFields = field && field.get('fields');
const values = entry.getIn(['data', field.get('name')]);
const value = entry.getIn(['data', field.get('name')]);
const widgetFor = (field, value) => {
const widget = resolveWidget(field.get('widget'));
return (<div key={field.get('name')}>{React.createElement(widget.preview, {
key: field.get('name'),
value: value && value.get(field.get('name')),
value: value && List.isList(value) ? value.get(field.get('name')) : value,
field,
getAsset,
})}</div>);
};
return values ? values.map((value, index) => {
const widgets = nestedFields && Map(nestedFields.map(f => [f.get('name'), widgetFor(f, value)]));
return Map({ data: value, widgets });
}) : null;
if (List.isList(value)) {
return value.map((val, index) => {
const widgets = nestedFields && Map(nestedFields.map(f => [f.get('name'), widgetFor(f, val)]));
return Map({ data: val, widgets });
});
}
return Map({
data: value,
widgets: nestedFields && Map(nestedFields.map(f => [f.get('name'), widgetFor(f, value)])),
});
};
handleIframeRef = (ref) => {