Skip to content
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: New "Gutenberg components" section #26314

Merged
merged 13 commits into from
Aug 3, 2018

Conversation

mmtr
Copy link
Member

@mmtr mmtr commented Jul 25, 2018

First task for exposing the Gutenberg components in Calypso and part of #26180.

It creates a new section in the DevDocs that displays the collection of components available in Gutenberg, with documentation explaining how to use them.

Right now, the collection only features the Button component (rest of them will be included in the next PR).

Testing Instructions

  • Navigate to /devdocs
  • New section "Gutenberg Components" appears in the sidebar under "Live Docs"
  • Click on the "Gutenberg Components" section
  • It redirects to /devdocs/gutenberg-components and a page with a short intro and a collection of component appears
  • The short introduction has a link that redirects to documentation with more info
  • The gallery only features the Button components
  • Click on the Button link
  • It redirects to a page that displays the same example as before, the code used in the example and README.md file included in the @wordpress/components package for the Button component (https://github.com/WordPress/gutenberg/blob/master/packages/components/src/button/README.md)

Screenshots

screen shot 2018-07-25 at 23 16 58
screen shot 2018-07-25 at 23 17 11
screen shot 2018-07-25 at 23 17 25

@mmtr mmtr added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. [Goal] Gutenberg Working towards full integration with Gutenberg labels Jul 25, 2018
@matticbot
Copy link
Contributor

@mmtr mmtr requested review from ehg, gziolo and gwwar July 25, 2018 21:31
@gwwar
Copy link
Contributor

gwwar commented Jul 25, 2018

Can you try rebasing from master again? Looks like a number of misc commits on the branch.

@mmtr
Copy link
Member Author

mmtr commented Jul 25, 2018

yeah, sorry @gwwar. not sure what happened. I'm fixing it

@mmtr mmtr removed request for ehg, gziolo and gwwar July 25, 2018 21:55
@gwwar
Copy link
Contributor

gwwar commented Jul 25, 2018

No worries, can happen sometimes with an odd merge, but best to clean it up before it gets too gnarly. A git rebase -i master should clear it up, though it can be painful if you have conflicts on a number of files.

Unless we're working together with another person on a branch, feel free to rebase freely as needed.

@mmtr mmtr force-pushed the add/devdocs-gutenberg-components branch 3 times, most recently from ddd1d05 to 20a8b94 Compare July 25, 2018 23:07
@mmtr
Copy link
Member Author

mmtr commented Jul 25, 2018

everything should be right now @gwwar. thanks for the help!

@mmtr mmtr requested review from ehg, gziolo and gwwar July 25, 2018 23:08
@@ -104,6 +104,13 @@ export default class DevdocsSidebar extends React.PureComponent {
link="/devdocs/blocks"
selected={ this.isItemSelected( '/devdocs/blocks', false ) }
/>
<SidebarItem
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we put this under the same feature flag?

Copy link
Member Author

Choose a reason for hiding this comment

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

I had the same doubt. My main concern is that there are some things we cannot hide even if the feature flag is not enabled:

Because of that and because all the Gutenberg components are actually ready to be used in Calypso (we just need to add more docs explaining how to use the rest of them), I thought that was ok to display this publicly.

But I don't have a strong opinion about this, honestly. If you think that having the readme files available is not a big deal, I can put this under the same feature flag.

showEditLink = false;
} else {
readmeFilePath = `/client/${ section }/${ example.props.readmeFilePath }/README.md`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe pull this out into a helper functions?

const shouldShowEditLink = ( section ) => ( section !== 'gutenberg-components' );

const getReadmeFilePath( section, example ) {
        switch( section ) {
             case 'design':
                 return `/client/components/${ example.props.readmeFilePath }/README.md`;
             case 'gutenberg-components';
                 return `/node_modules/@wordpress/components/src/${ example.props.readmeFilePath }/README.md`;
             default:
                  return `/client/${ section }/${ example.props.readmeFilePath }/README.md`;
        }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed!

@@ -163,6 +163,14 @@ const devdocs = {
next();
},

// Gutenberg C
Copy link
Contributor

Choose a reason for hiding this comment

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

😄 Don't forget to finish your comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! 😅 You have not seen anything 🤫

@@ -8,14 +8,15 @@ import classNames from 'classnames';
import PropTypes from 'prop-types';
import { LiveProvider, LiveEditor, LiveError, LivePreview } from 'react-live';
Copy link
Contributor

Choose a reason for hiding this comment

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

Special Sentient Sandwich 💯
screen shot 2018-07-25 at 4 44 14 pm

https://www.youtube.com/watch?v=2I481MAfLG8


/**
* Internal dependencies
*/
import Button from 'components/button';
import ClipboardButton from 'components/forms/clipboard-button';
import DocsExampleWrapper from 'devdocs/docs-example/wrapper';
import * as playgroundScope from 'devdocs/design/playground-scope';
import * as playgroundScopeForComponents from 'devdocs/design/playground-scope';
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 not sure we can get around not importing both sets.

Copy link
Member Author

Choose a reason for hiding this comment

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

What about this?

const scope = 'gutenberg-components' === section ? require('@wordpress/components') : require('devdocs/design/playground-scope');

Copy link
Contributor

@gwwar gwwar Jul 26, 2018

Choose a reason for hiding this comment

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

It depends on where we put the requires. For example think of visiting http://calypso.localhost:3000/devdocs/design, then clicking on Gutenberg Components without a browser refresh.

Maybe we could separate the two into two components and then async load?

Copy link
Member Author

Choose a reason for hiding this comment

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

require loads modules on-demand, so it shouldn't cause any issues when switching from one page to another

let scope = playgroundScopeForComponents;
if ( 'gutenberg-components' === this.props.section ) {
scope = playgroundScopeForGutenbergComponents;
}
Copy link
Contributor

@gwwar gwwar Jul 25, 2018

Choose a reason for hiding this comment

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

How about a ternary to avoid the let?

const scope = 'gutenberg-components' === this.props.section ? playgroundScopeForGutenbergComponents : playgroundScopeForComponents;

} else {
// jquery is only needed in the build for the desktop app
// see electron bug: https://github.com/atom/electron/issues/254
webpackConfig.externals.push( 'jquery' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah we'll need to make sure we remove this before change before merge. This is still used by Desktop

Copy link
Member

Choose a reason for hiding this comment

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

Is it still there? I hoped you would refactor paygate to be jQuery free :D

Copy link
Contributor

Choose a reason for hiding this comment

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

@astralbodies did anything change with regards to the jQuery include? Pretty sure we still need this, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

We need to fix it sooner than later! 😅

Copy link
Member

Choose a reason for hiding this comment

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

it's required by @wordpress/api-fetch, which is a dependency of @wordpress/components

I think we should get rid of the jQuery dependency here. The issue in this case is that jQuery in core triggers events on its own events layer, which we can't listen to with native addEventListeners. @gziolo had a good idea: use wp.hooks to relay the jQuery event into a native event, which can then be listened to by api-fetch. Possibly by adding some code to do this as an inline script: https://github.com/WordPress/gutenberg/blob/master/lib/client-assets.php#L154-L161

I think it would also be a good idea to audit what we're depending on jQuery for in Gutenberg in general, and see what can be factored out.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I have applied it in WordPress/gutenberg#8311, so as soon as that is merged and published to npm I'll remove the jQuery dependency.

Copy link
Member Author

Choose a reason for hiding this comment

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

@ehg I have reverted the change and jQuery is not needed now in the bundle. Is this ready to go now?

@gwwar
Copy link
Contributor

gwwar commented Jul 25, 2018

Overall this looks very promising! Let's see what other folks like @ehg and @mtias think!

Another thing to check is to verify that bundle sizes don't change unexpectedly in http://iscalypsofastyet.com/branch?branch=add/devdocs-gutenberg-components

@@ -0,0 +1,47 @@
/** @format */
Copy link
Member

@gziolo gziolo Jul 26, 2018

Choose a reason for hiding this comment

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

Should we add this code in Gutenberg?

It might be more beneficial to improve docs and add examples inside Gutenberg directly rather than keep them in two places. We can even keep those examples inside README and extract them and auto-build components inside Calypso.

Copy link
Member Author

Choose a reason for hiding this comment

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

that would be really nice!

@gziolo
Copy link
Member

gziolo commented Jul 26, 2018

Screens look sweet 👍

@mmtr mmtr self-assigned this Jul 26, 2018
@mmtr mmtr force-pushed the add/devdocs-gutenberg-components branch 2 times, most recently from f5d7d5f to d91d18c Compare July 26, 2018 22:48
@mmtr mmtr added the DevDocs label Jul 27, 2018
@mmtr
Copy link
Member Author

mmtr commented Jul 28, 2018

Another thing to check is to verify that bundle sizes don't change unexpectedly in http://iscalypsofastyet.com/branch?branch=add/devdocs-gutenberg-components

Thanks for this suggestion @gwwar. From what I'm understanding from these tips, I'd say everything is normal. Most of the chunks that have been increased are async loaded. The most relevant change probably is that the vendors build has been increased by 10.9% after including jQuery.

@gziolo
Copy link
Member

gziolo commented Aug 2, 2018

All the latest changes published to npm:

 - @wordpress/api-fetch@1.1.0
 - @wordpress/blocks@1.0.2
 - @wordpress/components@1.1.1
 - @wordpress/core-data@1.0.3
 - @wordpress/editor@1.0.1
 - @wordpress/nux@1.0.2

This includes #8267 and another one which removes jQuery from the list of dependencies:
https://unpkg.com/@wordpress/api-fetch@1.1.0/package.json

@mmtr mmtr force-pushed the add/devdocs-gutenberg-components branch from d91d18c to 297d91c Compare August 2, 2018 12:39
mmtr and others added 12 commits August 2, 2018 22:16
Adding helper functions for getting the readme file path and knowing
whether to show the edit in GitHub link
Finishing uncompleted comment
Loading only the one needed scope for in the component playground
Getting back jQuery
Getting back jQuery
Adding comment to make clear jQuery is needed temporarily
@mmtr mmtr force-pushed the add/devdocs-gutenberg-components branch from 297d91c to 894a537 Compare August 2, 2018 20:19
Copy link
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

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

Nice work! ✨ Things are looking really good here.

@ehg or @gziolo did you have any other comments before we land this piece?

@@ -2,6 +2,7 @@
@import '../../node_modules/react-virtualized/styles';
@import '../../node_modules/draft-js/dist/Draft';
@import '../../node_modules/notifications-panel/src/boot/stylesheets/style';
@import '../../node_modules/@wordpress/components/build-style/style';
Copy link
Contributor

@gwwar gwwar Aug 3, 2018

Choose a reason for hiding this comment

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

Hmm, actually any ideas from folks on how to best audit that we're not colliding with existing selectors? Maybe it'd be safer to pull this in devdocs.scss ?

Any opinions here @Automattic/team-calypso ?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it'd be safer to pull this in devdocs.scss ?

Let's do this for the moment, we're still figuring out SASS imports.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done :)

@gziolo
Copy link
Member

gziolo commented Aug 3, 2018

It looks good, I don't have any comments specific for WordPress packages.

@ehg
Copy link
Member

ehg commented Aug 3, 2018

Other than the issue on where to import the SASS, I think we can land this. Nice work.

@mmtr mmtr merged commit febda23 into master Aug 3, 2018
@mmtr mmtr deleted the add/devdocs-gutenberg-components branch August 3, 2018 16:28
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DevDocs [Goal] Gutenberg Working towards full integration with Gutenberg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants