Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Tools or use a pre-prelease version.

## Usage

### Supporting tools

- The babel plugin [trasnform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) is required if you want react devtools to tell you the source file & line number of created react elements. It's display in the bottom of the right panel if the information is present.

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


### Tree View

- Arrow keys or hjkl for navigation
Expand Down
3 changes: 3 additions & 0 deletions backend/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function getData(element: Object): DataType {
var type = null;
var key = null;
var ref = null;
var source = null;
var text = null;
var publicInstance = null;
var nodeType = 'Native';
Expand Down Expand Up @@ -65,6 +66,7 @@ function getData(element: Object): DataType {
if (element._currentElement.key) {
key = String(element._currentElement.key);
}
source = element._currentElement._source;
ref = element._currentElement.ref;
if (typeof type === 'string') {
name = type;
Expand Down Expand Up @@ -111,6 +113,7 @@ function getData(element: Object): DataType {
type,
key,
ref,
source,
name,
props,
state,
Expand Down
1 change: 1 addition & 0 deletions backend/getData012.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function getData012(element: Object): DataType {
type,
key,
ref,
source: null,
name,
props,
state,
Expand Down
1 change: 1 addition & 0 deletions backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type DataType = {
type: ?(string | AnyFn),
key: ?string,
ref: ?(string | AnyFn),
source: ?Object,
name: ?string,
props: ?Object,
state: ?Object,
Expand Down
47 changes: 47 additions & 0 deletions frontend/PropState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? I'd rather fix any environments that pass an absolute path. I've been meaning to check whether babelify and babel-loader do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like having an absolute path -- and it's critical for React Native's "open the file in your editor" functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we could change it to include both an absolute path and a project-relative path? or sth. or the # that is how long the project prefix is, so we could do source.filePath.slice(source.prefixLength) or sth

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the project-relative path is always what you want. The packager would know where the root is.

if (text.match(/\/src\//)) {
return 'src/' + text.split(/\/src\//)[1];
}
return text.replace(/^\/Users\/[^\/]+\//, '~/');
};

class PropState extends React.Component {
getChildContext() {
return {
Expand All @@ -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
Expand Down Expand Up @@ -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>
);
}
Expand Down Expand Up @@ -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;