Skip to content

Commit daff239

Browse files
author
Timothée Boucher
committed
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.
1 parent cfb33cd commit daff239

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

backend/getData.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ function getData(element: Object): DataType {
5454

5555
if (element._currentElement) {
5656
type = element._currentElement.type;
57-
key = element._currentElement.key;
57+
if (element._currentElement.key) {
58+
key = String(element._currentElement.key);
59+
}
5860
ref = element._currentElement.ref;
5961
if (typeof type === 'string') {
6062
name = type;

backend/getData012.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ function getData012(element: Object): DataType {
4848

4949
if (element._currentElement) {
5050
type = element._currentElement.type;
51-
key = element._currentElement.key;
51+
if (element._currentElement.key) {
52+
key = String(element._currentElement.key);
53+
}
5254
ref = element._currentElement.ref;
5355
if (typeof type === 'string') {
5456
name = type;

backend/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type DataType = {
1414
nodeType: 'Native' | 'Wrapper' | 'NativeWrapper' | 'Composite' | 'Text' | 'Empty',
1515
type: ?(string | AnyFn),
1616
key: ?string,
17-
ref: ?string,
17+
ref: ?(string | AnyFn),
1818
name: ?string,
1919
props: ?Object,
2020
state: ?Object,

frontend/PropState.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var BlurInput = require('./BlurInput');
1414
var DataView = require('./DataView/DataView');
1515
var DetailPane = require('./detail_pane/DetailPane');
1616
var DetailPaneSection = require('./detail_pane/DetailPaneSection');
17+
var PropVal = require('./PropVal');
1718
var React = require('react');
1819

1920
var decorate = require('./decorate');
@@ -74,8 +75,24 @@ class PropState extends React.Component {
7475
<DetailPane
7576
header={'<' + this.props.node.get('name') + '>'}
7677
hint="($r in the console)">
77-
{key && <DetailPaneSection title="Key" hint={key}/>}
78-
{ref && <DetailPaneSection title="Ref" hint={ref}/>}
78+
{key &&
79+
<DetailPaneSection
80+
title="Key"
81+
key={this.props.id + '-key'}>
82+
<PropVal
83+
val={key}
84+
/>
85+
</DetailPaneSection>
86+
}
87+
{ref &&
88+
<DetailPaneSection
89+
title="Ref"
90+
key={this.props.id + '-ref'}>
91+
<PropVal
92+
val={ref}
93+
/>
94+
</DetailPaneSection>
95+
}
7996
{editTextContent}
8097
<DetailPaneSection
8198
hint={propsReadOnly ? 'read-only' : null}

frontend/detail_pane/DetailPaneSection.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DetailPaneSection extends React.Component {
2020
} = this.props;
2121
return (
2222
<div style={styles.section}>
23-
<strong>{this.props.title}</strong>
23+
<strong style={styles.title}>{this.props.title}</strong>
2424
{hint ? ' ' + hint : null}
2525
{children}
2626
</div>
@@ -33,6 +33,9 @@ var styles = {
3333
marginBottom: 10,
3434
flexShrink: 0,
3535
},
36+
title: {
37+
marginRight: 5,
38+
},
3639
};
3740

3841
module.exports = DetailPaneSection;

0 commit comments

Comments
 (0)