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

Handle the site_icon_maskable setting within a full-site-editing context #919

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

carstingaxion
Copy link

@carstingaxion carstingaxion commented Jan 31, 2023

Introduce additional UI for the core/site-logo-block to toggle the existing setting and give a preview of the Image choosen, with the setting applied.

This should help deprecating the customizer at all, without loosing functionaliy and flexibility for the user.

This fixes #915

@google-cla
Copy link

google-cla bot commented Jan 31, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@carstingaxion
Copy link
Author

Thank you @westonruter for all your feedback.
And sorry for beeing a little late.

@carstingaxion carstingaxion marked this pull request as ready for review February 26, 2023 12:11
@carstingaxion
Copy link
Author

What do you think about the current state @westonruter ?

Copy link
Collaborator

@westonruter westonruter left a comment

Choose a reason for hiding this comment

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

Off to a good start!

Comment on lines +725 to +730

// Stop, if needed file was not built successfully.
$script_asset_path = "$path/site-icon-maskable.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a redundant check with _pwa_print_build_needed_notice, right? So is it needed?

Suggested change
// Stop, if needed file was not built successfully.
$script_asset_path = "$path/site-icon-maskable.asset.php";
if ( ! file_exists( $script_asset_path ) ) {
return;
}

Copy link
Author

@carstingaxion carstingaxion Mar 2, 2023

Choose a reason for hiding this comment

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

You are right, that is a redundant check, but leaving it out will result in fatal error with the following require statement on the next line. Or am I wrong?

Additionally, because this is called inside the block-editor, where the normal admin_notices will not be visible, this should prevent errors while trying to enque a non-existent file. To help the user mentioning, that the plugin was not built properly, we could introduce one of the newer createWarningNotice for the block-editor. But this should be new issue, I think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right, that is a redundant check, but leaving it out will result in fatal error with the following require statement on the next line. Or am I wrong?

If you see the change you made in pwa.php:

pwa-wp/pwa.php

Lines 100 to 106 in 81d2860

if ( ! file_exists( PWA_PLUGIN_DIR . '/wp-includes/js/workbox-v' . PWA_WORKBOX_VERSION ) ||
! file_exists( PWA_PLUGIN_DIR . '/wp-includes/js/workbox-v' . PWA_WORKBOX_VERSION . '/workbox-sw.js' ) ||
! file_exists( PWA_PLUGIN_DIR . '/wp-includes/js/dist/site-icon-maskable.asset.php' )
) {
add_action( 'admin_notices', '_pwa_print_build_needed_notice' );
return;
}

Note that in the bootstrap, it does a return to prevent the rest of the PWA functionality from being loaded. So if the file doesn't exist, then this conditional won't ever be reached.

wp-includes/class-wp-web-app-manifest.php Outdated Show resolved Hide resolved
'site_icon_maskable'
);

// mainly borrowed from ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

From what?

Copy link
Author

Choose a reason for hiding this comment

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

Suggested change
// mainly borrowed from ...
// mainly borrowed from the `SiteIcon` component

SiteIcon

Unfortunately there is no nice docs-page to reference to, propably because this component is part of the Edit Site components, which are described in its own README as

[...] but please keep in mind that it might never get fully documented.

wp-includes/class-wp-web-app-manifest.php Outdated Show resolved Hide resolved
<PanelBody>
<Flex align="start">
<FlexBlock>
<ToggleControl
Copy link
Collaborator

Choose a reason for hiding this comment

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

When I toggle this on the first tine I get a React warning:

Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://reactjs.org/link/controlled-components

Perhaps this is because it is missing a default false value?

Comment on lines +83 to +94
if (siteIconUrl) {
siteIcon = (
<img
alt={__('Site Icon')}
className="components-site-icon"
src={siteIconUrl}
width={64}
height={64}
style={siteIconStyle}
/>
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I tried selecting a non-square image as the Site Logo and this is resulting in an unexpected result for the maskable icon:

image

Three things aren't quite right here:

  1. The toggle for a maskable icon is showing even if I've not selected that I want to use the Site Logo as the Site Icon. I should only see the toggle if I'm using the Site Logo as the Site Icon.
  2. A Site Logo need not be square, but a Site Icon must be. Nevertheless, WP allows selection of a rectangular icon but then it crops it to be square. The same logic used for cropping to be square should also be replicated here in the preview. (Aside: I'm surprised that core doesn't have such a Site Icon preview when the "Use as site icon" toggle is checked, as there should be a way to see whether the square crop will even work. This would be an improvement for core.)
  3. If I change the selected image for the Site Logo while the block controls are open, the preview for the maskable icon does not update to use the newly selected image. See below:

image

Copy link
Author

Choose a reason for hiding this comment

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

OMG. But you are totally right on all of your points.

I'll try to find some solutions.

const [siteIconMaskable, setSiteIconMaskable] = useEntityProp(
'root',
'site',
'site_icon_maskable'
Copy link
Collaborator

@westonruter westonruter Mar 1, 2023

Choose a reason for hiding this comment

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

This is unexpectedly showing up as the label in the pre-save dialog when it should have a label:

image

Copy link
Author

Choose a reason for hiding this comment

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

This is unfortunately a known bug in gutenberg, I'm going to ref. the issue here, when I'll find it again ;)

@westonruter
Copy link
Collaborator

Relatedly, I just filed WordPress/gutenberg#48608

@codecov-commenter
Copy link

Codecov Report

Patch coverage: 29.62% and project coverage change: +0.02 🎉

Comparison is base (c715742) 19.62% compared to head (81d2860) 19.64%.

Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #919      +/-   ##
=============================================
+ Coverage      19.62%   19.64%   +0.02%     
- Complexity       347      349       +2     
=============================================
  Files             57       57              
  Lines           2324     2347      +23     
=============================================
+ Hits             456      461       +5     
- Misses          1868     1886      +18     
Flag Coverage Δ
php 19.64% <29.62%> (+0.02%) ⬆️
unit 19.64% <29.62%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pwa.php 0.00% <0.00%> (ø)
wp-includes/class-wp-web-app-manifest.php 63.09% <34.78%> (-3.29%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace the need for the customizer when using a FSE theme
3 participants