-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DevDocs: Generate a table for displaying proptypes #10342
Conversation
f2f4075
to
6666570
Compare
6666570
to
bb2bc0c
Compare
I think design wise it's good for this iteration. I agree it might require tweaking, but it's already good enough, and we can iterate on that once it's in. The only frustrating bit is that going back to "All Blocks" loses the scroll position in the list, which makes navigating a few blocks fairly frustrating. Might not be something to be done in this PR specifically, but I think it's important to address that. |
Yes, that is really annoying... hopefully I'll figure out a fix soon because it drives me bananas. |
I noticed after cherry-picking #10343, that inline comments aren't being displayed for Any idea how we'd fix this? |
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.
Looking good so far. I left you some initial pass comments :)
client/blocks/props-viewer/index.jsx
Outdated
* @param {string} propName The name of the prop | ||
* @return {ReactElement} The row | ||
*/ | ||
const row = ( propName ) => { |
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.
Could we extract functions that render stuff into components?
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.
Ah yes ... I think I was being a little too paranoid about keeping the changes under a couple hundred lines ;)
client/blocks/props-viewer/index.jsx
Outdated
* @param {string} rightName The prop name of the right side | ||
* @return {number} Which side wins | ||
*/ | ||
const sortProps = ( leftName, rightName ) => { |
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.
This feels like it should live outside render()
— it also makes me think that we're creating a new function per render?
@ehg said:
Looks like it only supports docblocks. It appears like there was commit in react-docgen near where I'd need to update it to support this as it just strips the comments, if I'm reading it correctly. I don't know how the maintainers feel about it ... so I opened an issue. Short of that, I think a codemod might would work... I know I've thought about a codemod to move the readme to the component at some point in the future, but I don't think I've brought it up, just thought about it. |
client/blocks/props-viewer/index.jsx
Outdated
} | ||
} | ||
|
||
PropsViewer.propTypes = { |
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.
These could be put in the class as a static
property :]
ec1f3d2
to
85b933a
Compare
client/blocks/props-viewer/index.jsx
Outdated
/** | ||
* External Dependencies | ||
*/ | ||
|
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.
No space needed here.
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.
Thanks!
client/blocks/props-viewer/index.jsx
Outdated
); | ||
} | ||
|
||
static propTypes = { |
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.
Any benefits to having these at the bottom, rather than the top of the class?
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.
I normally see them outside the class at the bottom of the file. I put them at the bottom so that someone would easily find them out of habit, without searching.
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.
Yeah, I think we only do that because we need Component
assigned, before we modify Component.propTypes
. With createClass
, we'd put them at the top.
Makefile
Outdated
@@ -164,7 +164,7 @@ build-dll: node_modules | |||
@mkdir -p build | |||
@CALYPSO_ENV=$(CALYPSO_ENV) $(NODE_BIN)/webpack --display-error-details --config webpack-dll.config.js | |||
|
|||
build-server: install | |||
build-server: install server/devdocs/proptypes-index.json |
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.
What environments will this actually run in? Do we actually need to generate a full proptypes index in the test environment?
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.
I realized I forgot to commit my tests, and the build failed without that file existing. I'd like to chat about it in slack if you don't mind. I don't like it.
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.
Did we converge on a solution to this? :)
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.
Yeah, needs mock and this reverted. Still working on it, taking a bit longer than I anticipated.
client/blocks/props-viewer/index.jsx
Outdated
* @param {object} component The component to render for | ||
* @return {ReactComponent|null} The table or nothing | ||
*/ | ||
renderTable = ( component ) => { |
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.
Why not use a regular, unbound, function here?
|
||
const components = require( '../../../../server/devdocs/proptypes-index.json' ); | ||
|
||
const findRealComponent = ( slug ) => { |
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.
Why are we duplicating code here?
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.
My personal strategy with duplicate code is to always duplicate once before refactoring for reuse. I do need to address this.
client/blocks/props-viewer/index.jsx
Outdated
return null; //todo: explain why this table is missing | ||
} | ||
|
||
return ( |
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.
This still feels a bit long, and unreadable to me.
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 does feel a bit long, but it's mostly just markup. Lines 155 - 160 could probably become more readable.
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.
Could we split this into a few subcomponents? Ideally it'd be nice if we don't fork render logic into separate methods (often that's a sign it should be split to separate components).
it( 'can render itself', () => { | ||
const example = ( <div>Example goes here</div> ); | ||
const component = ( <PropsViewer component={ 'props-viewer' } example={ example } /> ); | ||
const spection = findRealComponent( 'props-viewer' )[ 0 ]; |
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.
What's a spection?
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.
Spection comes from Latin specere: to look.
It technically isn't a real word, but one I made up ;)
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.
Hah, I guess I'd like something a little more human readable though. Makes me feel less of a caudex :P
6801ffa
to
fd4e5b7
Compare
I moved the build of the json file to only be when |
fd4e5b7
to
53b275c
Compare
Makefile
Outdated
@@ -172,7 +172,7 @@ build: install build-$(CALYPSO_ENV) | |||
|
|||
build-css: public/style.css public/style-rtl.css public/style-debug.css public/editor.css | |||
|
|||
build-development: server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json build-server build-dll $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js build-css | |||
build-development: server/devdocs/components-usage-stats.json build-server build-dll $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js build-css | |||
|
|||
build-wpcalypso: server/devdocs/proptypes-index.json server/devdocs/components-usage-stats.json build-server build-dll $(CLIENT_CONFIG_FILE) server/devdocs/search-index.js build-css |
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.
Now also builds with wpcalypso
Makefile
Outdated
@@ -91,10 +91,10 @@ welcome: | |||
install: node_modules | |||
|
|||
# Simply running `make run` will spawn the Node.js server instance. | |||
run: welcome githooks install build | |||
run: welcome githooks install build server/devdocs/proptypes-index.json |
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.
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.
good catch
Makefile
Outdated
@$(NODE) build/bundle-$(CALYPSO_ENV).js | ||
|
||
dashboard: install | ||
dashboard: install server/devdocs/proptypes-index.json |
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.
Also superfluous :)
0557fca
to
bc67821
Compare
returning to this since I have a few days and not sure if any issues remain from this review.
Closing because I suck at making time for this. |
In #19064 I first made the |
Generates a table of proptypes when viewing a component by itself in the DevDocs.
#9919 added a json file to the build that uses react/react-docgen to parse our components and extract the propTypes for each of them. This happens at build time. A later PR may allow this to run similar to how our CSS files are built while developing.
This PR requires that file directly, and doesn't require a server. This has two benefits:
A different PR can move the file somewhere in the client path. I'm not particularly happy about a relative path in this code. However, I feel as though that should be separate and not done in this PR.
The styling of this follows @aduth's state selector PR (#9433) style. I've tagged this for design review. I originally experimented with using flex-box instead of a table, but the complexity of the dom and CSS exploded on me. It would be a good future task, though I imagine most developers would be on a desktop device writing code. I could be wrong 😉 ...
There are some interesting possibilities that could come in a future PR near you:
isolate
mode #8482) that could really bring this to life.This work is based on #9289, #9919. There's a fix in #10343 to get some missing components into the index.
View live: https://calypso.live/devdocs/blocks?branch=add/proptypes-table