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

Enhanced twg settings validation #5573

Merged
merged 6 commits into from
Jul 21, 2022

Conversation

kuasha420
Copy link
Contributor

@kuasha420 kuasha420 commented Jul 19, 2022

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 4.7 and PHP 5.6.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@kuasha420 kuasha420 marked this pull request as ready for review July 19, 2022 20:03
@github-actions
Copy link

github-actions bot commented Jul 19, 2022

Size Change: +881 kB (+65%) 🆘

Total Size: 2.25 MB

Filename Size Change
./dist/assets/css/googlesitekit-admin-css-********************.min.css 47.3 kB +390 B (+1%)
./dist/assets/js/googlesitekit-adminbar-********************.js 37.4 kB +4 B (0%)
./dist/assets/js/googlesitekit-base-********************.js 1.13 kB -1 B (0%)
./dist/assets/js/googlesitekit-dashboard-details-********************.js 55.7 kB -1 B (0%)
./dist/assets/js/googlesitekit-dashboard-********************.js 62.5 kB -6 B (0%)
./dist/assets/js/googlesitekit-dashboard-splash-********************.js 70.7 kB +2 B (0%)
./dist/assets/js/googlesitekit-data-********************.js 2.09 kB +1 B (0%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 8.82 kB -1 B (0%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB -1 B (0%)
./dist/assets/js/googlesitekit-datastore-site-********************.js 14.7 kB +6 B (0%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 8.92 kB +1 B (0%)
./dist/assets/js/googlesitekit-datastore-user-********************.js 30 kB +2 B (0%)
./dist/assets/js/googlesitekit-idea-hub-post-list-********************.js 25.6 kB +4 B (0%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 69.1 kB -5 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 19.1 kB +1 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-********************.js 69.1 kB -13 B (0%)
./dist/assets/js/googlesitekit-modules-********************.js 19.4 kB +15 B (0%)
./dist/assets/js/googlesitekit-modules-idea-hub-********************.js 27.9 kB -7 B (0%)
./dist/assets/js/googlesitekit-modules-optimize-********************.js 19.4 kB +5 B (0%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 18.4 kB +2 B (0%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 39.3 kB -21 B (0%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 30.5 kB -52 B (0%)
./dist/assets/js/googlesitekit-modules-thank-with-google-********************.js 899 kB +881 kB (+4881%) 🆘
./dist/assets/js/googlesitekit-settings-********************.js 50.8 kB +19 B (0%)
./dist/assets/js/googlesitekit-user-input-********************.js 44.7 kB -90 B (0%)
./dist/assets/js/googlesitekit-vendor-********************.js 323 kB -28 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 19.2 kB +5 B (0%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 60.8 kB -2 B (0%)
./dist/assets/js/runtime-********************.js 1.28 kB +1 B (0%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11 kB
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 5.88 kB
./dist/assets/js/31-********************.js 2.8 kB
./dist/assets/js/32-********************.js 2.28 kB
./dist/assets/js/33-********************.js 3.72 kB
./dist/assets/js/34-********************.js 51.9 kB
./dist/assets/js/35-********************.js 3.12 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 769 B
./dist/assets/js/googlesitekit-activation-********************.js 27.5 kB
./dist/assets/js/googlesitekit-api-********************.js 9.19 kB
./dist/assets/js/googlesitekit-i18n-********************.js 3.92 kB
./dist/assets/js/googlesitekit-idea-hub-notice-********************.js 45.1 kB
./dist/assets/js/googlesitekit-polyfills-********************.js 380 B

compressed-size-action

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Looks good, just one question and also a thought on the post types we allow to be saved.

Let me know what you think, after that I think we're good to merge 😄

Comment on lines 166 to 168
if ( ! is_array( $button_post_types ) ) {
return array( 'post' );
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this here? I guess it's for the default value/settings? I'd think a safer default is to show this on no post types by default 🤔

Suggested change
if ( ! is_array( $button_post_types ) ) {
return array( 'post' );
}
if ( ! is_array( $button_post_types ) ) {
return array();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM. 👍

if ( ! is_array( $button_post_types ) ) {
return array( 'post' );
}
return array_intersect( $button_post_types, get_post_types( array( 'public' => true ) ) );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Additionally, I wonder if this matches the UI we show… in the UI we only show posts that support viewable (see: #5456). I wonder if this would allow a user to submit a post type successfully that wouldn't appear in the UI.

Not a big deal as they'd need to intentionally do so, but it would be nice if the only posts we allowed to save would be ones that would appear with the 'viewable' value in supports. 🤔

I know this is what was in the ACs/IB, but I think it's maybe a bit inaccurate? Would there be an easy way to get all post types that match what wp.data.select('core').getPostTypes().filter((postType) => postType.viewable) returns? If so let's do that 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, the API for getPostTypes() uses is_post_type_viewable for each post to determine the viewable status. For a post to be viewable:

  • if it's a builtin post type, the public must be true.
  • If it's not a builtin post type, the publicly_queryable must be true.

Which definitely makes your point valid. I'll see what's the best way to achieve that here.

Off Topic: speaking of getPostTypes be aware that it only returns 10 post types if the site has more. See here. The workaround is to supply { per_page: -1 } to the selector which will return 100. If there's 101 post type this workaround will not work 😁

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, sadly I think that's our best option for now until someone runs into an issue 😅

We could add pagination if needed, but for now 101 is probably enough.

@@ -0,0 +1,114 @@
<?php
/**
* Class Google\Site_Kit\Tests\Modules\Thank_With_Google\Settings
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Class Google\Site_Kit\Tests\Modules\Thank_With_Google\Settings
* Class Google\Site_Kit\Tests\Modules\Thank_With_Google\SettingsTest

/**
* Gets the setting value.
*
* @since m.e.x.t
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please be sure to use the correct placeholder as search/replace will miss it otherwise.

Suggested change
* @since m.e.x.t
* @since n.e.x.t

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh my goodness, they looks same to me on monospaced font. Sorry!

Copy link
Collaborator

Choose a reason for hiding this comment

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

I missed it too, waiting for someone to make a m.e.x.t release in ZenHub just to really mess with us 😉

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Code looks great, thanks! I'm just hunting down the huge filesize increase for Thanks with Google before merging.

@tofumatt
Copy link
Collaborator

Update: looks like a bug, because I ran it locally and got this:
CleanShot 2022-07-21 at 19 26 46

:shipit:

@tofumatt tofumatt merged commit 75c47fc into develop Jul 21, 2022
@tofumatt tofumatt deleted the enhance/5461-enhanced-twg-settings-validation branch July 21, 2022 18:27
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.

3 participants