From feb7123abdef9ca87fcbbeddf988b541b47f8e16 Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 2 Jan 2025 17:06:29 +1100 Subject: [PATCH 1/5] This is just a hack test to find a way to reset styles from a logged-in state on the frontend. --- .../features/wpcom-global-styles/index.php | 10 +++---- .../wpcom-global-styles-view.js | 30 +++++++++++++++++-- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php index cd1bc2fd6ece8..e7862e7176b3c 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php @@ -452,9 +452,11 @@ function wpcom_display_global_styles_launch_bar( $bar_controls ) { if ( ! wpcom_should_limit_global_styles() || ! wpcom_global_styles_in_use() ) { return $bar_controls; } + $blog_id = get_current_blog_id(); + $global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); if ( method_exists( '\WPCOM_Masterbar', 'get_calypso_site_slug' ) ) { - $site_slug = WPCOM_Masterbar::get_calypso_site_slug( get_current_blog_id() ); + $site_slug = WPCOM_Masterbar::get_calypso_site_slug( $blog_id ); } else { $home_url = home_url( '/' ); $site_slug = wp_parse_url( $home_url, PHP_URL_HOST ); @@ -540,12 +542,10 @@ class="launch-bar-global-styles-upgrade" class="launch-bar-global-styles-reset" href="https://wordpress.com/support/using-styles/#reset-all-styles" target="_blank" + data-blog-id="" + data-global-styles-id="" > - - - - diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js index 00620574d9ce3..4a74bf9e7eb43 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js @@ -1,8 +1,26 @@ /* global launchBarUserData */ +import wpcomRequest from 'wpcom-proxy-request'; import { wpcomTrackEvent } from '../../common/tracks'; - import './wpcom-global-styles-view.scss'; +const restGlobalStyles = async ( globalStylesId, siteIdOrSlug ) => { + if ( ! globalStylesId || ! siteIdOrSlug ) { + return false; + } + + // TODO find a way to PUT from the frontend preview. + return await wpcomRequest( { + path: `/sites/${ encodeURIComponent( siteIdOrSlug ) }/global-styles/${ globalStylesId }`, + apiNamespace: 'wp/v2', + method: 'POST', + body: { + id: globalStylesId, + settings: {}, + styles: {}, + }, + } ); +}; + /** * Records a Tracks click event. * @param {string} button - Identifier of the button that has been clicked. @@ -75,9 +93,15 @@ document.addEventListener( 'DOMContentLoaded', () => { window.location = previewButton.href; } ); - resetButton?.addEventListener( 'click', event => { + resetButton?.addEventListener( 'click', async event => { event.preventDefault(); recordEvent( 'wpcom_global_styles_gating_notice_reset_support' ); - window.open( resetButton.href, '_blank' ).focus(); + const globalStylesId = resetButton.dataset.globalStylesId; + const siteId = resetButton.dataset.blogId; + const result = await restGlobalStyles( globalStylesId, siteId ); + if ( ! result ) { + window.open( resetButton.href, '_blank' ).focus(); + } + // TODO SOMETHING console.log( { result, globalStylesId, siteId } ); } ); } ); From 92feacec2715ad80a2c468b8012f0adfb8c40ed9 Mon Sep 17 00:00:00 2001 From: ramon Date: Thu, 2 Jan 2025 17:12:46 +1100 Subject: [PATCH 2/5] changelog --- .../jetpack-mu-wpcom/changelog/add-allow-reset-global-styles | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/packages/jetpack-mu-wpcom/changelog/add-allow-reset-global-styles diff --git a/projects/packages/jetpack-mu-wpcom/changelog/add-allow-reset-global-styles b/projects/packages/jetpack-mu-wpcom/changelog/add-allow-reset-global-styles new file mode 100644 index 0000000000000..90ee6457fdb37 --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/add-allow-reset-global-styles @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Adds reset global styles functionality to the wpcom global styles view. From 2a310fcefa0e94957f70b5cf111047c10820fb94 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 3 Jan 2025 17:28:39 +1100 Subject: [PATCH 3/5] disable link and refresh --- .../features/wpcom-global-styles/index.php | 6 ++++++ .../wpcom-global-styles-view.js | 12 ++++++++--- .../wpcom-global-styles-view.scss | 20 +++++++++++++++---- .../docker/jetpack-docker-config-default.yml | 1 + 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php index e7862e7176b3c..89e8b612a93de 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php @@ -546,6 +546,12 @@ class="launch-bar-global-styles-reset" data-global-styles-id="" > + + diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js index 4a74bf9e7eb43..aa8eb5161658d 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.js @@ -98,10 +98,16 @@ document.addEventListener( 'DOMContentLoaded', () => { recordEvent( 'wpcom_global_styles_gating_notice_reset_support' ); const globalStylesId = resetButton.dataset.globalStylesId; const siteId = resetButton.dataset.blogId; - const result = await restGlobalStyles( globalStylesId, siteId ); - if ( ! result ) { + if ( globalStylesId && siteId ) { + resetButton?.classList.add( 'is-resetting' ); + const result = await restGlobalStyles( globalStylesId, siteId ); + if ( result ) { + window.location.reload(); + } else { + resetButton?.classList.remove( 'is-resetting' ); + } + } else { window.open( resetButton.href, '_blank' ).focus(); } - // TODO SOMETHING console.log( { result, globalStylesId, siteId } ); } ); } ); diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.scss b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.scss index aa1482b44160a..e6cb33eb26197 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.scss +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/wpcom-global-styles-view.scss @@ -59,10 +59,6 @@ color: inherit; font-weight: normal !important; - svg:first-child { - margin-right: 4px; - } - svg:last-child { margin-left: 4px; position: relative; @@ -73,6 +69,22 @@ background: transparent; color: #676767; } + + &.is-resetting { + opacity: 0.5; + pointer-events: none; + cursor: default; + .icon-block { + display: none; + } + .icon-scheduled { + display: inline; + } + } + + .icon-scheduled { + display: none; + } } } diff --git a/tools/docker/jetpack-docker-config-default.yml b/tools/docker/jetpack-docker-config-default.yml index 8498d44384cbd..a6b38125f435c 100644 --- a/tools/docker/jetpack-docker-config-default.yml +++ b/tools/docker/jetpack-docker-config-default.yml @@ -7,6 +7,7 @@ default: tools/docker/wordpress: /var/www/html .: /usr/local/src/jetpack-monorepo tools/docker/mu-plugins: /var/www/html/wp-content/mu-plugins + /Users/ramon/projects/gutenberg: /var/www/html/wp-content/plugins/gutenberg # Extra configuration (none by default). Anything set under this key will be written out as # an extra Docker compose configuration file. From 58576c3d27a1441b3521d514470c7749c2d56749 Mon Sep 17 00:00:00 2001 From: Ramon Date: Fri, 3 Jan 2025 17:35:25 +1100 Subject: [PATCH 4/5] Update jetpack-docker-config-default.yml --- tools/docker/jetpack-docker-config-default.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/docker/jetpack-docker-config-default.yml b/tools/docker/jetpack-docker-config-default.yml index a6b38125f435c..8498d44384cbd 100644 --- a/tools/docker/jetpack-docker-config-default.yml +++ b/tools/docker/jetpack-docker-config-default.yml @@ -7,7 +7,6 @@ default: tools/docker/wordpress: /var/www/html .: /usr/local/src/jetpack-monorepo tools/docker/mu-plugins: /var/www/html/wp-content/mu-plugins - /Users/ramon/projects/gutenberg: /var/www/html/wp-content/plugins/gutenberg # Extra configuration (none by default). Anything set under this key will be written out as # an extra Docker compose configuration file. From 98fe82c7e0bd34895dbc64bcc86889d95773e056 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 3 Jan 2025 17:48:44 +1100 Subject: [PATCH 5/5] coerce ids for esc_attr --- .../src/features/wpcom-global-styles/index.php | 4 ++-- .../wpcom-global-styles/wpcom-global-styles-view.scss | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php index 89e8b612a93de..ee4cff7653ebd 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/wpcom-global-styles/index.php @@ -542,8 +542,8 @@ class="launch-bar-global-styles-upgrade" class="launch-bar-global-styles-reset" href="https://wordpress.com/support/using-styles/#reset-all-styles" target="_blank" - data-blog-id="" - data-global-styles-id="" + data-blog-id="" + data-global-styles-id="" >