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('h1', {}, title),
h('dl', {}, h('dl', {},
h('dt', {}, 'Posts on Frontpage'), 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('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('dt', {}, 'Default Thumbnail'),
h('dd', {}, thumb && h('img', {src: this.props.getAsset(thumb).toString()})) h('dd', {}, thumb && h('img', {src: this.props.getAsset(thumb).toString()}))

View File

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