-
Notifications
You must be signed in to change notification settings - Fork 801
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
Ensure all prompts to remove premium styles automatically work #40818
Draft
ramonjd
wants to merge
5
commits into
trunk
Choose a base branch
from
add/allow-reset-global-styles
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
feb7123
This is just a hack test to find a way to reset styles from a logged-…
ramonjd 92feace
changelog
ramonjd 2a310fc
disable link and refresh
ramonjd 58576c3
Update jetpack-docker-config-default.yml
ramonjd 98fe82c
coerce ids for esc_attr
ramonjd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/add-allow-reset-global-styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Adds reset global styles functionality to the wpcom global styles view. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignore this comment. I was in READ mode on sandbox. |
||
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,21 @@ 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; | ||
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(); | ||
} | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a first pass, but thinking of alternatives to exposing blog and global styles id to frontend.
Via a query e.g.,
?reset-global-styles=true
? Then the PHP could do all the work, and also double check that the user is logged in, has privileges etc.If it fails for whatever reason, then we could render the link to the help docs.