-
Notifications
You must be signed in to change notification settings - Fork 865
Launch Site Flow Standardization: Add WP Admin masterbar variations #47705
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
Open
zaguiini
wants to merge
12
commits into
trunk
Choose a base branch
from
datsci-1168-standardize-site-launch-wp-admin-masterbar-entry-point
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.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b1b49b4
Launch Site Flow Standardization: Add WP Admin masterbar variations
zaguiini c280d19
Change user agent to assign the experiment in production
zaguiini 3a7d5e0
Address feedback
zaguiini 6f2b32b
Launch Site Flow Standardization: Implement launch site mutation in W…
bogiii 0bda094
Fix fatal error caused by duplicate WPCOM_REST_API_V2_Endpoint_Launch…
bogiii 3f5c392
Fix fatal class redeclaration by renaming endpoint class to Jetpack_L…
bogiii 0b1dc50
Launch Site Flow: Feed CelebrateLaunchModal with data from launch-but…
bogiii 448d384
Fix launch site on Atomic: use wpcom_json_api_request_as_user with wp…
bogiii 7c871c7
Extract launch site API call into shared useLaunchSiteMutation hook
bogiii f86de5b
Move CelebrateLaunchModal to common/ for shared use
bogiii 45bc4e0
Changelog
bogiii ae53c8e
Launch site: stay on page after modal close
bogiii 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/packages/explat/changelog/standardize-site-launch-wp-admin-masterbar-entry-point
This file contains hidden or 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: patch | ||
| Type: changed | ||
|
|
||
| Launch Site: implement direct site launch from the WP Admin masterbar button via an ExPlat experiment, with a shared mutation hook and celebration modal for use across launch entry points. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
4 changes: 4 additions & 0 deletions
4
...ackages/jetpack-mu-wpcom/changelog/standardize-site-launch-wp-admin-masterbar-entry-point
This file contains hidden or 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: patch | ||
| Type: changed | ||
|
|
||
| Launch Site: implement direct site launch from the WP Admin masterbar button via an ExPlat experiment, with a shared mutation hook and celebration modal for use across launch entry points. |
This file contains hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,2 +1,3 @@ | ||
| export { default as useCanvasMode } from './use-canvas-mode'; | ||
| export { default as useLaunchSiteMutation } from './use-launch-site-mutation'; | ||
| export { default as useLocation } from './use-location'; |
27 changes: 27 additions & 0 deletions
27
projects/packages/jetpack-mu-wpcom/src/common/hooks/use-launch-site-mutation.ts
This file contains hidden or 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,27 @@ | ||
| import { getSiteData } from '@automattic/jetpack-script-data'; | ||
| import { useMutation } from '@tanstack/react-query'; | ||
| import apiFetch from '@wordpress/api-fetch'; | ||
| import wpcomRequest, { canAccessWpcomApis } from 'wpcom-proxy-request'; | ||
|
|
||
| const useLaunchSiteMutation = ( onSuccess: () => void ) => { | ||
| const siteData = getSiteData(); | ||
|
|
||
| return useMutation( { | ||
| mutationFn: () => { | ||
| if ( canAccessWpcomApis() ) { | ||
| return wpcomRequest( { | ||
| path: `/sites/${ siteData.wpcom.blog_id }/launch`, | ||
| apiVersion: '1.1', | ||
| method: 'POST', | ||
| } ); | ||
| } | ||
| return apiFetch( { | ||
| path: '/wpcom/v2/launch-site', | ||
| method: 'POST', | ||
| } ); | ||
| }, | ||
| onSuccess, | ||
| } ); | ||
| }; | ||
|
|
||
| export default useLaunchSiteMutation; |
31 changes: 25 additions & 6 deletions
31
projects/packages/jetpack-mu-wpcom/src/features/launch-button/index.js
This file contains hidden or 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,11 +1,30 @@ | ||
| import { wpcomTrackEvent } from '../../common/tracks'; | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
| import { createRoot } from 'react-dom/client'; | ||
| import { LaunchButton } from './launch-button'; | ||
|
|
||
| document.addEventListener( 'DOMContentLoaded', () => { | ||
| const queryClient = new QueryClient(); | ||
|
|
||
| /** | ||
| * Renders the launch button. | ||
| * @return {Promise<void>} | ||
| */ | ||
| async function renderLaunchButton() { | ||
| const launchButton = document.querySelector( '#wpadminbar .launch-site' ); | ||
| if ( ! launchButton ) { | ||
| return; | ||
| } | ||
| launchButton.addEventListener( 'click', () => { | ||
| wpcomTrackEvent( 'wpcom_adminbar_launch_site' ); | ||
| } ); | ||
| } ); | ||
|
|
||
| const root = createRoot( launchButton ); | ||
| root.render( | ||
| <QueryClientProvider client={ queryClient }> | ||
| <LaunchButton | ||
| onCelebrationModalClose={ () => { | ||
| root.unmount(); | ||
| launchButton.remove(); | ||
| } } | ||
| /> | ||
| </QueryClientProvider> | ||
| ); | ||
| } | ||
|
|
||
| document.addEventListener( 'DOMContentLoaded', renderLaunchButton, { once: true } ); |
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
projects/packages/jetpack-mu-wpcom/src/features/launch-button/launch-button.js
This file contains hidden or 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,80 @@ | ||
| import { useExperimentWithAuth } from '@automattic/jetpack-explat'; | ||
| import { getSiteData } from '@automattic/jetpack-script-data'; | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { addQueryArgs } from '@wordpress/url'; | ||
| import { useState } from 'react'; | ||
| import CelebrateLaunchModal from '../../common/celebrate-launch-modal'; | ||
| import { useLaunchSiteMutation } from '../../common/hooks'; | ||
| import { wpcomTrackEvent } from '../../common/tracks'; | ||
|
|
||
| const icon = ( | ||
| <svg viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
| <path | ||
| fillRule="evenodd" | ||
| clipRule="evenodd" | ||
| d="M10.6242 9.74354L7.62419 12.1261V13.2995C7.62419 13.4418 7.77653 13.5322 7.90147 13.4641L10.5265 12.0322C10.5867 11.9994 10.6242 11.9363 10.6242 11.8676V9.74354ZM6.49919 12.0875L3.91203 9.50037H2.7001C1.70383 9.50037 1.07079 8.43399 1.54786 7.55937L2.97968 4.93437C3.20967 4.51272 3.65161 4.25036 4.13191 4.25036H7.17569C9.1325 2.16798 11.3176 0.754637 14.1427 0.531305C14.9004 0.471402 15.5282 1.09911 15.4682 1.85687C15.2449 4.68199 13.8316 6.86706 11.7492 8.82386V11.8676C11.7492 12.3479 11.4868 12.7899 11.0652 13.0199L8.44018 14.4517C7.56557 14.9288 6.49919 14.2957 6.49919 13.2995V12.0875ZM6.25602 5.37536H4.13191C4.0633 5.37536 4.00017 5.41284 3.96731 5.47308L2.53549 8.09808C2.46734 8.22303 2.55777 8.37536 2.7001 8.37536H3.87344L6.25602 5.37536Z" | ||
| /> | ||
| <path d="M0.498047 13.3962C0.498047 12.2341 1.44011 11.2921 2.60221 11.2921C3.76431 11.2921 4.70638 12.2341 4.70638 13.3962C4.70638 14.5583 3.76431 15.5004 2.60221 15.5004H1.06055C0.749887 15.5004 0.498047 15.2486 0.498047 14.9379V13.3962Z" /> | ||
| </svg> | ||
| ); | ||
|
|
||
| const Content = () => ( | ||
| <> | ||
| <span className="ab-icon">{ icon }</span> | ||
| <span className="ab-label">{ __( 'Launch site', 'jetpack-mu-wpcom' ) }</span> | ||
| </> | ||
| ); | ||
|
|
||
| const launchButtonData = typeof window === 'object' ? window.JETPACK_LAUNCH_BUTTON_DATA : {}; | ||
|
|
||
| /** | ||
| * The LaunchButton component. | ||
| * @param {object} props - Props | ||
| * @param {Function} props.onCelebrationModalClose - Callback on celebration modal close. | ||
| * @return {React.ReactNode} The LaunchButton component. | ||
| */ | ||
| export function LaunchButton( { onCelebrationModalClose } ) { | ||
| const [ , data ] = useExperimentWithAuth( 'calypso_standardized_site_launch_gating' ); | ||
| const [ showCelebrateLaunchModal, setShowCelebrateLaunchModal ] = useState( false ); | ||
|
|
||
| const siteData = getSiteData(); | ||
|
|
||
| const { mutate: launchSite } = useLaunchSiteMutation( () => setShowCelebrateLaunchModal( true ) ); | ||
|
|
||
| // Default experience. Markup should match what's coming from the back-end. | ||
| if ( ! data || data.variationName !== 'ungated_site_launch' ) { | ||
| // Maybe this data can come from the server. | ||
| const launchUrl = addQueryArgs( 'https://wordpress.com/start/launch-site', { | ||
| siteSlug: siteData.suffix, | ||
| ref: 'wp-admin', | ||
| } ); | ||
|
|
||
| return ( | ||
| <a | ||
| className="ab-item" | ||
| role="menuitem" | ||
| href={ launchUrl } | ||
| onClick={ () => wpcomTrackEvent( 'wpcom_adminbar_launch_site' ) } | ||
| > | ||
| <Content /> | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| const handleLaunchClick = e => { | ||
| e.preventDefault(); | ||
| wpcomTrackEvent( 'wpcom_adminbar_launch_site' ); | ||
| launchSite(); | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <a className="ab-item" role="menuitem" href="#" onClick={ handleLaunchClick }> | ||
| <Content /> | ||
| </a> | ||
| { showCelebrateLaunchModal && ( | ||
| <CelebrateLaunchModal { ...launchButtonData } onRequestClose={ onCelebrationModalClose } /> | ||
| ) } | ||
| </> | ||
| ); | ||
| } |
Oops, something went wrong.
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.
We were rendering the masterbar while loading the preview and that was assigning the user unintentionally. This snippet prevents loading the scripts twice.