diff --git a/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js b/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js index f989987c..6de3e7f1 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js @@ -22,9 +22,10 @@ const PreviewPaneFrame = styled(Frame)` `; export default class PreviewPane extends React.Component { - getWidget = (field, value, props) => { + getWidget = (field, value, props, idx = null) => { const { fieldsMetaData, getAsset, entry } = props; const widget = resolveWidget(field.get('widget')); + const key = idx ? field.get('name') + '_' + idx : field.get('name'); /** * Use an HOC to provide conditional updates for all previews. @@ -32,7 +33,7 @@ export default class PreviewPane extends React.Component { return !widget.preview ? null : ( f.get('name') === name); let value = values && values.get(field.get('name')); let nestedFields = field.get('fields'); + let singleField = field.get('field'); if (nestedFields) { field = field.set('fields', this.getNestedWidgets(nestedFields, value)); } + if (singleField) { + field = field.set('field', this.getSingleNested(singleField, value)); + } + const labelledWidgets = ['string', 'text', 'number']; if (Object.keys(this.inferedFields).indexOf(name) !== -1) { value = this.inferedFields[name].defaultPreview(value); @@ -103,6 +109,13 @@ export default class PreviewPane extends React.Component { return this.widgetsForNestedFields(fields, values); }; + getSingleNested = (field, values) => { + if (List.isList(values)) { + return values.map((value, idx) => this.getWidget(field, value, this.props, idx)); + } + return this.getWidget(field, values, this.props); + }; + /** * Use widgetFor as a mapping function for recursive widget retrieval */ diff --git a/packages/netlify-cms-ui-default/src/ListItemTopBar.js b/packages/netlify-cms-ui-default/src/ListItemTopBar.js index 358731cc..9c8cdd3f 100644 --- a/packages/netlify-cms-ui-default/src/ListItemTopBar.js +++ b/packages/netlify-cms-ui-default/src/ListItemTopBar.js @@ -28,30 +28,34 @@ const TopBarButton = styled.button` const TopBarButtonSpan = TopBarButton.withComponent('span'); -const DragIcon = styled(TopBarButtonSpan)` +const DragIconContainer = styled(TopBarButtonSpan)` width: 100%; cursor: move; `; -const ListItemTopBar = ({ className, collapsed, onCollapseToggle, onRemove, dragHandleHOC }) => ( - - {onCollapseToggle ? ( - - - - ) : null} - {dragHandleHOC ? ( - - - - ) : null} - {onRemove ? ( - - - - ) : null} - -); +const ListItemTopBar = ({ className, collapsed, onCollapseToggle, onRemove, dragHandleHOC }) => { + const DragHandle = dragHandleHOC(() => ( + + + + )); + + return ( + + {onCollapseToggle ? ( + + + + ) : null} + {dragHandleHOC ? : null} + {onRemove ? ( + + + + ) : null} + + ); +}; const StyledListItemTopBar = styled(ListItemTopBar)` display: flex; diff --git a/packages/netlify-cms-widget-list/src/ListControl.js b/packages/netlify-cms-widget-list/src/ListControl.js index 607c86e6..ae6c175b 100644 --- a/packages/netlify-cms-widget-list/src/ListControl.js +++ b/packages/netlify-cms-widget-list/src/ListControl.js @@ -159,16 +159,17 @@ export default class ListControl extends React.Component { return (fieldName, newValue, newMetadata) => { const { value, metadata, onChange, field } = this.props; const collectionName = field.get('name'); - const newObjectValue = this.getObjectValue(index).set(fieldName, newValue); - const parsedValue = - this.getValueType() === valueTypes.SINGLE ? newObjectValue.first() : newObjectValue; + const newObjectValue = + this.getValueType() === valueTypes.MULTIPLE + ? this.getObjectValue(index).set(fieldName, newValue) + : newValue; const parsedMetadata = { [collectionName]: Object.assign( metadata ? metadata.toJS() : {}, newMetadata ? newMetadata[collectionName] : {}, ), }; - onChange(value.set(index, parsedValue), parsedMetadata); + onChange(value.set(index, newObjectValue), parsedMetadata); }; } @@ -177,9 +178,10 @@ export default class ListControl extends React.Component { const { itemsCollapsed } = this.state; const { value, metadata, onChange, field } = this.props; const collectionName = field.get('name'); - const parsedMetadata = metadata && { - [collectionName]: metadata.removeIn(value.get(index).valueSeq()), - }; + const isSingleField = this.valueType === valueTypes.SINGLE; + + const metadataRemovePath = isSingleField ? value.get(index) : value.get(index).valueSeq(); + const parsedMetadata = metadata && { [collectionName]: metadata.removeIn(metadataRemovePath) }; this.setState({ itemsCollapsed: itemsCollapsed.delete(index) }); diff --git a/packages/netlify-cms-widget-object/src/ObjectControl.js b/packages/netlify-cms-widget-object/src/ObjectControl.js index ff3fa58a..626272ad 100644 --- a/packages/netlify-cms-widget-object/src/ObjectControl.js +++ b/packages/netlify-cms-widget-object/src/ObjectControl.js @@ -62,13 +62,20 @@ export default class ObjectControl extends Component { this.setState({ collapsed: !this.state.collapsed }); }; + renderFields = (multiFields, singleField) => { + if (multiFields) { + return multiFields.map((f, idx) => this.controlFor(f, idx)); + } + return this.controlFor(singleField); + }; + render() { const { field, forID, classNameWrapper, forList } = this.props; const { collapsed } = this.state; const multiFields = field.get('fields'); const singleField = field.get('field'); - if (multiFields) { + if (multiFields || singleField) { return (
)} - {collapsed ? null : multiFields.map((f, idx) => this.controlFor(f, idx))} + {collapsed ? null : this.renderFields(multiFields, singleField)}
); - } else if (singleField) { - return this.controlFor(singleField); } return

No field(s) defined for this widget

; diff --git a/packages/netlify-cms-widget-object/src/ObjectPreview.js b/packages/netlify-cms-widget-object/src/ObjectPreview.js index f5bd2b9a..605c3f55 100644 --- a/packages/netlify-cms-widget-object/src/ObjectPreview.js +++ b/packages/netlify-cms-widget-object/src/ObjectPreview.js @@ -3,7 +3,9 @@ import PropTypes from 'prop-types'; import { WidgetPreviewContainer } from 'netlify-cms-ui-default'; const ObjectPreview = ({ field }) => ( - {(field && field.get('fields')) || null} + + {(field && field.get('fields')) || field.get('field') || null} + ); ObjectPreview.propTypes = {