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

Add header to the quick edit when bulk editing #67390

Merged
merged 8 commits into from
Dec 6, 2024
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
16 changes: 8 additions & 8 deletions packages/base-styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@
@mixin heading-small() {
@include _text-heading();
font-size: $font-size-x-small;
line-height: $line-height-x-small;
line-height: $font-line-height-x-small;
Copy link
Member

Choose a reason for hiding this comment

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

Ah, nice catch. It looks like these weren't working since #65418 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah correct, although I don't think the Mixin's where being used anywhere within GB yet.

}

@mixin heading-medium() {
@include _text-heading();
font-size: $font-size-medium;
line-height: $line-height-small;
line-height: $font-line-height-small;
}

@mixin heading-large() {
@include _text-heading();
font-size: $font-size-large;
line-height: $line-height-small;
line-height: $font-line-height-small;
}

@mixin heading-x-large() {
@include _text-heading();
font-size: $font-size-x-large;
line-height: $line-height-medium;
line-height: $font-line-height-medium;
}

@mixin heading-2x-large() {
Expand All @@ -48,25 +48,25 @@
@mixin body-small() {
@include _text-body();
font-size: $font-size-small;
line-height: $line-height-x-small;
line-height: $font-line-height-x-small;
}

@mixin body-medium() {
@include _text-body();
font-size: $font-size-medium;
line-height: $line-height-small;
line-height: $font-line-height-small;
}

@mixin body-large() {
@include _text-body();
font-size: $font-size-large;
line-height: $line-height-medium;
line-height: $font-line-height-medium;
}

@mixin body-x-large() {
@include _text-body();
font-size: $font-size-x-large;
line-height: $line-height-x-large;
line-height: $font-line-height-x-large;
}

/**
Expand Down
88 changes: 88 additions & 0 deletions packages/edit-site/src/components/post-edit/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* WordPress dependencies
*/
import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
Icon,
__experimentalText as Text,
} from '@wordpress/components';
import { useMemo } from '@wordpress/element';
import {
privateApis as editorPrivateApis,
store as editorStore,
} from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { sprintf, __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { unlock } from '../../lock-unlock';

const { PostCardPanel } = unlock( editorPrivateApis );

export default function PostEditHeader( { postType, postId } ) {
const ids = useMemo( () => postId.split( ',' ), [ postId ] );
const { icon, labels } = useSelect(
( select ) => {
const { getEditedEntityRecord, getPostType } = select( coreStore );
const { getPostIcon } = unlock( select( editorStore ) );
const _record = getEditedEntityRecord(
'postType',
postType,
ids[ 0 ]
);

return {
icon: getPostIcon( postType, {
area: _record?.area,
} ),
labels: getPostType( postType )?.labels,
};
},
[ ids, postType ]
);

if ( ids.length === 1 ) {
return (
<PostCardPanel
postType={ postType }
postId={ parseInt( ids[ 0 ], 10 ) }
/>
);
}

return (
<VStack spacing={ 1 } className="edit-site-post-edit-header">
Copy link
Contributor

Choose a reason for hiding this comment

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

Part of me wonders if PostCardPanel should support multiple posts (as this seems to recreate a similar UI)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I could move it there, I initially decided not to given that PostCardPanel was initially written for the single header within the site editor.
Also if we do add support, should it be moved to the editor package instead?

<HStack spacing={ 2 } align="center" justify="normal">
<Icon
className="edit-site-post-edit-header__icon"
icon={ icon }
/>
<Text
numberOfLines={ 2 }
truncate
className="edit-site-post-edit-header__title"
as="h2"
>
{ labels?.name &&
sprintf(
// translators: %i number of selected items %s: Name of the plural post type e.g: "Posts".
__( '%i %s' ),
ids.length,
labels?.name
) }
</Text>
</HStack>
<Text className="edit-site-post-edit-header__description">
{ sprintf(
// translators: %s: Name of the plural post type e.g: "Posts".
__( 'Changes will be applied to all selected %s.' ),
labels?.name.toLowerCase()
) }
</Text>
</VStack>
);
}
8 changes: 3 additions & 5 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import { privateApis as editorPrivateApis } from '@wordpress/editor';
* Internal dependencies
*/
import Page from '../page';
import PostEditHeader from '../post-edit/header';
import { unlock } from '../../lock-unlock';
import usePatternSettings from '../page-patterns/use-pattern-settings';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

const { PostCardPanel, usePostFields } = unlock( editorPrivateApis );
const { usePostFields } = unlock( editorPrivateApis );

const fieldsWithBulkEditSupport = [
'title',
Expand Down Expand Up @@ -76,7 +77,6 @@ function PostEditForm( { postType, postId } ) {
id: 'featured_media',
layout: 'regular',
},
'title',
{
id: 'status',
label: __( 'Status & Visibility' ),
Expand Down Expand Up @@ -159,9 +159,7 @@ function PostEditForm( { postType, postId } ) {

return (
<VStack spacing={ 4 }>
{ ids.length === 1 && (
<PostCardPanel postType={ postType } postId={ ids[ 0 ] } />
) }
<PostEditHeader postType={ postType } postId={ postId } />
<DataForm
data={ ids.length === 1 ? record : multiEdits }
fields={ fieldsWithDependency }
Expand Down
10 changes: 10 additions & 0 deletions packages/edit-site/src/components/post-edit/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
padding-top: $grid-unit-20;
}
}

.edit-site-post-edit-header {
.edit-site-post-edit-header__description {
color: $gray-700;
}

.edit-site-post-edit-header__title {
@include heading-medium();
}
}
1 change: 1 addition & 0 deletions packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
mix-blend-mode: normal;
display: block;
}

/* stylelint-enable */

body.js #wpadminbar {
Expand Down
4 changes: 3 additions & 1 deletion packages/editor/src/components/document-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const MotionButton = motion( Button );
*/
export default function DocumentBar( props ) {
const {
postId,
postType,
postTypeLabel,
documentTitle,
Expand Down Expand Up @@ -93,6 +94,7 @@ export default function DocumentBar( props ) {
const _postTypeLabel = getPostType( _postType )?.labels?.singular_name;

return {
postId: _postId,
postType: _postType,
postTypeLabel: _postTypeLabel,
documentTitle: _document.title,
Expand Down Expand Up @@ -120,7 +122,7 @@ export default function DocumentBar( props ) {
const title = props.title || entityTitle;
const icon = props.icon;

const pageTypeBadge = usePageTypeBadge();
const pageTypeBadge = usePageTypeBadge( postId );

const mountedRef = useRef( false );
useEffect( () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function PostCardPanel( {
[ postId, postType ]
);

const pageTypeBadge = usePageTypeBadge();
const pageTypeBadge = usePageTypeBadge( postId );

return (
<div className="editor-post-card-panel">
Expand All @@ -78,9 +78,7 @@ export default function PostCardPanel( {
numberOfLines={ 2 }
truncate
className="editor-post-card-panel__title"
weight={ 500 }
as="h2"
lineHeight="20px"
>
{ title ? decodeEntities( title ) : __( 'No title' ) }
{ pageTypeBadge && (
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/post-card-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
width: 100%;

&.editor-post-card-panel__title {
@include heading-medium();
margin: 0;
padding: 2px 0;
display: flex;
Expand Down
11 changes: 3 additions & 8 deletions packages/editor/src/utils/pageTypeBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { store as editorStore } from '../store';

/**
* Custom hook to get the page type badge for the current post on edit site view.
*
* @param {number} postId postId of the current post being edited.
*/
export default function usePageTypeBadge() {
export default function usePageTypeBadge( postId ) {
const { isFrontPage, isPostsPage } = useSelect( ( select ) => {
const { getCurrentPostId } = select( editorStore );
const { canUser, getEditedEntityRecord } = select( coreStore );
const postId = getCurrentPostId();
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
Expand Down
Loading