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

Move gallery link controls to the block toolbar #62762

Merged
merged 28 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0e6cc04
Move link dropdown to toolbar in gallery block
akasunil Jun 22, 2024
cac26ab
Update e2e test for gallery block's setting
akasunil Jun 23, 2024
a0c3301
Fix e2e test for gallery block images link setting
akasunil Jun 23, 2024
ebd5a36
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jun 25, 2024
7e6f2c6
Fix unit test
akasunil Jun 25, 2024
5ea3de1
Synced with trunk and resolved conflicts
akasunil Jul 14, 2024
0c7a78b
Synced with trunk
akasunil Jul 20, 2024
ea17d8d
Added ToolbarDropdownMenu component instead of DropdownMenu
akasunil Jul 20, 2024
88b75ac
remove remove extra padding around link icon
akasunil Jul 20, 2024
cd83a3e
Remove unused components
akasunil Jul 20, 2024
6f40925
Revert "Synced with trunk"
akasunil Jul 20, 2024
c795bfa
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jul 20, 2024
694e665
Improve snackbar notices for gallery block link control select
akasunil Jul 22, 2024
8ad541b
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jul 24, 2024
b0f3339
Add constant for lightbox option in link control for gallery block
akasunil Jul 24, 2024
8107157
Update getHrefAndDestination function to handle Link control value ch…
akasunil Jul 24, 2024
eddabc7
Add lightbox option in link control of gallery block
akasunil Jul 24, 2024
3940299
Add info text for lightbox option in link control for gallery block
akasunil Jul 24, 2024
f3e8341
Set info text for lightbox option in single line
akasunil Jul 24, 2024
a321288
Merge branch 'trunk' of personal.github.com:WordPress/gutenberg into …
akasunil Jul 25, 2024
1228c00
reverting expand of click option changes
akasunil Jul 26, 2024
31dcc28
add change to resolve conflict
akasunil Jul 26, 2024
0bf1cac
fix: Avoid unsupported Gallery MenuGroup usage (#63953)
dcalhoun Jul 26, 2024
9456d3d
removing lightbox changes from edit component of gallery block
akasunil Jul 26, 2024
7976411
Removing unneccessory class
akasunil Jul 26, 2024
37a191b
Update link control lable in gallery block
akasunil Jul 27, 2024
893666c
Update label in unit test
akasunil Jul 27, 2024
16f87e7
Update text in snapshot
akasunil Jul 27, 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
88 changes: 75 additions & 13 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
ToggleControl,
RangeControl,
Spinner,
MenuGroup,
MenuItem,
ToolbarDropdownMenu,
withNotices,
} from '@wordpress/components';
import {
Expand All @@ -33,6 +36,12 @@ import { View } from '@wordpress/primitives';
import { createBlock } from '@wordpress/blocks';
import { createBlobURL } from '@wordpress/blob';
import { store as noticesStore } from '@wordpress/notices';
import {
link as linkIcon,
customLink,
image as imageIcon,
linkOff,
} from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -57,11 +66,23 @@ import GapStyles from './gap-styles';

const MAX_COLUMNS = 8;
const linkOptions = [
{ value: LINK_DESTINATION_ATTACHMENT, label: __( 'Attachment Page' ) },
{ value: LINK_DESTINATION_MEDIA, label: __( 'Media File' ) },
{
value: LINK_DESTINATION_NONE,
icon: customLink,
label: __( 'Link images to attachment pages' ),
value: LINK_DESTINATION_ATTACHMENT,
noticeText: __( 'Attachment Pages' ),
},
{
icon: imageIcon,
label: __( 'Link images to media files' ),
value: LINK_DESTINATION_MEDIA,
noticeText: __( 'Media Files' ),
},
{
icon: linkOff,
label: _x( 'None', 'Media item link option' ),
value: LINK_DESTINATION_NONE,
noticeText: __( 'None' ),
},
];
const ALLOWED_MEDIA_TYPES = [ 'image' ];
Expand Down Expand Up @@ -359,7 +380,7 @@ function GalleryEdit( props ) {
sprintf(
/* translators: %s: image size settings */
__( 'All gallery image links updated to: %s' ),
linkToText.label
linkToText.noticeText
),
{
id: 'gallery-attributes-linkTo',
Expand Down Expand Up @@ -552,15 +573,17 @@ function GalleryEdit( props ) {
size="__unstable-large"
/>
) }
<SelectControl
__nextHasNoMarginBottom
label={ __( 'Link to' ) }
value={ linkTo }
onChange={ setLinkTo }
options={ linkOptions }
hideCancelButton
size="__unstable-large"
/>
{ Platform.isNative ? (
<SelectControl
__nextHasNoMarginBottom
label={ __( 'Link' ) }
value={ linkTo }
onChange={ setLinkTo }
options={ linkOptions }
hideCancelButton
size="__unstable-large"
/>
) : null }
<ToggleControl
__nextHasNoMarginBottom
label={ __( 'Crop images to fit' ) }
Expand Down Expand Up @@ -594,6 +617,45 @@ function GalleryEdit( props ) {
) }
</PanelBody>
</InspectorControls>
{ Platform.isWeb ? (
<BlockControls group="block">
<ToolbarDropdownMenu
icon={ linkIcon }
label={ __( 'Link' ) }
>
{ ( { onClose } ) => (
<MenuGroup>
{ linkOptions.map( ( linkItem ) => {
const isOptionSelected =
linkTo === linkItem.value;
return (
<MenuItem
key={ linkItem.value }
isSelected={ isOptionSelected }
className={ clsx(
'components-dropdown-menu__menu-item',
{
'is-active':
isOptionSelected,
}
) }
iconPosition="left"
icon={ linkItem.icon }
onClick={ () => {
setLinkTo( linkItem.value );
onClose();
} }
role="menuitemradio"
>
{ linkItem.label }
</MenuItem>
);
} ) }
</MenuGroup>
) }
</ToolbarDropdownMenu>
</BlockControls>
) : null }
{ Platform.isWeb && (
<>
{ ! multiGallerySelection && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ exports[`Gallery block inserts block 1`] = `
<!-- /wp:gallery -->"
`;

exports[`Gallery block overrides "Link to" setting of gallery items 1`] = `
exports[`Gallery block overrides "Link" setting of gallery items 1`] = `
"<!-- wp:gallery {"linkTo":"media"} -->
<figure class="wp-block-gallery has-nested-images columns-default is-cropped"><!-- wp:image {"id":1,"linkDestination":"media"} -->
<figure class="wp-block-image"><img src="file:///local-image-1.jpeg" alt="" class="wp-image-1"/></figure>
Expand Down
10 changes: 5 additions & 5 deletions packages/block-library/src/gallery/test/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ describe( 'Gallery block', () => {
expect( getEditorHtml() ).toMatchSnapshot();
} );

// Test case related to TC012 - Settings - Link to
// Test case related to TC012 - Settings - Link
// Reference: https://github.com/wordpress-mobile/test-cases/blob/trunk/test-cases/gutenberg/gallery.md#tc012
it( 'overrides "Link to" setting of gallery items', async () => {
it( 'overrides "Link" setting of gallery items', async () => {
// Initialize with a gallery that contains two items, the latter includes "linkDestination" attribute
const screen = await initializeWithGalleryBlock( {
html: `<!-- wp:gallery {"linkTo":"none"} -->
Expand All @@ -612,10 +612,10 @@ describe( 'Gallery block', () => {
} );
const { getByText } = screen;

// Set "Link to" setting via Gallery block settings
// Set "Link" setting via Gallery block settings
await openBlockSettings( screen );
fireEvent.press( getByText( 'Link to' ) );
fireEvent.press( getByText( 'Media File' ) );
fireEvent.press( getByText( 'Link' ) );
fireEvent.press( getByText( 'Link images to media files' ) );

expect( getEditorHtml() ).toMatchSnapshot();
} );
Expand Down
Loading