Skip to content

Commit 734403b

Browse files
committed
fix(widgetsFor): return widgets for variable type lists
When using a Variable Type list widget and a custom preview component, the `widgetsFor` helper would only return a `data` list with each of the items in the list, not a `widgets` list, e.g. {"data" => {"markdown" => "# Title"} {"type" => "block_body"} } {"widgets" => undefined} 🚫 The `widgets` list should also be supplied, particularly for nested Markdown widgets, so a fully formatted preview can be rendered: {"data" => {"markdown" => "# Title"} {"type" => "block_body"} } {"widgets" => {"markdown" => Object} ✅ } This extends support in `widgetsFor` to detect variable type list widgets and correctly construct the `widgets` return value. As reported at #2307 (comment)
1 parent 51eb7e8 commit 734403b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/decap-cms-core/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,28 @@ export class PreviewPane extends React.Component {
167167
const { fields, entry, fieldsMetaData } = this.props;
168168
const field = fields.find(f => f.get('name') === name);
169169
const nestedFields = field && field.get('fields');
170+
const variableTypes = field && field.get('types');
170171
const value = entry.getIn(['data', field.get('name')]);
171172
const metadata = fieldsMetaData.get(field.get('name'), Map());
172173

174+
// Variable Type lists
175+
if (List.isList(value) && variableTypes) {
176+
return value.map(val => {
177+
const valueType = variableTypes.find(t => t.get('name') === val.get('type'));
178+
const typeFields = valueType && valueType.get('fields');
179+
const widgets =
180+
typeFields &&
181+
Map(
182+
typeFields.map((f, i) => [
183+
f.get('name'),
184+
<div key={i}>{this.getWidget(f, val, metadata.get(f.get('name')), this.props)}</div>,
185+
]),
186+
);
187+
return Map({ data: val, widgets });
188+
});
189+
}
190+
191+
// List widgets
173192
if (List.isList(value)) {
174193
return value.map(val => {
175194
const widgets =

0 commit comments

Comments
 (0)