From ba1a709b5b4a2708ab11465886e2f35c7158e5d6 Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Wed, 21 Feb 2018 15:17:17 -0500 Subject: [PATCH 1/9] withMedia, StringControl, visualEditor - edits --- .../Markdown/MarkdownControl/VisualEditor/index.js | 5 +++++ src/components/EditorWidgets/String/StringControl.js | 5 +++++ src/components/EditorWidgets/withMedia/withMediaControl.js | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js b/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js index 6f4451820a27..68185f06c3de 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js @@ -43,6 +43,11 @@ export default class Editor extends Component { }; } + componentDidMount() { + const { value } = this.props; + !value && this.props.onChange(''); + } + shouldComponentUpdate(nextProps, nextState) { return !this.state.value.equals(nextState.value); } diff --git a/src/components/EditorWidgets/String/StringControl.js b/src/components/EditorWidgets/String/StringControl.js index 3c13a4cda571..31cd12c2b3d3 100644 --- a/src/components/EditorWidgets/String/StringControl.js +++ b/src/components/EditorWidgets/String/StringControl.js @@ -11,6 +11,11 @@ export default class StringControl extends React.Component { setInactiveStyle: PropTypes.func.isRequired, }; + componentDidMount() { + const { value } = this.props; + !value && this.props.onChange(''); + } + render() { const { forID, diff --git a/src/components/EditorWidgets/withMedia/withMediaControl.js b/src/components/EditorWidgets/withMedia/withMediaControl.js index deb1c9de31d4..ce35adc41398 100644 --- a/src/components/EditorWidgets/withMedia/withMediaControl.js +++ b/src/components/EditorWidgets/withMedia/withMediaControl.js @@ -25,6 +25,11 @@ export default function withMediaControl(forImage) { this.controlID = uuid(); } + componentDidMount() { + const { value } = this.props; + !value && this.props.onChange(''); + } + shouldComponentUpdate(nextProps) { /** * Always update if the value changes. From 1d7c1a989ccb03418eedcfdb06ad1fcbc7ad2a50 Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Thu, 22 Feb 2018 14:31:27 -0500 Subject: [PATCH 2/9] changes --- src/actions/entries.js | 2 +- .../Markdown/MarkdownControl/VisualEditor/index.js | 5 ----- .../EditorWidgets/Markdown/MarkdownControl/index.js | 2 ++ src/components/EditorWidgets/Number/NumberControl.js | 4 ++++ src/components/EditorWidgets/String/StringControl.js | 7 +++---- src/components/EditorWidgets/Text/TextControl.js | 4 ++++ .../EditorWidgets/withMedia/withMediaControl.js | 9 ++++----- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/actions/entries.js b/src/actions/entries.js index 5b65f36add5c..cfaf3799ad0a 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -259,7 +259,7 @@ export function createEmptyDraft(collection) { return (dispatch) => { const dataFields = {}; collection.get('fields', List()).forEach((field) => { - dataFields[field.get('name')] = field.get('default', null); + dataFields[field.get('name')] = field.get('default', undefined); }); const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields }); dispatch(emptyDraftCreated(newEntry)); diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js b/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js index 68185f06c3de..6f4451820a27 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/VisualEditor/index.js @@ -43,11 +43,6 @@ export default class Editor extends Component { }; } - componentDidMount() { - const { value } = this.props; - !value && this.props.onChange(''); - } - shouldComponentUpdate(nextProps, nextState) { return !this.state.value.equals(nextState.value); } diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/index.js b/src/components/EditorWidgets/Markdown/MarkdownControl/index.js index b8f427805866..2b53df524049 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/index.js @@ -21,6 +21,8 @@ export default class MarkdownControl extends React.Component { value: PropTypes.string, }; + + constructor(props) { super(props); editorControl = props.editorControl; diff --git a/src/components/EditorWidgets/Number/NumberControl.js b/src/components/EditorWidgets/Number/NumberControl.js index c47938f7ff77..f88251f27d5f 100644 --- a/src/components/EditorWidgets/Number/NumberControl.js +++ b/src/components/EditorWidgets/Number/NumberControl.js @@ -15,6 +15,10 @@ export default class NumberControl extends React.Component { max: PropTypes.number, }; + static defaultProps = { + value: '', + }; + handleChange = (e) => { const valueType = this.props.field.get('valueType'); const { onChange } = this.props; diff --git a/src/components/EditorWidgets/String/StringControl.js b/src/components/EditorWidgets/String/StringControl.js index 31cd12c2b3d3..e6db1bdc20de 100644 --- a/src/components/EditorWidgets/String/StringControl.js +++ b/src/components/EditorWidgets/String/StringControl.js @@ -11,10 +11,9 @@ export default class StringControl extends React.Component { setInactiveStyle: PropTypes.func.isRequired, }; - componentDidMount() { - const { value } = this.props; - !value && this.props.onChange(''); - } + static defaultProps = { + value: '', + }; render() { const { diff --git a/src/components/EditorWidgets/Text/TextControl.js b/src/components/EditorWidgets/Text/TextControl.js index 93714807d21e..f7da7a09577d 100644 --- a/src/components/EditorWidgets/Text/TextControl.js +++ b/src/components/EditorWidgets/Text/TextControl.js @@ -12,6 +12,10 @@ export default class TextControl extends React.Component { setInactiveStyle: PropTypes.func.isRequired, }; + static defaultProps = { + value: '', + }; + /** * Always update to ensure `react-textarea-autosize` properly calculates * height. Certain situations, such as this widget being nested in a list diff --git a/src/components/EditorWidgets/withMedia/withMediaControl.js b/src/components/EditorWidgets/withMedia/withMediaControl.js index ce35adc41398..7cc2c585396d 100644 --- a/src/components/EditorWidgets/withMedia/withMediaControl.js +++ b/src/components/EditorWidgets/withMedia/withMediaControl.js @@ -20,16 +20,15 @@ export default function withMediaControl(forImage) { value: PropTypes.node, }; + static defaultProps = { + value: '', + }; + constructor(props) { super(props); this.controlID = uuid(); } - componentDidMount() { - const { value } = this.props; - !value && this.props.onChange(''); - } - shouldComponentUpdate(nextProps) { /** * Always update if the value changes. From a19b930ec1d923501023f15b8528c89ce10f890b Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Tue, 27 Feb 2018 16:35:07 -0500 Subject: [PATCH 3/9] issue-977 --- src/actions/entries.js | 2 +- src/components/EditorWidgets/Boolean/BooleanControl.js | 4 ++++ .../EditorWidgets/Markdown/MarkdownControl/index.js | 4 +++- .../EditorWidgets/Markdown/MarkdownPreview/index.js | 4 ++++ src/components/EditorWidgets/Object/ObjectControl.js | 4 ++++ src/components/EditorWidgets/Relation/RelationControl.js | 4 ++++ src/components/EditorWidgets/Select/SelectControl.js | 4 ++++ 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/actions/entries.js b/src/actions/entries.js index cfaf3799ad0a..353bc712b969 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -259,7 +259,7 @@ export function createEmptyDraft(collection) { return (dispatch) => { const dataFields = {}; collection.get('fields', List()).forEach((field) => { - dataFields[field.get('name')] = field.get('default', undefined); + dataFields[field.get('name')] = undefined; }); const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields }); dispatch(emptyDraftCreated(newEntry)); diff --git a/src/components/EditorWidgets/Boolean/BooleanControl.js b/src/components/EditorWidgets/Boolean/BooleanControl.js index 0612a9cc2a98..09a36707587a 100644 --- a/src/components/EditorWidgets/Boolean/BooleanControl.js +++ b/src/components/EditorWidgets/Boolean/BooleanControl.js @@ -38,3 +38,7 @@ BooleanControl.propTypes = { forID: PropTypes.string, value: PropTypes.bool, }; + +BooleanControl.defaultProps = { + value: false, +}; diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/index.js b/src/components/EditorWidgets/Markdown/MarkdownControl/index.js index 2b53df524049..94c723f25e44 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/index.js @@ -21,7 +21,9 @@ export default class MarkdownControl extends React.Component { value: PropTypes.string, }; - + static defaultProps = { + value: '', + }; constructor(props) { super(props); diff --git a/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js b/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js index 14f9dc1c7e69..56d883640987 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js @@ -15,4 +15,8 @@ MarkdownPreview.propTypes = { value: PropTypes.string, }; +MarkdownPreview.defaultProps = { + value: '', +}; + export default MarkdownPreview; diff --git a/src/components/EditorWidgets/Object/ObjectControl.js b/src/components/EditorWidgets/Object/ObjectControl.js index 636287db8004..c8824ecbd9a6 100644 --- a/src/components/EditorWidgets/Object/ObjectControl.js +++ b/src/components/EditorWidgets/Object/ObjectControl.js @@ -37,6 +37,10 @@ export default class ObjectControl extends Component { forList: PropTypes.bool, }; + static defaultProps = { + value: {}, + }; + constructor(props) { super(props); this.state = { diff --git a/src/components/EditorWidgets/Relation/RelationControl.js b/src/components/EditorWidgets/Relation/RelationControl.js index 589892b7fd6c..8cb2d6519753 100644 --- a/src/components/EditorWidgets/Relation/RelationControl.js +++ b/src/components/EditorWidgets/Relation/RelationControl.js @@ -30,6 +30,10 @@ class RelationControl extends Component { setInactiveStyle: PropTypes.func.isRequired, }; + static defaultProps = { + value: '', + }; + constructor(props, ctx) { super(props, ctx); this.controlID = uuid(); diff --git a/src/components/EditorWidgets/Select/SelectControl.js b/src/components/EditorWidgets/Select/SelectControl.js index f9570d7ec88e..748b39f58acc 100644 --- a/src/components/EditorWidgets/Select/SelectControl.js +++ b/src/components/EditorWidgets/Select/SelectControl.js @@ -22,6 +22,10 @@ export default class SelectControl extends React.Component { }), }; + static defaultProps = { + value: '', + }; + handleChange = (e) => { this.props.onChange(e.target.value); }; From c058e4bfaf329efdbe64098f6a77bf69c449c86c Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Tue, 27 Feb 2018 17:20:51 -0500 Subject: [PATCH 4/9] createEmptyDraft adjusted --- src/actions/entries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/entries.js b/src/actions/entries.js index 353bc712b969..a0aed54947a6 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -259,7 +259,7 @@ export function createEmptyDraft(collection) { return (dispatch) => { const dataFields = {}; collection.get('fields', List()).forEach((field) => { - dataFields[field.get('name')] = undefined; + dataFields[field.get('name')] = field.get('default'); }); const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields }); dispatch(emptyDraftCreated(newEntry)); From 440efcd9a58e06a78a9ea072b6491d5556c26ec3 Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Tue, 27 Feb 2018 17:23:00 -0500 Subject: [PATCH 5/9] createEmptyDraft adjusted --- src/actions/entries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/entries.js b/src/actions/entries.js index a0aed54947a6..cfaf3799ad0a 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -259,7 +259,7 @@ export function createEmptyDraft(collection) { return (dispatch) => { const dataFields = {}; collection.get('fields', List()).forEach((field) => { - dataFields[field.get('name')] = field.get('default'); + dataFields[field.get('name')] = field.get('default', undefined); }); const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields }); dispatch(emptyDraftCreated(newEntry)); From e844d7c00fed5e11cfbe79d86a35a51b0ea72e39 Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Tue, 27 Feb 2018 17:26:23 -0500 Subject: [PATCH 6/9] adjusted --- src/actions/entries.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/actions/entries.js b/src/actions/entries.js index cfaf3799ad0a..a0aed54947a6 100644 --- a/src/actions/entries.js +++ b/src/actions/entries.js @@ -259,7 +259,7 @@ export function createEmptyDraft(collection) { return (dispatch) => { const dataFields = {}; collection.get('fields', List()).forEach((field) => { - dataFields[field.get('name')] = field.get('default', undefined); + dataFields[field.get('name')] = field.get('default'); }); const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields }); dispatch(emptyDraftCreated(newEntry)); From e192bcd9c8e377bd9cf3c0123314eed9ddd1ad80 Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Wed, 28 Feb 2018 13:09:00 -0500 Subject: [PATCH 7/9] changes --- .../EditorWidgets/Markdown/MarkdownControl/RawEditor/index.js | 1 - .../EditorWidgets/Markdown/MarkdownPreview/index.js | 4 ---- src/components/EditorWidgets/Object/ObjectControl.js | 3 +-- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/EditorWidgets/Markdown/MarkdownControl/RawEditor/index.js b/src/components/EditorWidgets/Markdown/MarkdownControl/RawEditor/index.js index cd15da30fb50..eed87f89fd15 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownControl/RawEditor/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownControl/RawEditor/index.js @@ -51,7 +51,6 @@ export default class RawEditor extends React.Component { render() { const { className } = this.props; - return (
diff --git a/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js b/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js index 56d883640987..14f9dc1c7e69 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js @@ -15,8 +15,4 @@ MarkdownPreview.propTypes = { value: PropTypes.string, }; -MarkdownPreview.defaultProps = { - value: '', -}; - export default MarkdownPreview; diff --git a/src/components/EditorWidgets/Object/ObjectControl.js b/src/components/EditorWidgets/Object/ObjectControl.js index c8824ecbd9a6..399dacc948be 100644 --- a/src/components/EditorWidgets/Object/ObjectControl.js +++ b/src/components/EditorWidgets/Object/ObjectControl.js @@ -38,7 +38,7 @@ export default class ObjectControl extends Component { }; static defaultProps = { - value: {}, + value: Map(), }; constructor(props) { @@ -76,7 +76,6 @@ export default class ObjectControl extends Component { const widget = resolveWidget(widgetName); const fieldName = field.get('name'); const fieldValue = value && Map.isMap(value) ? value.get(fieldName) : value; - return ( Date: Wed, 28 Feb 2018 13:10:40 -0500 Subject: [PATCH 8/9] Update index.js --- .../EditorWidgets/Markdown/MarkdownPreview/index.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js b/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js index 56d883640987..14f9dc1c7e69 100644 --- a/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js +++ b/src/components/EditorWidgets/Markdown/MarkdownPreview/index.js @@ -15,8 +15,4 @@ MarkdownPreview.propTypes = { value: PropTypes.string, }; -MarkdownPreview.defaultProps = { - value: '', -}; - export default MarkdownPreview; From e8945fbe7e1759786bb26808cd04d59d1553ebc7 Mon Sep 17 00:00:00 2001 From: Mike Romani Date: Wed, 28 Feb 2018 13:54:24 -0500 Subject: [PATCH 9/9] fix issue w/accidental line erasures --- src/components/EditorWidgets/Object/ObjectControl.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/EditorWidgets/Object/ObjectControl.js b/src/components/EditorWidgets/Object/ObjectControl.js index 399dacc948be..79a79d3a5d73 100644 --- a/src/components/EditorWidgets/Object/ObjectControl.js +++ b/src/components/EditorWidgets/Object/ObjectControl.js @@ -76,6 +76,7 @@ export default class ObjectControl extends Component { const widget = resolveWidget(widgetName); const fieldName = field.get('name'); const fieldValue = value && Map.isMap(value) ? value.get(fieldName) : value; + return (