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

QuickEdit: Add Featured Image Control #64496

Merged
merged 51 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
785085b
Page Edit View: Implement Featured image page field
gigitux Aug 14, 2024
dd7e0a3
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 14, 2024
77f2217
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 21, 2024
433e45f
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 21, 2024
f890963
improve flow and style
gigitux Aug 22, 2024
c32622e
fix list layout
gigitux Aug 22, 2024
9a39fe6
improve design
gigitux Aug 23, 2024
5419b0a
remove not necessary style
gigitux Aug 23, 2024
68ef300
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 26, 2024
cd923f8
improve style
gigitux Aug 27, 2024
94335a4
improve default image control
gigitux Aug 27, 2024
030a28d
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 27, 2024
baf7a82
fix style
gigitux Aug 29, 2024
4095dab
remove not necessary configuration
gigitux Aug 29, 2024
23d8695
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 29, 2024
ec715ed
format _z-index.scss file
gigitux Aug 29, 2024
ea29690
improve style
gigitux Aug 29, 2024
106af4d
remove not necessary code
gigitux Aug 29, 2024
cc46724
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Aug 29, 2024
b11e923
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Sep 9, 2024
c6dffd7
fix focus
gigitux Sep 9, 2024
3c262d6
remove image field type
gigitux Sep 9, 2024
c053a9a
add comment
gigitux Sep 9, 2024
57faa8f
fix warning
gigitux Sep 9, 2024
d2eeb0e
fix image for deleted pages
gigitux Sep 9, 2024
05f0d1a
remove filename
gigitux Sep 10, 2024
c4db3b9
add border-radius
gigitux Sep 10, 2024
cd9fe2f
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Sep 18, 2024
8356977
migrate featured image to fields package
gigitux Sep 18, 2024
e27dec1
fix CSS
gigitux Sep 19, 2024
a187591
remove not necessary changes
gigitux Sep 19, 2024
8815e5a
fix type
gigitux Sep 19, 2024
a461d85
remove empty space
gigitux Sep 19, 2024
fcc2e6e
fix z-index gallery
gigitux Sep 19, 2024
577f836
fix overlapping and style
gigitux Sep 19, 2024
a3449c4
improve codestyle
gigitux Sep 19, 2024
2366429
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Sep 20, 2024
1b84ac0
use same placeholder style grid/list layout
gigitux Sep 20, 2024
6ca01ff
fix tsconfig
gigitux Sep 20, 2024
8e612d4
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Oct 22, 2024
c448c49
add type
gigitux Oct 22, 2024
2b595c2
remove mediaField from layout table
gigitux Oct 22, 2024
9cc6d80
update type
gigitux Oct 22, 2024
01a57a8
use text as type
gigitux Oct 22, 2024
7b1e40a
use media-utils package
gigitux Oct 22, 2024
6592d36
fix tsconfig
gigitux Oct 22, 2024
c2994e0
remove view prop
gigitux Oct 22, 2024
b039310
revert changes
gigitux Oct 22, 2024
42f90f4
generate package-lock.json
gigitux Oct 22, 2024
ea8e941
Merge branch 'trunk' of github.com:WordPress/gutenberg into add/page-…
gigitux Oct 23, 2024
e77b93b
generate package-lock.json
gigitux Oct 23, 2024
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 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ $z-layers: (

// Ensure footer stays above the preview field.
".dataviews-footer": 2,

// Needs to be below media library (.media-model) that has a z-index of 160000.
".components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown": 160000 - 10,
);

