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

Assembler CTA: Fix selecting the CTA doesn't go to the editor on mobile #79591

Merged
merged 3 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Design Picker: Fix selecting Assembler CTA doesn't go to the editor o…
…n mobile
  • Loading branch information
arthur791004 committed Jul 19, 2023
commit 79f3ecc6d86e62396154bba84103e4c3e322a6e7
7 changes: 6 additions & 1 deletion client/components/themes-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ export const ThemesList = ( { tabFilter, ...props } ) => {

const selectedSite = useSelector( getSelectedSite );
const isLoggedIn = useSelector( isUserLoggedIn );
const siteEditorUrl = useSelector( ( state ) => getSiteEditorUrl( state, selectedSite?.ID ) );
const siteEditorUrl = useSelector( ( state ) =>
getSiteEditorUrl( state, selectedSite?.ID, {
canvas: 'edit',
assembler: '1',
} )
);

const isPatternAssemblerCTAEnabled =
! isLoggedIn || isEnabled( 'pattern-assembler/logged-in-showcase' );
Expand Down
4 changes: 2 additions & 2 deletions client/landing/stepper/declarative-flow/import-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ const importFlow: Flow = {
}

case 'designSetup': {
const _selectedDesign = providedDependencies?.selectedDesign as Design;
if ( isAssemblerDesign( _selectedDesign ) ) {
const { selectedDesign: _selectedDesign, shouldGoToAssembler } = providedDependencies;
if ( isAssemblerDesign( _selectedDesign as Design ) && shouldGoToAssembler ) {
return navigate( 'patternAssembler' );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Design, StyleVariation, isAssemblerDesign } from '@automattic/design-picker';
import {
Design,
StyleVariation,
isAssemblerDesign,
shouldGoToAssembler,
} from '@automattic/design-picker';
import { getVariationTitle, getVariationType } from '@automattic/global-styles';
import { resolveDeviceTypeByViewPort } from '@automattic/viewport';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
Expand Down Expand Up @@ -54,7 +59,7 @@ export function recordSelectedDesign( {

export function getDesignTypeProps( design?: Design ) {
return {
goes_to_assembler_step: isAssemblerDesign( design ),
goes_to_assembler_step: isAssemblerDesign( design ) && shouldGoToAssembler(),
assembler_source: getAssemblerSource( design ),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useCategorizationFromApi,
getDesignPreviewUrl,
isBlankCanvasDesign,
isAssemblerDesign,
} from '@automattic/design-picker';
import { useLocale } from '@automattic/i18n-utils';
import { StepContainer } from '@automattic/onboarding';
Expand Down Expand Up @@ -463,6 +464,7 @@ const UnifiedDesignPickerStep: Step = ( { navigation, flow, stepName } ) => {
handleSubmit( {
selectedDesign: _selectedDesign,
selectedSiteCategory: categorization.selection,
shouldGoToAssemblerStep,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
shouldGoToAssemblerStep,
shouldGoToAssembler: shouldGoToAssemblerStep,

Copy link
Contributor

@taipeicoder taipeicoder Jul 19, 2023

Choose a reason for hiding this comment

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

The dependency is shouldGoToAssembler instead of shouldGoToAssemblerStep 🤓 We can also rename the argument!

case 'designSetup': {
  const { selectedDesign: _selectedDesign, shouldGoToAssembler } = providedDependencies;
  if ( isAssemblerDesign( _selectedDesign as Design ) && shouldGoToAssembler ) {
    return navigate( 'patternAssembler' );
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops...

} );
} else {
pickDesign( design );
Expand All @@ -471,7 +473,7 @@ const UnifiedDesignPickerStep: Step = ( { navigation, flow, stepName } ) => {

function handleSubmit( providedDependencies?: ProvidedDependencies, optionalProps?: object ) {
const _selectedDesign = providedDependencies?.selectedDesign as Design;
if ( _selectedDesign?.design_type !== 'assembler' ) {
if ( ! isAssemblerDesign( _selectedDesign ) ) {
recordSelectedDesign( {
flow,
intent,
Expand Down
4 changes: 2 additions & 2 deletions client/landing/stepper/declarative-flow/site-setup-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ const siteSetupFlow: Flow = {
}

case 'designSetup': {
const _selectedDesign = providedDependencies?.selectedDesign as Design;
if ( isAssemblerDesign( _selectedDesign ) ) {
const { selectedDesign: _selectedDesign, shouldGoToAssembler } = providedDependencies;
if ( isAssemblerDesign( _selectedDesign as Design ) && shouldGoToAssembler ) {
return navigate( 'patternAssembler' );
}

Expand Down
15 changes: 10 additions & 5 deletions client/signup/config/flows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
DOT_ORG_THEME,
WOOCOMMERCE_THEME,
MARKETPLACE_THEME,
shouldGoToAssembler,
} from '@automattic/design-picker';
import { isSiteAssemblerFlow } from '@automattic/onboarding';
import { isWithinBreakpoint } from '@automattic/viewport';
import { get, includes, reject } from 'lodash';
import detectHistoryNavigation from 'calypso/lib/detect-history-navigation';
import { getQueryArgs } from 'calypso/lib/query-args';
Expand Down Expand Up @@ -117,9 +117,8 @@ function getThankYouNoSiteDestination() {

function getChecklistThemeDestination( { flowName, siteSlug, themeParameter } ) {
if ( isSiteAssemblerFlow( flowName ) && themeParameter === DEFAULT_ASSEMBLER_DESIGN.slug ) {
// Go to the site assembler flow if viewport width >= 960px as the layout doesn't support small
// screen for now.
if ( isWithinBreakpoint( '>=960px' ) ) {
// Check whether to go to the assembler. If not, go to the site editor directly
if ( shouldGoToAssembler() ) {
return addQueryArgs(
{
theme: themeParameter,
Expand All @@ -130,8 +129,14 @@ function getChecklistThemeDestination( { flowName, siteSlug, themeParameter } )
);
}

return `/site-editor/${ siteSlug }`;
const params = new URLSearchParams( {
canvas: 'edit',
assembler: '1',
} );

return `/site-editor/${ siteSlug }?${ params }`;
}

return `/home/${ siteSlug }`;
}

Expand Down
5 changes: 3 additions & 2 deletions client/state/selectors/get-site-editor-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { getSiteAdminUrl } from 'calypso/state/sites/selectors';
*
* @param {Object} state Global state tree
* @param {?number} siteId Site ID
* @param {?Object} queryArgs The query arguments append to the Url
* @returns {string} Url of site editor instance for calypso or wp-admin.
*/
export const getSiteEditorUrl = ( state, siteId ) => {
export const getSiteEditorUrl = ( state, siteId, queryArgs = {} ) => {
const siteAdminUrl = getSiteAdminUrl( state, siteId );
const queryArgs = {};

// Only add the origin if it's not wordpress.com.
if ( typeof window !== 'undefined' && window.location.origin !== 'https://wordpress.com' ) {
queryArgs.calypso_origin = window.location.origin;
Expand Down
1 change: 1 addition & 0 deletions packages/design-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@automattic/js-utils": "workspace:^",
"@automattic/onboarding": "workspace:^",
"@automattic/typography": "workspace:^",
"@automattic/viewport": "workspace:^",
"@tanstack/react-query": "^4.29.1",
"@wordpress/components": "^23.0.0",
"@wordpress/react-i18n": "^3.21.0",
Expand Down
1 change: 1 addition & 0 deletions packages/design-picker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export {
isBlankCanvasDesign,
isDefaultGlobalStylesVariationSlug,
getMShotOptions,
shouldGoToAssembler,
} from './utils';
export {
FONT_PAIRINGS,
Expand Down
5 changes: 5 additions & 0 deletions packages/design-picker/src/utils/designs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isWithinBreakpoint } from '@automattic/viewport';
import { addQueryArgs } from '@wordpress/url';
import { DEFAULT_VIEWPORT_HEIGHT } from '../constants';
import type { Design, DesignPreviewOptions } from '../types';
Expand Down Expand Up @@ -66,3 +67,7 @@ export const getDesignPreviewUrl = (
};

export const isAssemblerDesign = ( design?: Design ) => design?.design_type === 'assembler';

// Go to the assembler only when the viewport width >= 960px as the it doesn't support small
// screen for now.
export const shouldGoToAssembler = () => isWithinBreakpoint( '>=960px' );
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ __metadata:
"@automattic/js-utils": "workspace:^"
"@automattic/onboarding": "workspace:^"
"@automattic/typography": "workspace:^"
"@automattic/viewport": "workspace:^"
"@tanstack/react-query": ^4.29.1
"@testing-library/jest-dom": ^5.16.5
"@testing-library/react": ^14.0.0
Expand Down