-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement validation errors overview and validation error annot…
…ations in code mode (#6) * fix: validation errors on an object/array not visible when expanded * feat: implement validation errors overview in TreeMode (WIP) * feat: add validation errors overview to CodeMode (WIP) * feat: show annotation with JSON schema errors in code mode * feat: make validation error overview expandable/collapsable * fix: positioning of floating context menu button and validation error icons * fix: editor not getting focus after clicking on a validation error * fix: validation errors not being updated when changed via public API * fix: do not show validation error summary when there is only one error, and remember collapsed state
- Loading branch information
Showing
10 changed files
with
309 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
@import '../../styles.scss'; | ||
|
||
.validation-errors-overview { | ||
font-family: $font-family-mono; | ||
font-size: $font-size-mono; | ||
background: $warning-color; | ||
color: $white; | ||
overflow: auto; | ||
max-height: $errors-overview-max-height; | ||
|
||
table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
|
||
tr { | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background-color: rgba(255, 255, 255, 0.1); | ||
} | ||
|
||
td { | ||
padding: 4px $padding; | ||
vertical-align:middle; | ||
|
||
&.validation-error-icon { | ||
width: 36px; | ||
box-sizing: border-box; | ||
} | ||
|
||
&.validation-error-action { | ||
width: 36px; | ||
box-sizing: border-box; | ||
padding: 0; | ||
|
||
button.validation-errors-collapse { | ||
width: 36px; | ||
height: 26px; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
background-color: rgba(255, 255, 255, 0.2); | ||
} | ||
} | ||
} | ||
|
||
div.validation-errors-expand { | ||
display: inline-block; | ||
position: relative; | ||
top: 3px; | ||
// TODO: position this icon in a better way | ||
} | ||
} | ||
} | ||
} | ||
} |
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,93 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import { | ||
faAngleDown, | ||
faAngleRight, | ||
faExclamationTriangle | ||
} from '@fortawesome/free-solid-svg-icons' | ||
import { isEmpty } from 'lodash-es' | ||
import Icon from 'svelte-awesome' | ||
import { stringifyPath } from '../../utils/pathUtils.js' | ||
/** | ||
* @type {ValidationError[]} | ||
**/ | ||
export let validationErrorsList | ||
/** | ||
* @type {function(error: ValidationError)} | ||
*/ | ||
export let selectError | ||
let expanded = true | ||
function collapse () { | ||
expanded = false | ||
} | ||
function expand () { | ||
expanded = true | ||
} | ||
$: filteredValidationErrors = validationErrorsList.filter(error => !error.isChildError) | ||
</script> | ||
|
||
{#if !isEmpty(validationErrorsList)} | ||
<div class="validation-errors-overview"> | ||
{#if expanded || validationErrorsList.length === 1} | ||
<table> | ||
<tbody> | ||
{#each validationErrorsList as validationError, index} | ||
<tr | ||
class="validation-error" | ||
on:click={() => { | ||
// trigger on the next tick to prevent the editor not getting focus | ||
setTimeout(() => selectError(validationError)) | ||
}} | ||
> | ||
<td class="validation-error-icon"> | ||
<Icon data={faExclamationTriangle} /> | ||
</td> | ||
<td> | ||
{stringifyPath(validationError.path)} | ||
</td> | ||
<td> | ||
{validationError.message} | ||
</td> | ||
<td class="validation-error-action"> | ||
{#if index === 0 && validationErrorsList.length > 1} | ||
<button | ||
class="validation-errors-collapse" | ||
on:click|stopPropagation={collapse} | ||
title="Collapse validation errors" | ||
> | ||
<Icon data={faAngleDown} /> | ||
</button> | ||
{/if} | ||
</td> | ||
</tr> | ||
{/each} | ||
</tbody> | ||
</table> | ||
{:else} | ||
<table> | ||
<tbody> | ||
<tr class="validation-error" on:click={expand}> | ||
<td class="validation-error-icon"> | ||
<Icon data={faExclamationTriangle} /> | ||
</td> | ||
<td> | ||
{validationErrorsList.length} validation errors | ||
<div class="validation-errors-expand"> | ||
<Icon data={faAngleRight} /> | ||
</div> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
{/if} | ||
</div> | ||
{/if} | ||
|
||
<style src="./ValidationErrorsOverview.scss"></style> |
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
Oops, something went wrong.