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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
50878bf
Import Github modal without reloading
ajotka Oct 16, 2024
a62d862
Export Github without reloading
ajotka Oct 16, 2024
b2a9515
keep slug opens modal functionality
ajotka Oct 16, 2024
ab78d44
lint
ajotka Oct 16, 2024
2bceaf1
Merge branch 'trunk' into 1902
ajotka Oct 16, 2024
ccdb830
Merge remote-tracking branch 'origin/trunk' into 1902
ajotka Oct 22, 2024
192b7f8
Merge remote-tracking branch 'origin/trunk' into 1902
ajotka Oct 22, 2024
60ffe8a
remove signal from github modals
ajotka Oct 22, 2024
92ab9f1
WIP: modal UI refactor
ajotka Oct 22, 2024
e22cc20
WIP: fetch logic for PRs
ajotka Oct 24, 2024
239809d
split modal to wordpress & gutenberg
ajotka Oct 24, 2024
b784d98
lint
ajotka Oct 24, 2024
310e483
Merge remote-tracking branch 'origin/trunk' into pr-preview
ajotka Oct 24, 2024
747ba06
fix error handling
ajotka Oct 24, 2024
0fd6775
revert changes in import modal for now
ajotka Oct 24, 2024
b6a140d
Merge remote-tracking branch 'origin/trunk' into 1902
ajotka Oct 30, 2024
71cc2e3
fixes after CR
ajotka Oct 30, 2024
b5f3355
If only the 'modal' parameter changes in url, don't reload the page
ajotka Oct 30, 2024
419deb7
Merge remote-tracking branch 'origin/trunk' into 1902
ajotka Oct 31, 2024
02932bb
Brandon suggestion
ajotka Oct 31, 2024
3a94478
Merge remote-tracking branch 'origin/trunk' into pr-preview
ajotka Oct 31, 2024
20e3a5b
Merge remote-tracking branch 'origin/trunk' into pr-preview
ajotka Oct 31, 2024
c143d8d
Merge branch '1902' into pr-preview
ajotka Oct 31, 2024
23d9327
move all modals to wordpress/components
ajotka Oct 31, 2024
3bbd338
lint
ajotka Oct 31, 2024
f4acb75
read core-pr from url and put to modal
ajotka Oct 31, 2024
c3ee188
New dropdown menu
ajotka Oct 31, 2024
a33d69d
Merge branch 'trunk' into pr-preview
ajotka Oct 31, 2024
cece255
Merge branch 'trunk' into pr-preview
brandonpayton Oct 31, 2024
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useEffect, useState } from 'react';
import Modal from '../modal';
import React, { useEffect, useState } from 'react';
import { logger } from '@php-wasm/logger';
import { Button, TextareaControl, TextControl } from '@wordpress/components';
import { TextareaControl, TextControl, Modal } from '@wordpress/components';

import css from './style.module.css';
import css from '../modal/style.module.css';

import { Blueprint } from '@wp-playground/blueprints';
import { useDispatch } from 'react-redux';
Expand All @@ -13,6 +12,7 @@ import {
useAppSelector,
} from '../../lib/state/redux/store';
import { setActiveModal } from '../../lib/state/redux/slice-ui';
import ModalButtons from '../modal/modal-buttons';

