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

Components: Expose the Editor's reusable components #3389

Merged
merged 2 commits into from
Nov 10, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions editor/components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Editor Components

This folder holds reusable editor components exported by the `editor` module.
These components combined as children of the `EditorProvider` component can be use to build alternative Editor Layouts.

## Which components should live in this folder?

- A component in this folder is any component you can reuse to build your own editor's layout.
- It shouldn't include any "layout styling".
- the only requirement to use this component is to to be included as a children of EditorProvider in the elements' hierarchy.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import { Component } from '@wordpress/element';
/**
* Internal dependencies
*/
import { autosave } from '../actions';
import { autosave } from '../../actions';
import {
isEditedPostDirty,
isEditedPostSaveable,
} from '../selectors';
} from '../../selectors';

export class AutosaveMonitor extends Component {
componentDidUpdate( prevProps ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { __ } from '@wordpress/i18n';
*/
import './style.scss';
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that we don't prefix document-outline class name with editor- like in all other places. We can fix it in another PR if it isn't designed this way on purpose.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, it should be prefixed. This is documented in coding guidelines, but I'm now noticing they were written prior to other folders containing components:

https://github.com/WordPress/gutenberg/blob/master/docs/coding-guidelines.md#css

Any default export of a folder's index.js must be prefixed with editor- followed by the directory name in which it resides:

.editor-[ directory name ]

The intended convention is:

  • [ root module name ]-[ current directory name ]
    • Example: editor-foo
  • [ root module name ]-[ current directory name ]__[ descendant description ]
    • Example: editor-foo__child
  • [ root module name ]-[ current directory name ]__[ descendant description ].is-[ modifier description ]
    • Example: editor-foo__child.is-green

import DocumentOutlineItem from './item';
import { getBlocks } from '../selectors';
import { selectBlock } from '../actions';
import { getBlocks } from '../../selectors';
import { selectBlock } from '../../actions';

/**
* Module constants
Expand Down
38 changes: 38 additions & 0 deletions editor/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Post Related Components
export { default as AutosaveMonitor } from './autosave-monitor';
export { default as DocumentOutline } from './document-outline';
export { default as MetaBoxes } from './meta-boxes';
export { default as PageAttributes } from './page-attributes';
export { default as PageAttributesCheck } from './page-attributes/check';
export { default as PostAuthor } from './post-author';
export { default as PostAuthorCheck } from './post-author/check';
export { default as PostComments } from './post-comments';
export { default as PostExcerpt } from './post-excerpt';
export { default as PostFeaturedImage } from './post-featured-image';
export { default as PostFormat } from './post-format';
export { default as PostFormatCheck } from './post-format/check';
export { default as PostLastRevision } from './post-last-revision';
export { default as PostLastRevisionCheck } from './post-last-revision/check';
export { default as PostPendingStatus } from './post-pending-status';
export { default as PostPendingStatusCheck } from './post-pending-status/check';
export { default as PostPingbacks } from './post-pingbacks';
export { default as PostPreviewButton } from './post-preview-button';
export { default as PostPublishButton } from './post-publish-button';
export { default as PostPublishButtonLabel } from './post-publish-button/label';
export { default as PostSavedState } from './post-saved-state';
export { default as PostSchedule } from './post-schedule';
export { default as PostScheduleLabel } from './post-schedule/label';
export { default as PostSticky } from './post-sticky';
export { default as PostStickyCheck } from './post-sticky/check';
export { default as PostTaxonomies } from './post-taxonomies';
export { default as PostTrash } from './post-trash';
export { default as PostVisibility } from './post-visibility';
export { default as PostVisibilityLabel } from './post-visibility/label';
export { default as UnsavedChangesWarning } from './unsaved-changes-warning';
Copy link
Member

Choose a reason for hiding this comment

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

It seems like some components that depend on the post state could have Post prefix, too. PageAttributes makes it harder to come up with a good pattern here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, did this change for one or two components but gave up, we could do it separately one by one.

Copy link
Member

Choose a reason for hiding this comment

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

I feel your pain, it can be combined with README task. We would have to leave an additional note when applicable.

export { default as WordCount } from './word-count';

// Content Related Components
export { default as Inserter } from './inserter';

// State Related Components
export { default as EditorProvider } from './provider';
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import { Component } from '@wordpress/element';
* Internal dependencies
*/
import InserterMenu from './menu';
import { getBlockInsertionPoint, getEditorMode } from '../selectors';
import { getBlockInsertionPoint, getEditorMode } from '../../selectors';
import {
insertBlock,
setBlockInsertionPoint,
clearBlockInsertionPoint,
hideInsertionPoint,
} from '../actions';
} from '../../actions';

class Inserter extends Component {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { getCategories, getBlockTypes, BlockIcon } from '@wordpress/blocks';
* Internal dependencies
*/
import './style.scss';
import { getBlocks, getRecentlyUsedBlocks } from '../selectors';
import { showInsertionPoint, hideInsertionPoint } from '../actions';
import { getBlocks, getRecentlyUsedBlocks } from '../../selectors';
import { showInsertionPoint, hideInsertionPoint } from '../../actions';

const { TAB, LEFT, UP, RIGHT, DOWN } = keycodes;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { connect } from 'react-redux';
*/
import MetaBoxesIframe from './meta-boxes-iframe';
import MetaBoxesPanel from './meta-boxes-panel';
import { getMetaBox } from '../selectors';
import { getMetaBox } from '../../selectors';

function MetaBox( { location, isActive, usePanel = false } ) {
function MetaBoxes( { location, isActive, usePanel = false } ) {
if ( ! isActive ) {
return null;
}
Expand All @@ -30,4 +30,4 @@ function MetaBox( { location, isActive, usePanel = false } ) {

export default connect( ( state, ownProps ) => ( {
isActive: getMetaBox( state, ownProps.location ).isActive,
} ) )( MetaBox );
} ) )( MetaBoxes );
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { Component } from '@wordpress/element';
*/
import './style.scss';
import './meta-box-iframe.scss';
import { handleMetaBoxReload, metaBoxStateChanged } from '../../actions';
import { getMetaBox, isSavingPost } from '../../selectors';
import { handleMetaBoxReload, metaBoxStateChanged } from '../../../actions';
import { getMetaBox, isSavingPost } from '../../../selectors';

class MetaBoxesIframe extends Component {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { withAPIData } from '@wordpress/components';
/**
* Internal dependencies
*/
import { getCurrentPostType } from '../selectors';
import { getCurrentPostType } from '../../selectors';

export function PageAttributesCheck( { postType, children } ) {
const supportsPageAttributes = get( postType.data, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { withInstanceId } from '@wordpress/components';
* Internal dependencies
*/
import PageAttributesCheck from './check';
import { editPost } from '../actions';
import { getEditedPostAttribute } from '../selectors';
import { editPost } from '../../actions';
import { getEditedPostAttribute } from '../../selectors';

export function PageAttributes( { onUpdateOrder, instanceId, order } ) {
const setUpdatedOrder = ( event ) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { Component } from '@wordpress/element';
* Internal dependencies
*/
import PostAuthorCheck from './check';
import { getEditedPostAttribute } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostAttribute } from '../../selectors';
import { editPost } from '../../actions';

export class PostAuthor extends Component {
constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { FormToggle, withInstanceId } from '@wordpress/components';
/**
* Internal Dependencies
*/
import { getEditedPostAttribute } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostAttribute } from '../../selectors';
import { editPost } from '../../actions';

function PostComments( { commentStatus = 'open', instanceId, ...props } ) {
const onToggleComments = () => props.editPost( { comment_status: commentStatus === 'open' ? 'closed' : 'open' } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { ExternalLink } from '@wordpress/components';
* Internal Dependencies
*/
import './style.scss';
import { getEditedPostExcerpt } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostExcerpt } from '../../selectors';
import { editPost } from '../../actions';

function PostExcerpt( { excerpt, onUpdateExcerpt } ) {
const onChange = ( event ) => onUpdateExcerpt( event.target.value );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { MediaUploadButton } from '@wordpress/blocks';
* Internal dependencies
*/
import './style.scss';
import { getEditedPostAttribute } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostAttribute } from '../../selectors';
import { editPost } from '../../actions';

function PostFeaturedImage( { featuredImageId, onUpdateImage, onRemoveImage, media } ) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { withAPIData } from '@wordpress/components';
/**
* Internal dependencies
*/
import { getCurrentPostType } from '../selectors';
import { getCurrentPostType } from '../../selectors';

function PostFormatCheck( { postType, children } ) {
if ( ! get( postType.data, [ 'supports', 'post-formats' ] ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { withInstanceId } from '@wordpress/components';
*/
import './style.scss';
import PostFormatCheck from './check';
import { getEditedPostAttribute, getSuggestedPostFormat } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostAttribute, getSuggestedPostFormat } from '../../selectors';
import { editPost } from '../../actions';

const POST_FORMATS = [
{ id: 'aside', caption: __( 'Aside' ) },
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { connect } from 'react-redux';
/**
* Internal dependencies
*/
import { getCurrentPostLastRevisionId } from '../selectors';
import { getCurrentPostLastRevisionId } from '../../selectors';

function PostLastRevisionCheck( { lastRevisionId, children } ) {
if ( ! lastRevisionId ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import PostLastRevisionCheck from './check';
import {
getCurrentPostLastRevisionId,
getCurrentPostRevisionsCount,
} from '../selectors';
import { getWPAdminURL } from '../utils/url';
} from '../../selectors';
import { getWPAdminURL } from '../../utils/url';

function LastRevision( { lastRevisionId, revisionsCount } ) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { withAPIData } from '@wordpress/components';
/**
* Internal dependencies
*/
import { isCurrentPostPublished } from '../selectors';
import { isCurrentPostPublished } from '../../selectors';

export function PostPendingStatusCheck( { isPublished, children, user } ) {
if ( isPublished || ! user.data || ! user.data.capabilities.publish_posts ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { FormToggle, withInstanceId } from '@wordpress/components';
* Internal dependencies
*/
import PostPendingStatusCheck from './check';
import { getEditedPostAttribute } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostAttribute } from '../../selectors';
import { editPost } from '../../actions';

export function PostPendingStatus( { instanceId, status, onUpdateStatus } ) {
const pendingId = 'pending-toggle-' + instanceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { FormToggle, withInstanceId } from '@wordpress/components';
/**
* Internal Dependencies
*/
import { getEditedPostAttribute } from '../selectors';
import { editPost } from '../actions';
import { getEditedPostAttribute } from '../../selectors';
import { editPost } from '../../actions';

function PostPingbacks( { pingStatus = 'open', instanceId, ...props } ) {
const onTogglePingback = () => props.editPost( { ping_status: pingStatus === 'open' ? 'closed' : 'open' } );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../../selectors';
import { autosave } from '../../actions';

export class PreviewButton extends Component {
export class PostPreviewButton extends Component {
constructor() {
super( ...arguments );

Expand Down Expand Up @@ -124,4 +124,4 @@ export default connect(
modified: getEditedPostAttribute( state, 'modified' ),
} ),
{ autosave }
)( PreviewButton );
)( PostPreviewButton );
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import { shallow } from 'enzyme';
/**
* Internal dependencies
*/
import { PreviewButton } from '../';
import { PostPreviewButton } from '../';

describe( 'PreviewButton', () => {
describe( 'PostPreviewButton', () => {
describe( 'constructor()', () => {
it( 'should initialize with non-awaiting-save', () => {
const instance = new PreviewButton( {} );
const instance = new PostPreviewButton( {} );

expect( instance.state.isAwaitingSave ).toBe( false );
} );
} );

describe( 'getWindowTarget()', () => {
it( 'returns a string unique to the post id', () => {
const instance = new PreviewButton( {
const instance = new PostPreviewButton( {
postId: 1,
} );

Expand All @@ -30,7 +30,7 @@ describe( 'PreviewButton', () => {
describe( 'componentDidUpdate()', () => {
it( 'should change popup location if save finishes', () => {
const wrapper = shallow(
<PreviewButton
<PostPreviewButton
postId={ 1 }
link="https://wordpress.org/?p=1"
isSaveable
Expand Down Expand Up @@ -63,7 +63,7 @@ describe( 'PreviewButton', () => {
} );

const wrapper = shallow(
<PreviewButton { ...props } autosave={ autosave } />
<PostPreviewButton { ...props } autosave={ autosave } />
);

wrapper.simulate( 'click', { preventDefault } );
Expand Down Expand Up @@ -115,7 +115,7 @@ describe( 'PreviewButton', () => {
describe( 'render()', () => {
it( 'should render a link', () => {
const wrapper = shallow(
<PreviewButton
<PostPreviewButton
postId={ 1 }
isSaveable
link="https://wordpress.org/?p=1" />
Expand All @@ -128,7 +128,7 @@ describe( 'PreviewButton', () => {

it( 'should be disabled if post is not saveable', () => {
const wrapper = shallow(
<PreviewButton
<PostPreviewButton
postId={ 1 }
link="https://wordpress.org/?p=1" />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
isEditedPostPublishable,
} from '../../selectors';

export function PublishButton( {
export function PostPublishButton( {
isSaving,
onStatusChange,
onSave,
Expand All @@ -49,7 +49,7 @@ export function PublishButton( {
publishStatus = 'publish';
}

const className = classnames( 'editor-publish-button', {
const className = classnames( 'editor-post-publish-button', {
'is-saving': isSaving,
} );

Expand Down Expand Up @@ -95,4 +95,4 @@ const applyWithAPIData = withAPIData( () => {
export default flowRight( [
applyConnect,
applyWithAPIData,
] )( PublishButton );
] )( PostPublishButton );
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.editor-publish-button.is-saving,
.editor-publish-button.is-saving:disabled {
.editor-post-publish-button.is-saving,
.editor-post-publish-button.is-saving:disabled {
position: relative;

// These styles overrides the disabled state with the button primary styles
Expand Down
Loading