-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Handle & render the _source property #406
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,6 +91,7 @@ function getData012(element: Object): DataType { | |
| type, | ||
| key, | ||
| ref, | ||
| source: null, | ||
| name, | ||
| props, | ||
| state, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,18 @@ var React = require('react'); | |
| var decorate = require('./decorate'); | ||
| var invariant = require('./invariant'); | ||
|
|
||
| /** | ||
| * Shorten a file path to something reasonable. | ||
| * - if it has `/src/` in it, assume that's the project root | ||
| * - if it starts w/ `/Users/name/`, replace that with `~/` | ||
| */ | ||
| var shortFilePath = text => { | ||
|
||
| if (text.match(/\/src\//)) { | ||
| return 'src/' + text.split(/\/src\//)[1]; | ||
| } | ||
| return text.replace(/^\/Users\/[^\/]+\//, '~/'); | ||
| }; | ||
|
|
||
| class PropState extends React.Component { | ||
| getChildContext() { | ||
| return { | ||
|
|
@@ -29,6 +41,23 @@ class PropState extends React.Component { | |
| }; | ||
| } | ||
|
|
||
| renderSource(): ?React.Element { | ||
| var source = this.props.node.get('source'); | ||
| if (!source) { | ||
| return null; | ||
| } | ||
| return ( | ||
| <div style={styles.source}> | ||
| <div style={styles.sourceName}> | ||
| {shortFilePath(source.fileName)} | ||
| </div> | ||
| <div style={styles.sourcePos}> | ||
| :{source.lineNumber} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| render(): React.Element { | ||
| if (!this.props.node) { | ||
| // TODO(jared): style this | ||
|
|
@@ -129,6 +158,8 @@ class PropState extends React.Component { | |
| </DetailPaneSection>} | ||
| {this.props.extraPanes && | ||
| this.props.extraPanes.map(fn => fn && fn(this.props.node, this.props.id))} | ||
| <div style={{flex: 1}} /> | ||
| {this.renderSource()} | ||
| </DetailPane> | ||
| ); | ||
| } | ||
|
|
@@ -171,4 +202,20 @@ var WrappedPropState = decorate({ | |
| }, | ||
| }, PropState); | ||
|
|
||
| var styles = { | ||
| source: { | ||
| padding: '5px 10px', | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| }, | ||
|
|
||
| sourceName: { | ||
| color: 'blue', | ||
| }, | ||
|
|
||
| sourcePos: { | ||
| color: '#777', | ||
| }, | ||
| }; | ||
|
|
||
| module.exports = WrappedPropState; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's display → It's displayed