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

Chrome: Adding the post excerpt panel #871

Merged
merged 4 commits into from
May 24, 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
1 change: 1 addition & 0 deletions editor/assets/stylesheets/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $z-layers: (
'.editor-visual-editor__block {core/image aligned left or right}': 10,
'.editor-visual-editor__block-controls': 1,
'.editor-header': 20,
'.editor-post-visibility__dialog': 30,
);

@function z-index( $key ) {
Expand Down
10 changes: 8 additions & 2 deletions editor/selectors.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { first, last } from 'lodash';
import { first, last, get } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -60,10 +60,16 @@ export function getEditedPostVisibility( state ) {

export function getEditedPostTitle( state ) {
return state.editor.edits.title === undefined
? state.currentPost.title.raw
? get( state.currentPost, 'title.raw' )
: state.editor.edits.title;
}

export function getEditedPostExcerpt( state ) {
return state.editor.edits.excerpt === undefined
? get( state.currentPost, 'excerpt.raw' )
: state.editor.edits.excerpt;
}

export function getEditedPostPreviewLink( state ) {
const link = state.currentPost.link;
if ( ! link ) {
Expand Down
52 changes: 52 additions & 0 deletions editor/sidebar/post-excerpt/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* External dependencies
*/
import { connect } from 'react-redux';

/**
* WordPress dependencies
*/
import { __ } from 'i18n';
import PanelBody from 'components/panel/body';

/**
* Internal Dependencies
*/
import './style.scss';
import { getEditedPostExcerpt } from '../../selectors';
import { editPost } from '../../actions';

function PostExcerpt( { excerpt, onUpdateExcerpt } ) {
const onChange = ( event ) => onUpdateExcerpt( event.target.value );

return (
<PanelBody title={ __( 'Excerpt' ) } initialOpen={ false }>
<textarea
className="editor-post-excerpt__textarea"
onChange={ onChange }
value={ excerpt }
placeholder={ __( 'Write an excerpt (optional)' ) }
aria-label={ __( 'Excerpt' ) }
/>
<a href="https://codex.wordpress.org/Excerpt" target="_blank">
{ __( 'Learn more about manual excerpts' ) }
</a>
</PanelBody>
);
}

export default connect(
( state ) => {
return {
excerpt: getEditedPostExcerpt( state ),
};
},
( dispatch ) => {
return {
onUpdateExcerpt( excerpt ) {
dispatch( editPost( { excerpt } ) );
},
};
}
)( PostExcerpt );

6 changes: 6 additions & 0 deletions editor/sidebar/post-excerpt/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.editor-post-excerpt__textarea {
width: 100%;
height: 80px;
margin-top: 20px;
margin-bottom: 10px;
}
2 changes: 2 additions & 0 deletions editor/sidebar/post-settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import IconButton from 'components/icon-button';
*/
import './style.scss';
import PostStatus from '../post-status';
import PostExcerpt from '../post-excerpt';

const PostSettings = ( { toggleSidebar } ) => {
return (
Expand All @@ -30,6 +31,7 @@ const PostSettings = ( { toggleSidebar } ) => {
</div>
</PanelHeader>
<PostStatus />
<PostExcerpt />
</Panel>
);
};
Expand Down
1 change: 1 addition & 0 deletions editor/sidebar/post-visibility/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
background: $white;
padding: 10px;
min-width: 240px;
z-index: z-index( '.editor-post-visibility__dialog' );
}

.editor-post-visibility__dialog-arrow {
Expand Down
29 changes: 29 additions & 0 deletions editor/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getPostEdits,
getEditedPostStatus,
getEditedPostTitle,
getEditedPostExcerpt,
getEditedPostVisibility,
getEditedPostPreviewLink,
getBlock,
Expand Down Expand Up @@ -223,6 +224,34 @@ describe( 'selectors', () => {
} );
} );

describe( 'getEditedPostExcerpt', () => {
it( 'should return the post saved excerpt if the excerpt is not edited', () => {
const state = {
currentPost: {
excerpt: { raw: 'sassel' },
},
editor: {
edits: { status: 'private' },
},
};

expect( getEditedPostExcerpt( state ) ).to.equal( 'sassel' );
} );

it( 'should return the edited excerpt', () => {
const state = {
currentPost: {
excerpt: { raw: 'sassel' },
},
editor: {
edits: { excerpt: 'youcha' },
},
};

expect( getEditedPostExcerpt( state ) ).to.equal( 'youcha' );
} );
} );

describe( 'getEditedPostVisibility', () => {
it( 'should return public by default', () => {
const state = {
Expand Down