@function z-index( $key ) {
Expand Down
36 changes: 35 additions & 1 deletion packages/core-data/src/entity-types/attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ import type {

import type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';

interface MediaDetails {
width: number;
height: number;
file: string;
filesize: number;
sizes: { [ key: string ]: Size };
image_meta: ImageMeta;
original_image?: string;
}
interface ImageMeta {
aperture: string;
credit: string;
camera: string;
caption: string;
created_timestamp: string;
copyright: string;
focal_length: string;
iso: string;
shutter_speed: string;
title: string;
orientation: string;
keywords: any[];
}

interface Size {
file: string;
width: number;
height: number;
filesize?: number;
mime_type: string;
source_url: string;
uncropped?: boolean;
}

declare module './base-entity-records' {
export namespace BaseEntityRecords {
export interface Attachment< C extends Context > {
Expand Down Expand Up @@ -124,7 +158,7 @@ declare module './base-entity-records' {
/**
* Details about the media file, specific to its type.
*/
media_details: Record< string, string >;
media_details: MediaDetails;
/**
* The ID for the associated post of the attachment.
*/
Expand Down
8 changes: 6 additions & 2 deletions packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export type Field< Item > = {
/**
* Callback used to render the field. Defaults to `field.getValue`.
*/
render?: ComponentType< { item: Item } >;
render?: ComponentType< DataViewRenderFieldProps< Item > >;

/**
* Callback used to render an edit control for the field.
Expand Down Expand Up @@ -159,7 +159,7 @@ export type NormalizedField< Item > = Field< Item > & {
label: string;
header: string | ReactElement;
getValue: ( args: { item: Item } ) => any;
render: ComponentType< { item: Item } >;
render: ComponentType< DataViewRenderFieldProps< Item > >;
Edit: ComponentType< DataFormControlProps< Item > >;
sort: ( a: Item, b: Item, direction: SortDirection ) => number;
isValid: ( item: Item, context?: ValidationContext ) => boolean;
Expand All @@ -181,6 +181,10 @@ export type DataFormControlProps< Item > = {
hideLabelFromVision?: boolean;
};

export type DataViewRenderFieldProps< Item > = {
item: Item;
};

/**
* The filters applied to the dataset.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@wordpress/editor": "file:../editor",
"@wordpress/element": "file:../element",
"@wordpress/escape-html": "file:../escape-html",
"@wordpress/fields": "file:../fields",
"@wordpress/hooks": "file:../hooks",
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
Expand Down
10 changes: 8 additions & 2 deletions packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,19 @@ function PostEditForm( { postType, postId } ) {
);
const form = {
type: 'panel',
fields: [ 'title', 'status', 'date', 'author', 'comment_status' ],
fields: [
'featured_media',
'title',
'author',
'date',
'comment_status',
],
};
const onChange = ( edits ) => {
for ( const id of ids ) {
if (
edits.status !== 'future' &&
record.status === 'future' &&
record?.status === 'future' &&
new Date( record.date ) > new Date()
) {
edits.date = null;
Expand Down
55 changes: 3 additions & 52 deletions packages/edit-site/src/components/post-fields/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import clsx from 'clsx';
*/
import { __, sprintf } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import { featuredImageField } from '@wordpress/fields';
import {
createInterpolateElement,
useMemo,
Expand All @@ -33,11 +34,9 @@ import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
import {
LAYOUT_GRID,
LAYOUT_TABLE,
LAYOUT_LIST,
OPERATOR_IS_ANY,
} from '../../utils/constants';
import { default as Link, useLink } from '../routes/link';
import Media from '../media';
import { default as Link } from '../routes/link';

// See https://github.com/WordPress/gutenberg/issues/55886
// We do not support custom statutes at the moment.
Expand Down Expand Up @@ -81,46 +80,6 @@ const getFormattedDate = ( dateToDisplay ) =>
getDate( dateToDisplay )
);

function FeaturedImage( { item, viewType } ) {
const isDisabled = item.status === 'trash';
const { onClick } = useLink( {
postId: item.id,
postType: item.type,
canvas: 'edit',
} );
const hasMedia = !! item.featured_media;
const size =
viewType === LAYOUT_GRID
? [ 'large', 'full', 'medium', 'thumbnail' ]
: [ 'thumbnail', 'medium', 'large', 'full' ];
const media = hasMedia ? (
<Media
className="edit-site-post-list__featured-image"
id={ item.featured_media }
size={ size }
/>
) : null;
const renderButton = viewType !== LAYOUT_LIST && ! isDisabled;
return (
<div
className={ `edit-site-post-list__featured-image-wrapper is-layout-${ viewType }` }
>
{ renderButton ? (
<button
className="edit-site-post-list__featured-image-button"
type="button"
onClick={ onClick }
aria-label={ item.title?.rendered || __( '(no title)' ) }
>
{ media }
</button>
) : (
media
) }
</div>
);
}

function PostStatusField( { item } ) {
const status = STATUSES.find( ( { value } ) => value === item.status );
const label = status?.label || item.status;
Expand Down Expand Up @@ -190,15 +149,7 @@ function usePostFields( viewType ) {

const fields = useMemo(
() => [
{
id: 'featured-image',
label: __( 'Featured Image' ),
getValue: ( { item } ) => item.featured_media,
render: ( { item } ) => (
<FeaturedImage item={ item } viewType={ viewType } />
Copy link
Contributor

Choose a reason for hiding this comment

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

Two questions:

  1. Was there a reason to change the order here?
  2. What was the reason for inlining the render function instead of keeping the FeaturedImage component?

),
enableSorting: false,
},
featuredImageField,
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that we're moving the dataviews fields to the fields package one by one 👍 and fixing them (removing dependencies...)

{
label: __( 'Title' ),
id: 'title',
Expand Down
3 changes: 3 additions & 0 deletions packages/edit-site/src/components/post-fields/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown {
z-index: z-index(".components-popover.components-dropdown__content.dataforms-layouts-panel__field-dropdown");
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ export const defaultLayouts = {
layout: {
primaryField: 'title',
styles: {
'featured-image': {
width: '1%',
},
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
title: {
maxWidth: 300,
},
Expand All @@ -42,14 +39,14 @@ export const defaultLayouts = {
},
[ LAYOUT_GRID ]: {
layout: {
mediaField: 'featured-image',
mediaField: 'featured_media',
primaryField: 'title',
},
},
[ LAYOUT_LIST ]: {
layout: {
primaryField: 'title',
mediaField: 'featured-image',
mediaField: 'featured_media',
},
},
};
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import "../../dataviews/src/style.scss";
@import "../../fields/src/fields/featured-image/style.scss";

@import "./components/add-new-template/style.scss";
@import "./components/block-editor/style.scss";
Expand Down Expand Up @@ -30,6 +31,7 @@
@import "./components/editor-canvas-container/style.scss";
@import "./components/post-edit/style.scss";
@import "./components/post-list/style.scss";
@import "./components/post-fields/style.scss";
@import "./components/resizable-frame/style.scss";
@import "./hooks/push-changes-to-global-styles/style.scss";
@import "./components/global-styles/font-library-modal/style.scss";
Expand Down
4 changes: 4 additions & 0 deletions packages/fields/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Undocumented declaration.

Undocumented declaration.

### featuredImageField

Undocumented declaration.

### orderField

Undocumented declaration.
Expand Down
2 changes: 2 additions & 0 deletions packages/fields/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
"@wordpress/html-entities": "file:../html-entities",
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/media-utils": "file:../media-utils",
"@wordpress/notices": "file:../notices",
"@wordpress/patterns": "file:../patterns",
"@wordpress/primitives": "file:../primitives",
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/router": "file:../router",
"@wordpress/url": "file:../url",
"@wordpress/warning": "file:../warning",
"change-case": "4.1.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/fields/src/actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ export function getItemTitle( item: Post ) {
if ( typeof item.title === 'string' ) {
return decodeEntities( item.title );
}
if ( 'rendered' in item.title ) {
if ( item.title && 'rendered' in item.title ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In which case do we call this function with a non existent item.title ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember encountering some errors in the past, which led me to add this check. However, I’m no longer able to replicate the issue. I’m happy to revert the changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the changes with b039310.

return decodeEntities( item.title.rendered );
}
if ( 'raw' in item.title ) {
if ( item.title && 'raw' in item?.title ) {
return decodeEntities( item.title.raw );
}
return '';
Expand Down
Loading
Loading