export function ErrorReportModal(props: { blueprint: Blueprint }) {
const activeModal = useAppSelector(
Expand Down Expand Up @@ -157,49 +157,36 @@ export function ErrorReportModal(props: { blueprint: Blueprint }) {
}

return (
<Modal isOpen={true} onRequestClose={onClose}>
<header
className={css.errorReportModalHeader}
aria-label="Error reporting form header"
>
<h2>{getTitle()}</h2>
<p>{getContent()}</p>
</header>
<Modal title={getTitle()} onRequestClose={onClose} className={css.modalSmall}>
<p>{getContent()}</p>
{showForm() && (
<>
<main>
<TextareaControl
label="How can we recreate this error?"
help="Describe what caused the error and how can we recreate it."
value={text}
onChange={setText}
className={css.errorReportModalTextarea}
required={true}
/>
<TextareaControl
label="Logs"
value={logs}
onChange={setLogs}
className={css.errorReportModalTextarea}
/>

<TextControl
label="Url"
value={url}
onChange={setUrl}
/>
</main>
<footer className={css.errorReportModalFooter}>
<Button
variant="primary"
onClick={onSubmit}
isBusy={loading}
disabled={loading || !text}
>
Report error
</Button>
<Button onClick={onClose}>Cancel</Button>
</footer>
<TextareaControl
label="How can we recreate this error?"
help="Describe what caused the error and how can we recreate it."
value={text}
onChange={setText}
required={true}
/>
<TextareaControl
label="Logs"
value={logs}
onChange={setLogs}
/>

<TextControl
label="Url"
value={url}
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:

areBusy={loading}
areDisabled={loading || !text}
onCancel={onClose}
onSubmit={onSubmit}
submitText={'Report error'}
/>
</>
)}
</Modal>
Expand Down

This file was deleted.

28 changes: 10 additions & 18 deletions packages/playground/website/src/components/import-form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { PlaygroundClient, importWordPressFiles } from '@wp-playground/client';

import css from './style.module.css';
import forms from '../../forms.module.css';
import Button from '../button';
import { logger } from '@php-wasm/logger';
import ModalButtons from '../modal/modal-buttons';

interface ImportFormProps {
playground: PlaygroundClient;
Expand All @@ -18,7 +18,6 @@ export default function ImportForm({
onImported,
onClose,
}: ImportFormProps) {
const form = useRef<any>();
const fileInputRef = useRef<any>();
const [file, setFile] = useState<File | null>(null);
const [error, setError] = useState<string>('');
Expand Down Expand Up @@ -46,10 +45,7 @@ export default function ImportForm({
}

return (
<form id="import-playground-form" ref={form} onSubmit={handleSubmit}>
<h2 tabIndex={0} style={{ marginTop: 0, textAlign: 'center' }}>
Import Playground
</h2>
<>
<p className={css.modalText}>
You may replace the current WordPress Playground site with a
previously exported one.
Expand All @@ -64,17 +60,13 @@ export default function ImportForm({
accept="application/zip"
/>
</div>
<div className={forms.submitRow}>
<Button
id="import-submit--btn"
className={forms.btn}
disabled={!file}
variant="primary"
size="large"
>
Import
</Button>
</div>
</form>

<ModalButtons
areDisabled={!file}
onCancel={onClose}
onSubmit={handleSubmit}
submitText={'Import'}
/>
</>
);
}
20 changes: 10 additions & 10 deletions packages/playground/website/src/components/import-form/modal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { usePlaygroundClient } from '../../lib/use-playground-client';
import ImportForm from './index';
import Modal from '../modal';
import { Modal } from '@wordpress/components';
import { setActiveModal } from '../../lib/state/redux/slice-ui';
import { PlaygroundDispatch } from '../../lib/state/redux/store';
import { useDispatch } from 'react-redux';
Expand All @@ -23,18 +23,18 @@ export const ImportFormModal = () => {

return (
<Modal
isOpen={!!playground}
contentLabel='This is a dialog window which overlays the main content of the
title={'Import Playground'}
contentLabel='This is a dialog window which overlays the main content of the
page. The modal begins with a heading 2 called "Import
Playground". Pressing the Close Import Window will close
the modal and bring you back to where you were on the page.'
onRequestClose={closeModal}
>
<ImportForm
playground={playground!}
onClose={closeModal}
onImported={handleImported}
/>
onRequestClose={closeModal}
>
<ImportForm
playground={playground!}
onClose={closeModal}
onImported={handleImported}
/>
</Modal>
);
};
9 changes: 8 additions & 1 deletion packages/playground/website/src/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.


acquireOAuthTokenIfNeeded();

Expand All @@ -42,7 +43,9 @@ export const modalSlugs = {
START_ERROR: 'start-error',
IMPORT_FORM: 'import-form',
GITHUB_IMPORT: 'github-import',
GITHUB_EXPORT: 'github-export'
GITHUB_EXPORT: 'github-export',
PREVIEW_PR_WP: 'preview-pr-wordpress',
PREVIEW_PR_GUTENBERG: 'preview-pr-gutenberg',
}

const displayMode = getDisplayModeFromQuery();
Expand Down Expand Up @@ -178,6 +181,10 @@ function Modals(blueprint: Blueprint) {
return <StartErrorModal />;
} else if (currentModal === modalSlugs.IMPORT_FORM) {
return <ImportFormModal />;
} else if (currentModal === modalSlugs.PREVIEW_PR_WP) {
return <PreviewPRModal target={'wordpress'} />;
} else if (currentModal === modalSlugs.PREVIEW_PR_GUTENBERG) {
return <PreviewPRModal target={'gutenberg'} />;
} else if (currentModal === modalSlugs.GITHUB_IMPORT) {
return <GithubImportModal
onImported={({
Expand Down
16 changes: 5 additions & 11 deletions packages/playground/website/src/components/log-modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useEffect, useState } from 'react';
import Modal from '../modal';
import { logEventType, logger } from '@php-wasm/logger';

import classNames from 'classnames';
import css from './style.module.css';

import { TextControl } from '@wordpress/components';
import { Modal, TextControl } from '@wordpress/components';
import {
PlaygroundDispatch,
PlaygroundReduxState,
Expand All @@ -23,16 +22,11 @@ export function LogModal(props: { description?: JSX.Element; title?: string }) {
dispatch(setActiveModal(null));
}

const styles = {
content: { width: 800 },
};

return (
<Modal isOpen={true} onRequestClose={onClose} styles={styles}>
<header aria-label="Error logs list header">
<h2>{props.title || 'Error Logs'}</h2>
<Modal title={props.title || 'Error Logs'} onRequestClose={onClose}>
<div>
{props.description}
</header>
</div>
<SiteLogs key={activeModal} className={css.logsInsideModal} />
</Modal>
);
Expand Down Expand Up @@ -91,7 +85,7 @@ export function SiteLogs({ className }: { className?: string }) {
No matching logs found.
</div>
) : (
<div className={css.logEmptyPlaceholder}>
<div>
Error logs for Playground, WordPress, and PHP will show
up here when something goes wrong.
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
flex-grow: 1;
}

.log__list {
padding-bottom: 20px;
flex-grow: 1;
max-height: 100%;
}

.log__empty_placeholder {
padding-bottom: 20px;
}

.log__entry {
font-family: monospace;
word-wrap: break-word;
Expand Down
61 changes: 0 additions & 61 deletions packages/playground/website/src/components/modal/index.tsx

This file was deleted.

34 changes: 34 additions & 0 deletions packages/playground/website/src/components/modal/modal-buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Button, Flex } from '@wordpress/components';
import React from 'react';

interface ModalButtonsProps {
submitText?: string;
areDisabled?: boolean;
areBusy?: boolean;
onCancel?: () => void;
onSubmit?: (e: any) => void;
}
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.

>
<Button
isBusy={areBusy}
disabled={areDisabled}
variant="link"
onClick={onCancel}
>
Cancel
</Button>
<Button
isBusy={areBusy}
disabled={areDisabled}
variant="primary"
onClick={onSubmit}
>
{submitText}
</Button>
</Flex>
)
}
Loading