-
Notifications
You must be signed in to change notification settings - Fork 268
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
Website: Add error report modal #1102
Merged
Merged
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
b100814
Collect request errors
bgrgicak 5b03727
Remove service worker logs
bgrgicak 16295b6
Add fatal error event
bgrgicak bc874a5
Fix base-php error
bgrgicak db6bde2
Add event listener
bgrgicak 0c1ac32
Fix linter errors
bgrgicak 20d5190
Remove debug code
bgrgicak a9dd3a9
Use custom event target instead of window
bgrgicak 669757e
Collect request errors
bgrgicak da44dd0
Remove service worker logs
bgrgicak f295b8c
Add fatal error event
bgrgicak 24f4d0d
Fix base-php error
bgrgicak c3d4941
Add event listener
bgrgicak 6520a2b
Fix linter errors
bgrgicak f447ca9
Remove debug code
bgrgicak f8694b8
Use custom event target instead of window
bgrgicak 416e40c
Add error report modal
bgrgicak 298e241
Always show fields
bgrgicak 12418ef
Merge branch 'add/logger-crash-event' into add/error-report-modal
bgrgicak 6e5f8e0
Collect request errors
bgrgicak 29d0553
Add fatal error event
bgrgicak e473349
Remove debug code
bgrgicak 16a9ed1
Merge branch 'add/error-report-modal' of https://github.com/WordPress…
bgrgicak 9762186
Merge branch 'trunk' into add/logger-crash-event
bgrgicak 8891776
Merge branch 'add/logger-crash-event' into add/error-report-modal
bgrgicak 7bb6157
Linter
bgrgicak 93e28c0
Inline dispatch event method
bgrgicak 8f6c9d3
Update packages/playground/website/src/components/error-report-modal/…
bgrgicak fc3c28b
Update packages/playground/website/src/components/error-report-modal/…
bgrgicak a7f2347
Remove section
bgrgicak 9c5b595
Merge branch 'add/logger-crash-event' into add/error-report-modal
bgrgicak be0148c
Merge branch 'trunk' into add/logger-crash-event
bgrgicak a9aa605
Add event listener tests
bgrgicak 88d497f
Merge branch 'add/logger-crash-event' into add/error-report-modal
bgrgicak 74eecae
Merge branch 'trunk' into add/error-report-modal
bgrgicak 212e72d
Add untested API request and update submit messages
bgrgicak f46d37b
Merge branch 'trunk' into add/error-report-modal
bgrgicak 65b683f
Allow CORS requests to logger.php
bgrgicak 009bc98
Vif validation issues
bgrgicak 0e0a441
Toggle form states
bgrgicak 22c3fac
Merge branch 'trunk' into add/error-report-modal
bgrgicak ee0bd6f
Remove temp code
bgrgicak 978dec8
Prevent PHP errors from triggering modal
bgrgicak ac9f9cd
Fix typo
bgrgicak 8c33769
Update packages/playground/website/src/components/error-report-modal/…
bgrgicak 38e8889
Merge branch 'trunk' into add/error-report-modal
bgrgicak 74f6c7a
Separate log message parts
bgrgicak c5e1ca5
Format logger
bgrgicak b2dfafc
Add report error button
bgrgicak 559a603
Merge branch 'trunk' into add/error-report-modal
bgrgicak 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
This file contains 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 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 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 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 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 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
182 changes: 182 additions & 0 deletions
182
packages/playground/website/src/components/error-report-modal/index.tsx
This file contains 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,182 @@ | ||
import { useEffect, useState } from 'react'; | ||
import Modal from '../modal'; | ||
import { addFatalErrorListener, logger } from '@php-wasm/logger'; | ||
import { Button, TextareaControl, TextControl } from '@wordpress/components'; | ||
|
||
import css from './style.module.css'; | ||
|
||
import { usePlaygroundContext } from '../../playground-context'; | ||
|
||
export function ErrorReportModal() { | ||
const { showErrorModal, setShowErrorModal } = usePlaygroundContext(); | ||
const [loading, setLoading] = useState(false); | ||
const [text, setText] = useState(''); | ||
const [logs, setLogs] = useState(''); | ||
const [url, setUrl] = useState(''); | ||
const [submitted, setSubmitted] = useState(false); | ||
const [submitError, setSubmitError] = useState(''); | ||
|
||
useEffect(() => { | ||
addFatalErrorListener(logger, (e) => { | ||
const error = e as CustomEvent; | ||
if (error.detail?.source === 'php-wasm') { | ||
setShowErrorModal(true); | ||
} | ||
}); | ||
}, [setShowErrorModal]); | ||
|
||
useEffect(() => { | ||
resetForm(); | ||
if (showErrorModal) { | ||
setLogs(logger.getLogs().join('')); | ||
setUrl(window.location.href); | ||
} | ||
}, [showErrorModal, setShowErrorModal, logs, setLogs]); | ||
|
||
function resetForm() { | ||
setText(''); | ||
setLogs(''); | ||
setUrl(''); | ||
} | ||
|
||
function resetSubmission() { | ||
setSubmitted(false); | ||
setSubmitError(''); | ||
} | ||
|
||
function onClose() { | ||
setShowErrorModal(false); | ||
resetForm(); | ||
resetSubmission(); | ||
} | ||
|
||
async function onSubmit() { | ||
setLoading(true); | ||
const formdata = new FormData(); | ||
formdata.append('description', text); | ||
if (logs) { | ||
formdata.append('logs', logs); | ||
} | ||
if (url) { | ||
formdata.append('url', url); | ||
} | ||
try { | ||
const response = await fetch( | ||
'https://playground.wordpress.net/logger.php', | ||
{ | ||
method: 'POST', | ||
body: formdata, | ||
} | ||
); | ||
setSubmitted(true); | ||
|
||
const body = await response.json(); | ||
if (!body.ok) { | ||
throw new Error(body.error); | ||
} | ||
|
||
setSubmitError(''); | ||
resetForm(); | ||
} catch (e) { | ||
setSubmitError((e as Error).message); | ||
} finally { | ||
setLoading(false); | ||
} | ||
} | ||
|
||
function getTitle() { | ||
if (!submitted) { | ||
return 'Report error'; | ||
} else if (submitError) { | ||
return 'Failed to report the error'; | ||
} else { | ||
return 'Thank you for reporting the error'; | ||
} | ||
} | ||
|
||
function getContent() { | ||
if (!submitted) { | ||
return ( | ||
<> | ||
Playground crashed because of an error. You can help resolve | ||
the issue by sharing the error details with us. | ||
</> | ||
); | ||
} else if (submitError) { | ||
return ( | ||
<> | ||
We were unable to submit the error report. Please try again | ||
or open an{' '} | ||
<a href="https://github.com/WordPress/wordpress-playground/issues/"> | ||
issue on GitHub. | ||
</a> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<> | ||
Your report has been submitted to the{' '} | ||
<a href="https://wordpress.slack.com/archives/C06Q5DCKZ3L"> | ||
Making WordPress #playground-logs Slack channel | ||
</a>{' '} | ||
and will be reviewed by the team. | ||
</> | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Show the form if the error has not been submitted or if there was an error submitting it. | ||
* | ||
* @return {boolean} | ||
*/ | ||
function showForm() { | ||
return !submitted || submitError; | ||
} | ||
|
||
return ( | ||
<Modal isOpen={showErrorModal} onRequestClose={onClose}> | ||
<header className={css.errorReportModalHeader}> | ||
<h2>{getTitle()}</h2> | ||
<p>{getContent()}</p> | ||
</header> | ||
{showForm() && ( | ||
<> | ||
<main> | ||
<TextareaControl | ||
label="What happened?" | ||
help="Describe what caused the error and how can we reproduce 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> | ||
</> | ||
)} | ||
</Modal> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/playground/website/src/components/error-report-modal/style.module.css
This file contains 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,19 @@ | ||
.error-report-modal__header h2 { | ||
font-size: 20px; | ||
} | ||
|
||
.error-report-modal__header p { | ||
font-size: 13px; | ||
} | ||
|
||
.error-report-modal__textarea textarea { | ||
resize: vertical; | ||
width: 100% !important; | ||
} | ||
|
||
.error-report-modal__footer { | ||
margin-top: 20px; | ||
} | ||
.error-report-modal__error { | ||
margin: 16px 0 0; | ||
} |
This file contains 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 |
---|---|---|
|
@@ -20,5 +20,4 @@ | |
padding: 15px; | ||
text-align: left; | ||
max-height: 90vh; | ||
overflow: auto; | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/playground/website/src/components/toolbar-buttons/report-error.tsx
This file contains 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,23 @@ | ||
import { MenuItem } from '@wordpress/components'; | ||
import { bug } from '@wordpress/icons'; | ||
|
||
import { usePlaygroundContext } from '../../playground-context'; | ||
|
||
type Props = { onClose: () => void }; | ||
export function ReportError({ onClose }: Props) { | ||
const { setShowErrorModal } = usePlaygroundContext(); | ||
return ( | ||
<MenuItem | ||
icon={bug} | ||
iconPosition="left" | ||
data-cy="report-error" | ||
aria-label="Report an error in Playground" | ||
onClick={() => { | ||
setShowErrorModal(true); | ||
onClose(); | ||
}} | ||
> | ||
Report error | ||
</MenuItem> | ||
); | ||
} |
This file contains 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ import { StorageType, StorageTypes } from './types'; | |
import { ResetSiteMenuItem } from './components/toolbar-buttons/reset-site'; | ||
import { DownloadAsZipMenuItem } from './components/toolbar-buttons/download-as-zip'; | ||
import { RestoreFromZipMenuItem } from './components/toolbar-buttons/restore-from-zip'; | ||
import { ReportError } from './components/toolbar-buttons/report-error'; | ||
import { resolveBlueprint } from './lib/resolve-blueprint'; | ||
import { GithubImportMenuItem } from './components/toolbar-buttons/github-import-menu-item'; | ||
import { acquireOAuthTokenIfNeeded } from './github/acquire-oauth-token-if-needed'; | ||
|
@@ -27,6 +28,7 @@ import { ExportFormValues } from './github/github-export-form/form'; | |
import { joinPaths } from '@php-wasm/util'; | ||
import { PlaygroundContext } from './playground-context'; | ||
import { collectWindowErrors, logger } from '@php-wasm/logger'; | ||
import { ErrorReportModal } from './components/error-report-modal'; | ||
|
||
collectWindowErrors(logger); | ||
|
||
|
@@ -80,13 +82,17 @@ if (currentConfiguration.wp === '6.3') { | |
acquireOAuthTokenIfNeeded(); | ||
|
||
function Main() { | ||
const [showErrorModal, setShowErrorModal] = useState(false); | ||
const [githubExportFiles, setGithubExportFiles] = useState<any[]>(); | ||
const [githubExportValues, setGithubExportValues] = useState< | ||
Partial<ExportFormValues> | ||
>({}); | ||
|
||
return ( | ||
<PlaygroundContext.Provider value={{ storage }}> | ||
<PlaygroundContext.Provider | ||
value={{ storage, showErrorModal, setShowErrorModal }} | ||
> | ||
<ErrorReportModal /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up idea – add a "Report an error" button to trigger the modal manually. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done b2dfafc |
||
<PlaygroundViewport | ||
storage={storage} | ||
displayMode={displayMode} | ||
|
@@ -115,6 +121,7 @@ function Main() { | |
storage={currentConfiguration.storage} | ||
onClose={onClose} | ||
/> | ||
<ReportError onClose={onClose} /> | ||
<DownloadAsZipMenuItem onClose={onClose} /> | ||
<RestoreFromZipMenuItem onClose={onClose} /> | ||
<GithubImportMenuItem onClose={onClose} /> | ||
|
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.
Is this for Playground integrators?
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.
This is for localhost, but it's also required if we want to allow an integrator to send error reports.