From cfb33cdbb0a306046033425a14bee275df2d9dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Boucher?= Date: Mon, 15 Feb 2016 17:10:29 -0800 Subject: [PATCH 1/5] Add element's `key` and `ref` to tree and prop views Fixes #148. Fixes #226. If a `key` or `ref` is set on the React element, it's displayed before the `props` in the tree view and in the `PropState` sidebar. If none is set, nothing is changed. Also removed a piece of code `Node.js` that would never run. (condition is checked in the previous block that `return`s) --- backend/getData.js | 6 ++++++ backend/getData012.js | 6 ++++++ backend/types.js | 2 ++ frontend/Node.js | 9 ++++----- frontend/PropState.js | 4 ++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/backend/getData.js b/backend/getData.js index 7980cedc94..c12ed373d6 100644 --- a/backend/getData.js +++ b/backend/getData.js @@ -24,6 +24,8 @@ function getData(element: Object): DataType { var updater = null; var name = null; var type = null; + var key = null; + var ref = null; var text = null; var publicInstance = null; var nodeType = 'Native'; @@ -52,6 +54,8 @@ function getData(element: Object): DataType { if (element._currentElement) { type = element._currentElement.type; + key = element._currentElement.key; + ref = element._currentElement.ref; if (typeof type === 'string') { name = type; } else if (element.getName) { @@ -95,6 +99,8 @@ function getData(element: Object): DataType { return { nodeType, type, + key, + ref, name, props, state, diff --git a/backend/getData012.js b/backend/getData012.js index 4fa7146312..2f9c44ed0a 100644 --- a/backend/getData012.js +++ b/backend/getData012.js @@ -21,6 +21,8 @@ function getData012(element: Object): DataType { var updater = null; var name = null; var type = null; + var key = null; + var ref = null; var text = null; var publicInstance = null; var nodeType = 'Native'; @@ -46,6 +48,8 @@ function getData012(element: Object): DataType { if (element._currentElement) { type = element._currentElement.type; + key = element._currentElement.key; + ref = element._currentElement.ref; if (typeof type === 'string') { name = type; } else { @@ -83,6 +87,8 @@ function getData012(element: Object): DataType { return { nodeType, type, + key, + ref, name, props, state, diff --git a/backend/types.js b/backend/types.js index 0182fae8b4..cf35d1d1f2 100644 --- a/backend/types.js +++ b/backend/types.js @@ -13,6 +13,8 @@ export type DataType = { nodeType: 'Native' | 'Wrapper' | 'NativeWrapper' | 'Composite' | 'Text' | 'Empty', type: ?(string | AnyFn), + key: ?string, + ref: ?string, name: ?string, props: ?Object, state: ?Object, diff --git a/frontend/Node.js b/frontend/Node.js index dce5670535..8f79588f4e 100644 --- a/frontend/Node.js +++ b/frontend/Node.js @@ -144,6 +144,8 @@ class Node extends React.Component { <{name} + {node.get('key') && } + {node.get('ref') && } {node.get('props') && } {!content && '/'} > @@ -160,11 +162,6 @@ class Node extends React.Component { ); } - // Plain string - if (typeof children === 'string') { - return
{children}
; - } - var closeTag = ( @@ -196,6 +193,8 @@ class Node extends React.Component { <{'' + node.get('name')} + {node.get('key') && } + {node.get('ref') && } {node.get('props') && } > diff --git a/frontend/PropState.js b/frontend/PropState.js index 361aa3ce7e..870f6ea999 100644 --- a/frontend/PropState.js +++ b/frontend/PropState.js @@ -64,6 +64,8 @@ class PropState extends React.Component { } } + var key = this.props.node.get('key'); + var ref = this.props.node.get('ref'); var state = this.props.node.get('state'); var context = this.props.node.get('context'); var propsReadOnly = !this.props.node.get('canUpdate'); @@ -72,6 +74,8 @@ class PropState extends React.Component { '} hint="($r in the console)"> + {key && } + {ref && } {editTextContent} Date: Fri, 29 Apr 2016 13:38:03 -0700 Subject: [PATCH 2/5] Make the sidebar work with refs that are functions Refs as strings is the "old" way. They can also be functions and this should handle it nicely. They are already handled nicely in the main elements panel. However the sidebar only showed `[object Object]`. To make it work, I reused the `PropVal` element since it already manages styles for different types of values. This way, `key` and `ref` look like they do in the main panel. In particular, `PropVal` handles functions well: if they are named, they are replaced by `functionName()`, otherwise simply by `fn()`. This change also includes parsing `key` as a string, just in case. --- backend/getData.js | 4 +++- backend/getData012.js | 4 +++- backend/types.js | 2 +- frontend/PropState.js | 21 +++++++++++++++++++-- frontend/detail_pane/DetailPaneSection.js | 5 ++++- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/backend/getData.js b/backend/getData.js index c12ed373d6..cde521b01d 100644 --- a/backend/getData.js +++ b/backend/getData.js @@ -54,7 +54,9 @@ function getData(element: Object): DataType { if (element._currentElement) { type = element._currentElement.type; - key = element._currentElement.key; + if (element._currentElement.key) { + key = String(element._currentElement.key); + } ref = element._currentElement.ref; if (typeof type === 'string') { name = type; diff --git a/backend/getData012.js b/backend/getData012.js index 2f9c44ed0a..3e9852abd8 100644 --- a/backend/getData012.js +++ b/backend/getData012.js @@ -48,7 +48,9 @@ function getData012(element: Object): DataType { if (element._currentElement) { type = element._currentElement.type; - key = element._currentElement.key; + if (element._currentElement.key) { + key = String(element._currentElement.key); + } ref = element._currentElement.ref; if (typeof type === 'string') { name = type; diff --git a/backend/types.js b/backend/types.js index cf35d1d1f2..2c0a33ac83 100644 --- a/backend/types.js +++ b/backend/types.js @@ -14,7 +14,7 @@ export type DataType = { nodeType: 'Native' | 'Wrapper' | 'NativeWrapper' | 'Composite' | 'Text' | 'Empty', type: ?(string | AnyFn), key: ?string, - ref: ?string, + ref: ?(string | AnyFn), name: ?string, props: ?Object, state: ?Object, diff --git a/frontend/PropState.js b/frontend/PropState.js index 870f6ea999..75b83c83c2 100644 --- a/frontend/PropState.js +++ b/frontend/PropState.js @@ -14,6 +14,7 @@ var BlurInput = require('./BlurInput'); var DataView = require('./DataView/DataView'); var DetailPane = require('./detail_pane/DetailPane'); var DetailPaneSection = require('./detail_pane/DetailPaneSection'); +var PropVal = require('./PropVal'); var React = require('react'); var decorate = require('./decorate'); @@ -74,8 +75,24 @@ class PropState extends React.Component { '} hint="($r in the console)"> - {key && } - {ref && } + {key && + + + + } + {ref && + + + + } {editTextContent} - {this.props.title} + {this.props.title} {hint ? ' ' + hint : null} {children} @@ -33,6 +33,9 @@ var styles = { marginBottom: 10, flexShrink: 0, }, + title: { + marginRight: 5, + }, }; module.exports = DetailPaneSection; From 7b956afe2f7028e54361ddf2d36bfd7a2844679b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Boucher?= Date: Fri, 29 Apr 2016 22:26:37 -0700 Subject: [PATCH 3/5] Add keys for good measure, CSS tweak These `Props` can probably use a `key`, sitting like that in a row... Moving the triangle up a bit to line it up better with the text. --- frontend/DataView/DataView.js | 1 + frontend/Node.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/frontend/DataView/DataView.js b/frontend/DataView/DataView.js index bfcb60236d..2763ef8869 100644 --- a/frontend/DataView/DataView.js +++ b/frontend/DataView/DataView.js @@ -230,6 +230,7 @@ var styles = { fontSize: 8, cursor: 'pointer', position: 'absolute', + top: '-2px', right: '100%', padding: '5px 0', }, diff --git a/frontend/Node.js b/frontend/Node.js index 8f79588f4e..6dd6d21ffe 100644 --- a/frontend/Node.js +++ b/frontend/Node.js @@ -144,9 +144,9 @@ class Node extends React.Component { <{name} - {node.get('key') && } - {node.get('ref') && } - {node.get('props') && } + {node.get('key') && } + {node.get('ref') && } + {node.get('props') && } {!content && '/'} > From 8577b9d9af2bcd7974ffcd8687065a5f486bac29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Boucher?= Date: Fri, 29 Apr 2016 23:06:11 -0700 Subject: [PATCH 4/5] Add keys for good measure in second similar part --- frontend/Node.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/Node.js b/frontend/Node.js index 6dd6d21ffe..b064343118 100644 --- a/frontend/Node.js +++ b/frontend/Node.js @@ -193,9 +193,9 @@ class Node extends React.Component { <{'' + node.get('name')} - {node.get('key') && } - {node.get('ref') && } - {node.get('props') && } + {node.get('key') && } + {node.get('ref') && } + {node.get('props') && } > {collapsed && '…'} From d83931e354ff0c55954cffac0bab651dc54c9a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Boucher?= Date: Sat, 30 Apr 2016 09:52:42 -0700 Subject: [PATCH 5/5] Fix lint errors Oops. --- frontend/Node.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frontend/Node.js b/frontend/Node.js index b064343118..966c76bc41 100644 --- a/frontend/Node.js +++ b/frontend/Node.js @@ -144,9 +144,9 @@ class Node extends React.Component { <{name} - {node.get('key') && } - {node.get('ref') && } - {node.get('props') && } + {node.get('key') && } + {node.get('ref') && } + {node.get('props') && } {!content && '/'} > @@ -193,9 +193,9 @@ class Node extends React.Component { <{'' + node.get('name')} - {node.get('key') && } - {node.get('ref') && } - {node.get('props') && } + {node.get('key') && } + {node.get('ref') && } + {node.get('props') && } > {collapsed && '…'}