-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
chore(website): error viewer in playground #5061
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e122a08
chore(website): add POC for error viewer in playground
armano2 236a440
chore(website): correct colors
armano2 0471e16
chore(website): correct issue with optional fixers
armano2 d541bcb
chore(website): expose fixers to errors-viewer
armano2 44206d1
chore(website): add simple locking system for fixers
armano2 164f254
Merge remote-tracking branch 'origin/main' into chore/errors-view-in-…
armano2 d7c249a
chore(website): change label apply to fix
armano2 9790b65
Merge remote-tracking branch 'origin/main' into chore/errors-view-in-…
armano2 f7691a0
fix: correct small issue with compilerOptions not updating in eslint
armano2 f0ae860
fix: apply changes requested in code review
armano2 85ad1b8
Merge remote-tracking branch 'origin/main' into chore/errors-view-in-…
armano2 b7d93c7
fix: apply changes from code review
armano2 59ca8ca
fix: add useMemo to cache model
armano2 3694da2
Update packages/website/src/components/ErrorsViewer.tsx
armano2 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 hidden or 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 |
---|---|---|
|
@@ -229,4 +229,4 @@ | |
"totalDonations": 1500, | ||
"website": "https://www.mysportsinjury.co.uk" | ||
} | ||
] | ||
] | ||
This file contains hidden or 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,21 @@ | ||
.list { | ||
font-family: var(--ifm-font-family-monospace); | ||
background: transparent; | ||
border: none; | ||
padding-left: 1.5rem; | ||
padding-right: 1.5rem; | ||
font-size: 13px; | ||
line-height: 18px; | ||
letter-spacing: 0; | ||
font-feature-settings: 'liga' 0, 'calt' 0; | ||
box-sizing: border-box; | ||
white-space: break-spaces; | ||
margin: 0; | ||
} | ||
|
||
.fixer { | ||
margin: 0.5rem 1.5rem; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} |
This file contains hidden or 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,111 @@ | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import type Monaco from 'monaco-editor'; | ||
import type { ErrorItem } from './types'; | ||
|
||
import styles from './ErrorsViewer.module.css'; | ||
|
||
export interface ErrorsViewerProps { | ||
readonly value?: ErrorItem[]; | ||
} | ||
|
||
export interface ErrorBlockProps { | ||
readonly item: ErrorItem; | ||
readonly setIsLocked: (value: boolean) => void; | ||
readonly isLocked: boolean; | ||
} | ||
|
||
function severityClass(severity: Monaco.MarkerSeverity): string { | ||
switch (severity) { | ||
case 8: | ||
return 'danger'; | ||
case 4: | ||
return 'caution'; | ||
case 2: | ||
return 'note'; | ||
} | ||
return 'info'; | ||
} | ||
|
||
function groupErrorItems(items: ErrorItem[]): [string, ErrorItem[]][] { | ||
return Object.entries( | ||
items.reduce<Record<string, ErrorItem[]>>((acc, obj) => { | ||
if (!acc[obj.group]) { | ||
acc[obj.group] = []; | ||
} | ||
acc[obj.group].push(obj); | ||
return acc; | ||
}, {}), | ||
).sort(([a], [b]) => a.localeCompare(b)); | ||
} | ||
|
||
function ErrorBlock({ | ||
item, | ||
setIsLocked, | ||
isLocked, | ||
}: ErrorBlockProps): JSX.Element { | ||
return ( | ||
<div className={`admonition alert alert--${severityClass(item.severity)}`}> | ||
<div className="admonition-content"> | ||
<div className="row row--no-gutters"> | ||
<div className="col col--12"> | ||
{item.message} {item.location} | ||
</div> | ||
{item.hasFixers && ( | ||
<div className="col col--12"> | ||
{item.fixers.map((fixer, index) => ( | ||
<div key={index} className={styles.fixer}> | ||
<span>> {fixer.message}</span> | ||
<button | ||
className="button button--primary button--sm" | ||
disabled={isLocked} | ||
onClick={(): void => { | ||
fixer.fix(); | ||
setIsLocked(true); | ||
}} | ||
> | ||
fix | ||
</button> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default function ErrorsViewer({ | ||
value, | ||
}: ErrorsViewerProps): JSX.Element { | ||
const model = useMemo( | ||
() => (value ? groupErrorItems(value) : undefined), | ||
[value], | ||
); | ||
|
||
const [isLocked, setIsLocked] = useState(false); | ||
|
||
useEffect(() => { | ||
setIsLocked(false); | ||
}, [value]); | ||
armano2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<div className={styles.list}> | ||
{model?.map(([group, data]) => { | ||
return ( | ||
<div className="margin-top--sm" key={group}> | ||
<h4>{group}</h4> | ||
{data.map((item, index) => ( | ||
<ErrorBlock | ||
isLocked={isLocked} | ||
setIsLocked={setIsLocked} | ||
item={item} | ||
key={index} | ||
/> | ||
))} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.