Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
151f9e9
Show tags in the pre-publish panel
oandregal Aug 1, 2018
4d8af26
Extract to MaybeTagsPanel
oandregal Aug 1, 2018
1becfb8
Tags panel: control visibility
oandregal Aug 1, 2018
ed9753b
Tags panel: control visibility
oandregal Aug 1, 2018
dfb60da
Prevent crash if tags werent fetched yet
oandregal Aug 1, 2018
870b5e7
Remove unused code
oandregal Aug 1, 2018
7218b33
MaybeTagsPanel visibility
oandregal Aug 1, 2018
b0c1464
Suggest post format
oandregal Aug 2, 2018
c98522c
Do not open panels by default
oandregal Aug 2, 2018
83635bc
Do not mount component until taxonomy has been fetched
oandregal Aug 2, 2018
0a0cd18
Refactor for code clarity
oandregal Aug 2, 2018
9f53604
Tweak icon and copy text
oandregal Aug 2, 2018
ac4e132
Refactor to use ifCondition HOC
oandregal Aug 2, 2018
f8d386d
Make a more conversational post format
oandregal Aug 2, 2018
ab0bf56
Update text copy
oandregal Aug 2, 2018
9ef07b3
Update copy text
oandregal Aug 2, 2018
b2073e8
Update copy text for transations
oandregal Aug 2, 2018
603c7a1
Remove icons
oandregal Aug 3, 2018
e40d773
Improve copy text for tags panel
oandregal Aug 3, 2018
620dbbd
Add section title
oandregal Aug 3, 2018
1baa309
Update copy
oandregal Aug 3, 2018
053038d
chore: Make some tweaks to copy
tofumatt Aug 7, 2018
5d18b23
Shorten hasTags check
oandregal Aug 8, 2018
ed42917
Update to use suggestion
oandregal Aug 8, 2018
52ab3d3
Refactor logic for get suggestion
oandregal Aug 8, 2018
e230479
Update copy
oandregal Aug 8, 2018
713d5a6
Update copy
oandregal Aug 8, 2018
c1ac898
chore: Use clearer suggeston text
tofumatt Aug 8, 2018
afffd27
Refactor for clarity
oandregal Aug 9, 2018
dc3d61a
chore: Tweak name of component for readability
tofumatt Aug 13, 2018
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
2 changes: 1 addition & 1 deletion packages/editor/src/components/post-format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { withInstanceId, compose } from '@wordpress/compose';
*/
import PostFormatCheck from './check';

