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

Overwrite Missing block UI Text #2610

Merged
merged 29 commits into from
Sep 28, 2020
Merged

Overwrite Missing block UI Text #2610

merged 29 commits into from
Sep 28, 2020

Conversation

etoledom
Copy link
Contributor

@etoledom etoledom commented Sep 11, 2020

WPiOS PR: wordpress-mobile/WordPress-iOS#14880
WPAndroid PR: wordpress-mobile/WordPress-Android#13011
gutenberg PR: WordPress/gutenberg#25238

This PR implements the changes from WordPress/gutenberg#25238 and overwrites the default Missing block alert text with text that references WordPress.com and Jetpack.

This also allows us to change these texts dynamically depending on the UBE-related capabilities sent from the native apps, after calling updateCapabilities().

To test:
Please check wordpress-mobile/WordPress-iOS#14880

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered if this change warrants user-facing release notes more info and have added them to RELEASE-NOTES.txt if necessary.

@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Sep 11, 2020

Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job!

Base automatically changed from feature/unsupported-block-editor-jetpack-sso-enabled to develop September 11, 2020 23:55
@marecar3
Copy link
Contributor

Hey @etoledom 👋
I have marked this PR as ready for review as it seems that we are ready? Thanks.

cc @Tug @guarani @mchowning

@marecar3 marecar3 marked this pull request as ready for review September 24, 2020 22:48
Comment on lines +42 to +44
const unsupportedBlocksButton = shouldOverwriteButtonTitle
? __( 'Open Jetpack Security settings' )
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: It seems like instead of using the extra shouldOverwriteButtonTitle variable, we could use the if-else statement above to set unsupportedBlocksButton.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would make us declare unsupportedBlocksButton as let right?
I thought shouldOverwriteButtonTitle name would also give some context of the reasoning for the undefined.

Would you say something like this?

let unsupportedBlocksButtonTitle = undefined;
if ( unsupportedBlockEditor.supported === false && unsupportedBlockEditor.switchable ) {
    unsupportedBlocksButtonTitle = __( 'Open Jetpack Security settings' );
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think I had something like that in mind.

Comment on lines 10 to 15
const unsupportedBlockEditor = {
supported:
getSettings( 'capabilities' ).unsupportedBlockEditor === true,
switchable:
getSettings( 'capabilities' ).unsupportedBlockEditorSwitch === true,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: An alternative here could be to use:

	const { 
		unsupportedBlockEditor = false,
		unsupportedBlockEditorSwitch = false
	} = getSettings( 'capabilities' ).unsupportedBlockEditor;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unsupportedBlockEditor.supported and unsupportedBlockEditor.switchable I think gives a nice context on their usage. Like:

if (
 	unsupportedBlockEditor.supported === false &&
 	unsupportedBlockEditor.switchable
 )

vs

if (
 	unsupportedBlockEditor === false &&
 	unsupportedBlockEditorSwitch
)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(By the way, I think this whole file is a mess anyway, and not much extendible if we add more strings in the future. We will probably split it in the future)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, those attributes (unsupportedBlockEditor and unsupportedBlockEditorSwitch) would be descriptive enough on their own so that they can be deconstructed and used as-is without needing to be renamed. But I know it's hard here to find a good name, so I'm happy to leave it as-is if you want to.

Copy link
Contributor

@guarani guarani left a comment

Choose a reason for hiding this comment

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

The changes here look good. I added some comments on things that I had suggestions about.

const { getSettings } = select( 'core/block-editor' );
const unsupportedBlockEditor = {
supported:
getSettings( 'capabilities' ).unsupportedBlockEditor === true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just asking out of curiosity. We have a lot of explicit bool checks in this file (i.e., someValue === true and someValue === false). Are we doing that to guard against a cases where someValue could be some other truth-y or false-y values, or is it a style preference to do the explicit bool check instead of doing something like someValue (or even !!someValue if we needed a bool) and !someValue, or maybe there's another reason?

Just asking because I tend to use the !s when I can (I find them more readable), and I'm curious if there are considerations I may not be considering when I do that. I'm not asking because I think we need to change it here. 🙂

Copy link
Contributor

@mchowning mchowning left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@Tug Tug left a comment

Choose a reason for hiding this comment

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

Couldn't we have achieved that feature by just adding a hook in missing/edit.native.js:

const missingBlockDetail = applyFilters( 'native.missing_block_detail', __( 'We are working hard to add more blocks with each release.' ) );

...

<Text style={ [ infoTextStyle, infoDescriptionStyle ] }>
	{ missingBlockDetail }
</Text>

Then in gb-mobile:

addFilter( 'native.missing_block_detail', ( defaultValue ) => {
	// uiStrings() logic goes here
} );

?

Same for the action button.


export const uiStrings = () => {
const { getSettings } = select( 'core/block-editor' );
const unsupportedBlockEditor = {
Copy link
Contributor

@Tug Tug Sep 25, 2020

Choose a reason for hiding this comment

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

Nitpick: I think just using 2 variables instead of grouping them in an object is just simpler and easier to understand, especially since you're assigning an unsupportedBlockEditor to a supported property

};
};

addStrings( uiStrings );
Copy link
Contributor

@Tug Tug Sep 25, 2020

Choose a reason for hiding this comment

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

Nitpick: I would expect that, given its name, addStrings would accept a list of strings as parameter. The fact that it accepts a function returning a mapping of (string id, string value) makes it a bit hard to grasp imo.

@etoledom
Copy link
Contributor Author

Couldn't we have achieved that feature by just adding a hook

@Tug - Nice tip! Indeed looks a lot simpler.

The only thing we need from it is that it has to refresh and return the correct String after updating the capabilities.
I will test this out and probably make the chance on an upcoming PR if that's OK with you 👍

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.

5 participants