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

Create selectors for the Live Preview feature #80017

Merged
merged 13 commits into from
Aug 2, 2023

Conversation

okmttdhr
Copy link
Member

@okmttdhr okmttdhr commented Jul 31, 2023

Related to #79219, #79218, #79775

Proposed Changes

Extract functions added in #79775 into selectors. This allows us to reuse functions between #79219 and #79218.

Testing Instructions

Simple sites

  • Patch D117384-code into your sandbox.
  • Go to the Theme Showcase page.
  • Click any theme and go to the Theme Detail page.
  • See if clicking the "Live Preview" button redirects you to the Site Editor (Block Theme Previews).
    • You will not see the button when a theme is;
      • your active theme
      • is not FullSiteEditing compatible
      • a theme with a static page as a homepage
      • a 3rd party theme
      • a premium theme
      • a woocommerce theme

Atomic sites

  • Go to the Theme Showcase page.
  • Click any theme and go to the Theme Detail page.
  • You must install a theme before using the Live Preview on Atomic sites. pbxlJb-3Uv-p2#known-issues
    • When you're using Calypso, activate it once and then reactivate the original theme.
    • When you're using the classic view, just install it.
  • See if clicking the "Live Preview" button redirects you to the Site Editor (Block Theme Previews). -> I am not yet sure how to patch it to make BTP work (c.f. https://github.com/Automattic/dotcom-forge/issues/3322). We can just check if the "Live Preview" button exists or not.
    • You will not see the button when a theme is;
      • your active theme
      • is not FullSiteEditing compatible
      • a theme with a static page as a homepage
      • not installed (not listed in "My Themes")

Please see pbxlJb-3Uv-p2#known-issues about unsupported themes.
I don't think we should go through everything in this PR since I just extracted some functions from #79219.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-ajp-p2)?

@github-actions
Copy link

github-actions bot commented Jul 31, 2023

@matticbot
Copy link
Contributor

matticbot commented Jul 31, 2023

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~13 bytes removed 📉 [gzipped])

name    parsed_size           gzip_size
theme        -406 B  (-0.1%)      -13 B  (-0.0%)
themes        +21 B  (+0.0%)      +10 B  (+0.0%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@okmttdhr okmttdhr force-pushed the add/btp-theme-showcase-prepare branch from bb39fae to 2f4cd9a Compare August 1, 2023 04:57
@okmttdhr okmttdhr changed the title Add the “Live Preview” button on the Themes Showcase page Create selectors for the Live Preview feature Aug 1, 2023
@okmttdhr okmttdhr force-pushed the add/btp-theme-showcase-prepare branch from 2f4cd9a to a66c3fd Compare August 1, 2023 05:19
@okmttdhr okmttdhr marked this pull request as ready for review August 1, 2023 06:41
@okmttdhr okmttdhr requested a review from a team August 1, 2023 07:07
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 1, 2023
@okmttdhr okmttdhr self-assigned this Aug 1, 2023
Copy link
Contributor

@arthur791004 arthur791004 left a comment

Choose a reason for hiding this comment

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

Nice refactor! Leave minor feedback but they're not blockers 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, but I'd like to encourage you to use Typescript for new files and components introduced in this PR, if possible!

Copy link
Member Author

Choose a reason for hiding this comment

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

Will create a follow up PR 😄

@okmttdhr okmttdhr force-pushed the add/btp-theme-showcase-prepare branch from ebea88e to 058c7fe Compare August 2, 2023 05:37
@taipeicoder
Copy link
Contributor

@okmttdhr could you confirm that the livePreviewUrl is correct? This is what I'm seeing on my end:

Screenshot 2023-08-02 at 2 08 45 PM

Always use siteId to get the URL.
And use sourceSiteId when it prevents Layout Shift.
@okmttdhr
Copy link
Member Author

okmttdhr commented Aug 2, 2023

could you confirm that the livePreviewUrl is correct? This is what I'm seeing on my end:

Thanks for pointing that out. I addressed it in c204113.

@okmttdhr
Copy link
Member Author

okmttdhr commented Aug 2, 2023

I'm merging this PR!

@okmttdhr okmttdhr merged commit 40b689a into trunk Aug 2, 2023
@okmttdhr okmttdhr deleted the add/btp-theme-showcase-prepare branch August 2, 2023 07:18
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Aug 2, 2023

// Block Theme Previews need the theme installed on Atomic sites.
const isAtomic = isSiteAutomatedTransfer( state, siteId );
const isThemeInstalledOnAtomicSite = isAtomic && !! getTheme( state, sourceSiteId, themeId );
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to use siteId instead of sourceSiteId here. I'm getting the following error message on Atomic sites:

Screenshot 2023-08-02 at 3 27 25 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's open a follow-up PR 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll take a look. Where did you see this error? Maybe on the Block Theme Previews page (= Site Editor)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep!

Copy link
Member Author

@okmttdhr okmttdhr Aug 2, 2023

Choose a reason for hiding this comment

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

@taipeicoder One more question, on which theme did you see the error, as an example? Thanks! 🙏

Copy link
Contributor

Choose a reason for hiding this comment

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

I've opened the issue #80133 to track this 🙂

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.

4 participants