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

Move WordPress & Gutenberg PR Preview to Playground website #1938

Open
wants to merge 29 commits into
base: trunk
Choose a base branch
from

Conversation

ajotka
Copy link
Contributor

@ajotka ajotka commented Oct 24, 2024

Motivation for the change, related issues

#1655 (comment)

I moved wordpress.html and gutenberg.html to Playground itself.
By the way, I also made a mini appearance refactor for the modal, based on Figma. And I used components from WordPress packages.

Implementation details

  • Add modals with input to fill PR number
  • Move & unify logic to fetch PR by number
  • Error handling
  • Appearance refactor for Modals
  • Implement new Modal to other components
  • Fetch PR number directly from query
  • New Dropdown Menu in main sidebar (thanks to this, we can import playground when we don't have any active one)

Testing Instructions (or ideally a Blueprint)

  • Any blueprint
  • Go to Playground settings
  • Click three dots next to Homepage button future Logo place
  • Select Preview a WordPress PR or Preview a Gutenberg PR

It is also possible to open modal via URL params:
/?modal=preview-pr-wordpress or /?modal=preview-pr-gutenberg

image
image
image

@ajotka ajotka marked this pull request as draft October 24, 2024 11:20
@ajotka
Copy link
Contributor Author

ajotka commented Oct 24, 2024

@adamziel Tell me, due to moving this functionality to Playground, should we remove the wordpress.html and gutenberg.html files?

FYI, I'm setting this PR as Draft for now, because I'm waiting for the changes to be accepted with other modals. After implementing those changes, I'll add this refactor of all modals -> headers and action buttons.

@adamziel
Copy link
Collaborator

due to moving this functionality to Playground, should we remove the wordpress.html and gutenberg.html files?

Good question! There are existing links to those files out there so adding a redirect to custom-redirects-lib.php seems like the best option. Looping in @brandonpayton.

I'm waiting for the changes to be accepted with other modals

One of them is now merged 🎉 And the other one has a last bit of pending feedback. I'm happy to merge once it's addressed. Thank you so much for contributing!

@brandonpayton
Copy link
Member

due to moving this functionality to Playground, should we remove the wordpress.html and gutenberg.html files?

Good question! There are existing links to those files out there so adding a redirect to custom-redirects-lib.php seems like the best option. Looping in @brandonpayton.

Hi @ajotka! We could add a redirect for wordpress.html and gutenberg.html if the open Preview PR modals were reflected in the Playground app URL. For example, the GitHub Export modal is auto-opened based on the URL:

https://playground.wordpress.net/?state=github-export

If the PR Preview modals were controlled in a similar way, we could add redirects to open them.

Here is the code that controls the GitHub Export modal visibility:

const query = new URLSearchParams(window.location.search);
export const isGitHubExportModalOpen = signal(
query.get('state') === 'github-export'
);
interface GithubExportModalProps {
allowZipExport: GitHubExportFormProps['allowZipExport'];
onExported?: GitHubExportFormProps['onExported'];
initialFilesBeforeChanges?: GitHubExportFormProps['initialFilesBeforeChanges'];
initialValues?: GitHubExportFormProps['initialValues'];
}
export function closeModal() {
isGitHubExportModalOpen.value = false;
// Remove ?state=github-export from the URL.
const url = new URL(window.location.href);
url.searchParams.delete('state');
window.history.replaceState({}, '', url.href);
}
export function openModal() {
isGitHubExportModalOpen.value = true;
// Add a ?state=github-export to the URL so that the user can refresh the page
// and still see the modal.
const url = new URL(window.location.href);
url.searchParams.set('state', 'github-export');
window.history.replaceState({}, '', url.href);
}

I'm not sure it's great for each modal to control its own visibility, but it should work OK for now.

@brandonpayton
Copy link
Member

If the PR Preview modals were controlled in a similar way, we could add redirects to open them.

Ah, I see how we are controlling other modal visibility via redux state. I think we'll need to have a way to link to certain modals or initialize that redux state if we want to redirect the old .html files to the PR Preview modals.

@brandonpayton
Copy link
Member

Oh, good! I see how #1908 should make all modals addressable via query param:
https://github.com/WordPress/wordpress-playground/pull/1908/files#diff-7b2f9269a39b35f1cb76b6085ebbe1aea324dc8a5043cc349559ddb0827beb38R31

At least it looks that way. I haven't tested it.

If modals are indeed addressable via query param after #1908, we should have no problem adding redirects after this PR is merged. I added #1969 to track this.

@ajotka ajotka marked this pull request as ready for review October 31, 2024 15:01
@ajotka ajotka requested a review from a team as a code owner October 31, 2024 15:01
@ajotka
Copy link
Contributor Author

ajotka commented Oct 31, 2024

Refactor is ready 🎉 @adamziel
-> Now, all modals are from @wordpress/components package.
-> I introduced ModalButtons for Cancel and Submit buttons at the bottom of modal.
-> I made two styles of modals; One, the default, 600px width. Second, modalSmall, 350px; (to prvent resizing when error or other new note will apperar.
-> New DropdownMenu, next to the future Logo (thanks to this, we can import playground when we don't have any active one).

@brandonpayton URL params for PR modals:
/?modal=preview-pr-wordpress
/?modal=preview-pr-gutenberg

Note: It would be good to merge #1908 to trunk first, because I used logic from there.

@brandonpayton
Copy link
Member

I merged the latest from trunk into this PR, so changes from #1908 are here now.

Planning to review shortly.

@brandonpayton
Copy link
Member

-> New DropdownMenu, next to the future Logo (thanks to this, we can import playground when we don't have any active one).

This is nice. It makes more sense IMO.

Copy link
Member

@brandonpayton brandonpayton left a comment

Choose a reason for hiding this comment

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

Hi @ajotka, I reviewed this and left some comments. Overall, it looks like a nice change, but I think some reorganization would be helpful before we merge.

onChange={setUrl}
/>

<ModalButtons
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to keep more vertical spacing between the bottom buttons and the content. The alignment change seems fine and aligns with other modals in the Playground web app redesign Figma.

Before this PR:

After this PR:

@@ -33,6 +33,7 @@ import {
setSiteManagerOpen,
} from '../../lib/state/redux/slice-ui';
import { ImportFormModal } from '../import-form/modal';
import { PreviewPRModal } from '../../github/preview-pr/modal';
Copy link
Member

Choose a reason for hiding this comment

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

The way the modal modules are laid out is a bit different than usual module layout.

Here, we are importing '../import-form/modal' which internally imports import-form/index. This surprised me because index typically represents the main/root export of a component.

Can we reorganize these modal modules and imports so that /index is the main representation of a component to other modules?

For import-form, it might look something like:

  • import-form-modal/index exports ImportFormModal as the default export
  • The modal imported like import ImportFormModal from '../import-form-modal';

The current organization works, but it's a bit backwards in the way it uses /index. I think we can make it more typical so it gives tomorrow's developers (and ourselves) nothing additional to think about when reading this code.

export default function ModalButtons({ submitText = 'Submit', areDisabled = false, areBusy, onCancel, onSubmit }: ModalButtonsProps) {
return (
<Flex
justify={'end'}
Copy link
Member

Choose a reason for hiding this comment

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

It's not a big deal, but if we're using a string, we can say just justify="end", without the curly braces.

import GitHubExportForm, { GitHubExportFormProps } from './form';
import { usePlaygroundClient } from '../../lib/use-playground-client';
import { PlaygroundDispatch } from '../../lib/state/redux/store';
import { useDispatch } from 'react-redux';
import { setActiveModal } from '../../lib/state/redux/slice-ui';
import { useEffect } from 'react';
import css from '../../components/modal/style.module.css';
Copy link
Member

Choose a reason for hiding this comment

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

If we are still using these styles everywhere, maybe we should restore the components/modal/index module, apply the styles in that one place, and then go back to importing Modal from components/modal rather than directly from @wordpress/components.

Seeing this needed for all the modals suggests that maybe we ultimately do have a Playground Modal. And if there are any places where that is too much, it would be OK for those to use @wordpress/components directly.

Does that sound reasonable?

@@ -430,10 +430,10 @@ export default function GitHubExportForm({
if (pushResult) {
return (
<form id="export-playground-form" onSubmit={handleSubmit}>
<h2 tabIndex={0} style={{ marginTop: 0, textAlign: 'center' }}>
<h3>
Copy link
Member

Choose a reason for hiding this comment

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

Why did these change from <h2> to <h3>? It doesn't look like there are any other <h2>'s in the modal. The modal title appears to be an <h1>.

@@ -10,9 +10,9 @@ import {
Icon,
__experimentalItemGroup as ItemGroup,
__experimentalItem as Item,
Flex,
Flex, DropdownMenu,
Copy link
Member

Choose a reason for hiding this comment

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

Nit: These should be on separate lines because the rest are line-separated.

{/* Remove Playground logo because branding isn't finalized. */}
{/* <Logo className={css.sidebarLogoButton} /> */}
</div>
{/* Padding 3px is because of focus on dropdown button */}
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for this "why" comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Up next
Development

Successfully merging this pull request may close these issues.

3 participants