-
Notifications
You must be signed in to change notification settings - Fork 272
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
Show error log if Playground fails to start #1336
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c8f8f03
Add log modal
bgrgicak 9312991
Add search and styles
bgrgicak a0c05b0
Reverse order of logs to reduce scrolling
bgrgicak c2840f7
Show logs on Playgound start error
bgrgicak ce59dd5
Add start error modal
bgrgicak 272e2d1
Add dismiss
bgrgicak 5d5625e
Fix linter error
bgrgicak 55bd7ee
Merge branch 'trunk' into add/1230-blueprint-error-show-logs
bgrgicak eab466f
Update message and show error modal
bgrgicak 2a6add2
Merge branch 'trunk' into add/1230-blueprint-error-show-logs
bgrgicak 7d2bb35
Fix modal overriding each other
bgrgicak 2dfec6f
Isolate modal code
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
59 changes: 59 additions & 0 deletions
59
packages/playground/website/src/components/log-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,59 @@ | ||
import { useEffect, useState } from 'react'; | ||
import Modal from '../modal'; | ||
import { logger } from '@php-wasm/logger'; | ||
|
||
import css from './style.module.css'; | ||
|
||
import { usePlaygroundContext } from '../../playground-context'; | ||
import { TextControl } from '@wordpress/components'; | ||
|
||
export function LogModal(props: { description?: JSX.Element; title?: string }) { | ||
const { activeModal, setActiveModal } = usePlaygroundContext(); | ||
const [logs, setLogs] = useState<string[]>([]); | ||
const [searchTerm, setSearchTerm] = useState(''); | ||
|
||
useEffect(getLogs, [activeModal]); | ||
|
||
function getLogs() { | ||
setLogs(logger.getLogs()); | ||
} | ||
|
||
function onClose() { | ||
setActiveModal(false); | ||
} | ||
|
||
function logList() { | ||
return logs | ||
.filter((log) => | ||
log.toLowerCase().includes(searchTerm.toLowerCase()) | ||
) | ||
.reverse() | ||
.map((log, index) => ( | ||
<pre className={css.logModalLog} key={index}> | ||
{log} | ||
</pre> | ||
)); | ||
} | ||
|
||
const styles = { | ||
content: { width: 800 }, | ||
}; | ||
|
||
return ( | ||
<Modal isOpen={true} onRequestClose={onClose} styles={styles}> | ||
<header> | ||
<h2>{props.title || 'Logs'}</h2> | ||
{props.description} | ||
<TextControl | ||
title="Search" | ||
placeholder="Search logs" | ||
value={searchTerm} | ||
onChange={setSearchTerm} | ||
autoFocus={true} | ||
className={css.logModalSearch} | ||
/> | ||
</header> | ||
<main className={css.logModalMain}>{logList()}</main> | ||
</Modal> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/playground/website/src/components/log-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,14 @@ | ||
.log-modal__main { | ||
padding-bottom: 20px; | ||
} | ||
|
||
.log-modal__search { | ||
/* Title margin bottom + log margin top */ | ||
margin-bottom: 1.33rem; | ||
} | ||
|
||
.log-modal__log { | ||
text-wrap: wrap; | ||
word-wrap: break-word; | ||
margin: 0.5rem 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
45 changes: 45 additions & 0 deletions
45
packages/playground/website/src/components/start-error-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,45 @@ | ||
import { Button } from '@wordpress/components'; | ||
import { LogModal } from '../log-modal'; | ||
import { useState } from '@wordpress/element'; | ||
|
||
import css from './style.module.css'; | ||
|
||
export const localStorageKey = 'playground-start-error-dont-show-again'; | ||
|
||
export function StartErrorModal() { | ||
const [dontShowAgain, setDontShowAgain] = useState( | ||
localStorage.getItem(localStorageKey) === 'true' | ||
); | ||
|
||
if (dontShowAgain) { | ||
return null; | ||
} | ||
|
||
const dismiss = () => { | ||
localStorage.setItem(localStorageKey, 'true'); | ||
setDontShowAgain(true); | ||
}; | ||
|
||
const description = ( | ||
<> | ||
<p> | ||
An error occurred while starting Playground. Please read the | ||
logs below to understand the issue. If there is Invalid | ||
blueprint error, the error will include the step which caused | ||
the issue. You can review your blueprint and{' '} | ||
<a href="https://wordpress.github.io/wordpress-playground/blueprints-api/troubleshoot-and-debug-blueprints"> | ||
check out the documentation | ||
</a>{' '} | ||
for more information. | ||
</p> | ||
<Button | ||
className={css.startErrorModalDismiss} | ||
text="Don't show again" | ||
onClick={dismiss} | ||
variant="secondary" | ||
isSmall={true} | ||
/> | ||
</> | ||
); | ||
return <LogModal title="Error" description={description} />; | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/playground/website/src/components/start-error-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,3 @@ | ||
.start-error-modal__dismiss { | ||
margin-bottom: 1.33rem; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
packages/playground/website/src/components/toolbar-buttons/view-logs.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 { details } from '@wordpress/icons'; | ||
|
||
import { usePlaygroundContext } from '../../playground-context'; | ||
|
||
type Props = { onClose: () => void }; | ||
export function ViewLogs({ onClose }: Props) { | ||
const { setActiveModal } = usePlaygroundContext(); | ||
return ( | ||
<MenuItem | ||
icon={details} | ||
iconPosition="left" | ||
data-cy="view-logs" | ||
aria-label="View logs" | ||
onClick={() => { | ||
setActiveModal('log'); | ||
onClose(); | ||
}} | ||
> | ||
View logs | ||
</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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
import { createContext, useContext } from 'react'; | ||
import { StorageType } from './types'; | ||
|
||
export type ActiveModal = 'error-report' | 'log' | 'start-error' | false; | ||
|
||
export const PlaygroundContext = createContext<{ | ||
storage: StorageType; | ||
showErrorModal: boolean; | ||
setShowErrorModal: (show: boolean) => void; | ||
}>({ storage: 'none', showErrorModal: false, setShowErrorModal: () => {} }); | ||
activeModal: ActiveModal; | ||
setActiveModal: (modal: ActiveModal) => void; | ||
}>({ | ||
storage: 'none', | ||
activeModal: false, | ||
setActiveModal: () => {}, | ||
}); | ||
export const usePlaygroundContext = () => useContext(PlaygroundContext); |
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.
Let's use
target="_blank"
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.
Rewrite proposal:
Oops! There was a problem starting Playground. To figure out what went wrong, please take a look at the error logs provided below. If you see an "Invalid blueprint error," the logs will point out the specific step causing the issue. You can then double-check your blueprint. For more help, you can also visit our documentation.
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.
Would the crash modal replace this one if the error is a fatal crash?
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.
Yes, after fixing eab466f. But it doesn't look good. It first shows the logger and after that the error report modal. I need to find a way to not show logs in this case.
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.
It took me a bit to get to a clean solution, but this should work now 2dfec6f