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

Data View - Page View: Add Featured Image Control #64496

Open
wants to merge 36 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 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
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
3 changes: 3 additions & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ $z-layers: (

// Ensure quick actions toolbar appear above pagination
".dataviews-bulk-actions-toolbar": 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
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const fields = [
{ value: 'published', label: 'Published' },
],
},
{
id: 'image',
label: 'Image',
type: 'image' as const,
},
];

export const Default = ( { type }: { type: 'panel' | 'regular' } ) => {
Expand All @@ -87,6 +92,7 @@ export const Default = ( { type }: { type: 'panel' | 'regular' } ) => {
reviewer: 'fulano',
date: '2021-01-01T12:00:00',
birthdate: '1950-02-23T12:00:00',
image: 'https://picsum.photos/200',
} );

const form = {
Expand All @@ -98,6 +104,7 @@ export const Default = ( { type }: { type: 'panel' | 'regular' } ) => {
'status',
'date',
'birthdate',
'image',
],
};

Expand Down
71 changes: 71 additions & 0 deletions packages/dataviews/src/dataform-controls/image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* WordPress dependencies
*/
import {
Button,
FormFileUpload,
__experimentalHStack as HStack,
} from '@wordpress/components';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
*/
import type { DataFormControlProps } from '../types';

export default function Image< Item >( {
data,
field,
onChange,
}: DataFormControlProps< Item > ) {
const { id } = field;
const value = field.getValue( { item: data } );

const onChangeControl = useCallback(
( newValue: string ) =>
onChange( {
[ id ]: newValue,
} ),
[ id, onChange ]
);

return (
<fieldset className="dataviews-controls__image">
{ value && (
<img
src={ value }
alt=""
style={ {
maxWidth: '200px',
maxHeight: '200px',
} }
/>
) }
<HStack>
<FormFileUpload
accept="image/*"
onChange={ ( event ) => {
if ( event.target.files?.length ) {
const objectUrl = URL.createObjectURL(
event.target.files[ 0 ]
);
onChangeControl( objectUrl );
}
} }
>
<Button variant="primary">Upload</Button>
</FormFileUpload>
{ value && (
<Button
variant="secondary"
onClick={ () => {
onChangeControl( '' );
} }
>
Clean
</Button>
) }
</HStack>
</fieldset>
);
}
2 changes: 2 additions & 0 deletions packages/dataviews/src/dataform-controls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import integer from './integer';
import radio from './radio';
import select from './select';
import text from './text';
import image from './image';

interface FormControls {
[ key: string ]: ComponentType< DataFormControlProps< any > >;
Expand All @@ -27,6 +28,7 @@ const FORM_CONTROLS: FormControls = {
radio,
select,
text,
image,
};

export function getControl< Item >(
Expand Down
9 changes: 9 additions & 0 deletions packages/dataviews/src/field-types/image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Internal dependencies
*/

export default {
sort: () => 0,
isValid: () => true,
Edit: 'image',
};
5 changes: 5 additions & 0 deletions packages/dataviews/src/field-types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { FieldType, SortDirection, ValidationContext } from '../types';
import { default as integer } from './integer';
import { default as text } from './text';
import { default as datetime } from './datetime';
import { default as image } from './image';

/**
*
Expand All @@ -25,6 +26,10 @@ export default function getFieldTypeDefinition( type?: FieldType ) {
return datetime;
}

if ( 'image' === type ) {
return image;
}

return {
sort: ( a: any, b: any, direction: SortDirection ) => {
if ( typeof a === 'number' && typeof b === 'number' ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dataviews/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type Operator =
| 'isAll'
| 'isNotAll';

export type FieldType = 'text' | 'integer' | 'datetime';
export type FieldType = 'text' | 'integer' | 'datetime' | 'image';

export type ValidationContext = {
elements?: Option[];
Expand Down
8 changes: 7 additions & 1 deletion packages/edit-site/src/components/post-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ 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 ) {
Expand Down
Loading
Loading