const POST_FORMATS = [
export const POST_FORMATS = [
Copy link
Member

Choose a reason for hiding this comment

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

Seems odd to replicate this here when it's likely in the API (single source of truth is good), but I get it's from before your commit. 🤷‍♂️

{ id: 'aside', caption: __( 'Aside' ) },
{ id: 'gallery', caption: __( 'Gallery' ) },
{ id: 'link', caption: __( 'Link' ) },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* External dependencies
*/
import { find, get, includes } from 'lodash';

/**
* WordPress dependencies.
*/
import { __, sprintf } from '@wordpress/i18n';
import { ifCondition, compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import { Button, PanelBody } from '@wordpress/components';

/**
* Internal dependencies.
*/
import { POST_FORMATS } from '../post-format';

const PostFormatSuggestion = ( { suggestedPostFormat, suggestionText, onUpdatePostFormat } ) => (
<Button isLink onClick={ () => onUpdatePostFormat( suggestedPostFormat ) }>
{ suggestionText }
</Button>
);

const PostFormatPanel = ( { suggestion, onUpdatePostFormat } ) => {
const panelBodyTitle = [
__( 'Suggestion:' ),
(
<span className="editor-post-publish-panel__link" key="label">
{ __( 'Use a post format' ) }
</span>
),
];

return (
<PanelBody initialOpen={ false } title={ panelBodyTitle } >
<p>
{ __( 'Your theme uses post formats to highlight different kinds of content, like images or videos. Apply a post format to see this special styling.' ) }
</p>
<p>
<PostFormatSuggestion
onUpdatePostFormat={ onUpdatePostFormat }
suggestedPostFormat={ suggestion.id }
suggestionText={ sprintf(
__( 'Apply the "%1$s" format.' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

This misses a translators comment. Will try to address it in #9363

suggestion.caption
) }
/>
</p>
</PanelBody>
);
};

const getSuggestion = ( supportedFormats, suggestedPostFormat ) => {
const formats = POST_FORMATS.filter( ( format ) => includes( supportedFormats, format.id ) );
return find( formats, ( format ) => format.id === suggestedPostFormat );
};

export default compose(
withSelect( ( select ) => {
const { getEditedPostAttribute, getSuggestedPostFormat } = select( 'core/editor' );
const supportedFormats = get( select( 'core' ).getThemeSupports(), [ 'formats' ], [] );
return {
currentPostFormat: getEditedPostAttribute( 'format' ),
suggestion: getSuggestion( supportedFormats, getSuggestedPostFormat() ),
};
} ),
withDispatch( ( dispatch ) => ( {
onUpdatePostFormat( postFormat ) {
dispatch( 'core/editor' ).editPost( { format: postFormat } );
},
} ) ),
ifCondition( ( { suggestion, currentPostFormat } ) => suggestion && suggestion.id !== currentPostFormat ),
)( PostFormatPanel );
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { compose, ifCondition } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { PanelBody } from '@wordpress/components';

import FlatTermSelector from '../post-taxonomies/flat-term-selector';

const TagsPanel = () => {
const panelBodyTitle = [
__( 'Suggestion:' ),
(
<span className="editor-post-publish-panel__link" key="label">
{ __( 'Add tags' ) }
</span>
),
];

return (
<PanelBody initialOpen={ false } title={ panelBodyTitle }>
<p>
{ __( 'Tags help users and search engines navigate your site and find your content. Add a few keywords to describe your post.' ) }
</p>
<FlatTermSelector slug={ 'post_tag' } />
</PanelBody>
);
};

class MaybeTagsPanel extends Component {
constructor( props ) {
super( props );
this.state = {
hadTagsWhenOpeningThePanel: props.hasTags,
};
}

/*
* We only want to show the tag panel if the post didn't have
* any tags when the user hit the Publish button.
*
* We can't use the prop.hasTags because it'll change to true
* if the user adds a new tag within the pre-publish panel.
* This would force a re-render and a new prop.hasTags check,
* hiding this panel and keeping the user from adding
* more than one tag.
*/
render() {
if ( ! this.state.hadTagsWhenOpeningThePanel ) {
return <TagsPanel />;
}

return null;
}
}

export default compose(
withSelect( ( select ) => {
const postType = select( 'core/editor' ).getCurrentPostType();
const tagsTaxonomy = select( 'core' ).getTaxonomy( 'post_tag' );
return {
areTagsFetched: tagsTaxonomy !== undefined,
isPostTypeSupported: tagsTaxonomy && tagsTaxonomy.types.some( ( type ) => type === postType ),
hasTags: tagsTaxonomy && select( 'core/editor' ).getEditedPostAttribute( tagsTaxonomy.rest_base ).length,
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 learned that pages don't have taxonomies the hard way #9082

};
} ),
ifCondition( ( { areTagsFetched, isPostTypeSupported } ) => isPostTypeSupported && areTagsFetched ),
)( MaybeTagsPanel );
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import PostVisibility from '../post-visibility';
import PostVisibilityLabel from '../post-visibility/label';
import PostSchedule from '../post-schedule';
import PostScheduleLabel from '../post-schedule/label';
import MaybeTagsPanel from './maybe-tags-panel';
import MaybePostFormatPanel from './maybe-post-format-panel';

function PostPublishPanelPrepublish( {
hasPublishAction,
Expand All @@ -41,6 +43,8 @@ function PostPublishPanelPrepublish( {
] }>
<PostSchedule />
</PanelBody>
<MaybePostFormatPanel />
Copy link
Member

Choose a reason for hiding this comment

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

Have you checked how <PostSchedule / or <PostVisibility /> are implemented?

https://github.com/WordPress/gutenberg/tree/master/packages/editor/src/components/post-schedule
https://github.com/WordPress/gutenberg/tree/master/packages/editor/src/components/post-visibility

They contain two parts the components which render the panel's body and a wrapper component with suffix Check. It would be nice to align.

@youknowriad, why we don't wrap those components with checks in the publish panel? We do it in the sidebar:
https://github.com/WordPress/gutenberg/blob/master/edit-post/components/sidebar/post-schedule/index.js#L15-L35

Copy link
Contributor

Choose a reason for hiding this comment

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

Because it's already taken care of in the component itself. In the sidebar, we don't want the extra panels if the check is false, here, there's no extra wrappers added.

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 can extract the ifCondition to a Check component if that's preferred. We use a variety of patterns through the codebase, though, so unless we want to consolidate towards using a particular one I'm happy as it is.

<MaybeTagsPanel />
{ children }
</Fragment>
) }
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/components/post-publish-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@
.post-publish-panel__postpublish-header {
font-weight: 500;
}

.post-publish-panel__tip {
color: $alert-yellow;
}