Description
Currently there are a few issues with how Decorator data is currently structured that make it more difficult to both render and customize.
Some of these issues are as follows:
- Currently there is an implicit dependency on how decorator data is structured to each FieldType's cell templates, some of which contain deep object nesting which throw template errors when not present. For example:
{
"id": blog.fields.find_by_name('Body').id,
"render_method": "wysiwyg",
"input": {
"display": {
"styles": {
"height": "500px"
}
}
}
}
One of the issues with data other than id
and render_method
is there is no standardization across different FieldTypes for attribute data. Additionally the deep nesting can cause null errors as data tried to get accessed data[:input][:display][:styles][:height]
could easily break if any of those expected Objects are not present.
Proposed Change:
Given that these elements will soon be rendered in React we can take advantage of a few ES7 features that allow encapsulation while still remaining flat. For example we could set the metadata
to be shaped something like this:
id: "8a810-72726hnva-jhvjssdcs"
render_method: "wysiwyg"
style:
height: "500px"
id: "blog_body_editor"
data-gtm: "7828734687346834"
This data could then be passed into a Field
component that can use the rest operator to bunch all data that is not id
or render_method
into an object called attrs
.
const {id, render_method = 'default', ....attrs} = this.props;
// A look up object for different TextFieldType renders
const FieldComponent = TextFieldTypeRenders[render_method]
return <FieldComponent fieldData={ FieldsLookUp[id] } {....attrs}/>
- There is inconsistencies between the
Index
andWizard
Decorators in how their data is laid out. For example:
[
{
"name": "Author",
"grid_width": 2,
"cells": [{
"field": {
"method": "creator.email"
},
"display": {
"classes": [
"circular"
]
}
}]
},
Additionally having cells
be an array while easier for ruby makes look up and access more complex and inefficient for tracking and updating changes to the data in React.
Proposed Change:
We should make data as flat as possible and keep all data on the first level and achieve nesting via reference keys.