From 6cd6af9bedbbf564f0463dbbb383a9cd2f8b84c4 Mon Sep 17 00:00:00 2001 From: Andrew Nelson <47403803+anlinguist@users.noreply.github.com> Date: Wed, 27 Mar 2024 03:20:09 -0600 Subject: [PATCH] feat: pass validation severity into UI (#416) Pass validation severity into UI, see discussion #369 and issues #148 and #150 --- .../controls/ValidationErrorsOverview.scss | 24 +++++++++++++++---- .../controls/ValidationErrorsOverview.svelte | 17 ++++++++++--- .../components/modes/textmode/TextMode.svelte | 4 ++-- .../modes/treemode/ValidationErrorIcon.scss | 24 ++++++++++++++++++- .../modes/treemode/ValidationErrorIcon.svelte | 2 +- src/lib/themes/defaults.scss | 1 + .../examples/custom_validation/+page.svelte | 4 ++-- 7 files changed, 63 insertions(+), 13 deletions(-) diff --git a/src/lib/components/controls/ValidationErrorsOverview.scss b/src/lib/components/controls/ValidationErrorsOverview.scss index cf4b6ade..5905d3e7 100644 --- a/src/lib/components/controls/ValidationErrorsOverview.scss +++ b/src/lib/components/controls/ValidationErrorsOverview.scss @@ -3,8 +3,6 @@ .jse-validation-errors-overview { font-family: $font-family-mono; font-size: $font-size-mono; - background: $message-warning-background; - color: $message-warning-color; overflow: auto; max-height: $errors-overview-max-height; @@ -15,8 +13,26 @@ tr { cursor: pointer; + &.jse-validation-error { + background: $message-error-background; + color: $message-error-color; + } + + &.jse-validation-warning { + background: $message-warning-background; + color: $message-warning-color; + &:hover { + filter: brightness(105%); + } + } + + &.jse-validation-info { + background: $message-info-background; + color: $message-info-color; + } + &:hover { - background-color: rgba(255, 255, 255, 0.1); + filter: brightness(110%); } td { @@ -55,4 +71,4 @@ } } } -} +} \ No newline at end of file diff --git a/src/lib/components/controls/ValidationErrorsOverview.svelte b/src/lib/components/controls/ValidationErrorsOverview.svelte index 66615382..fced3763 100644 --- a/src/lib/components/controls/ValidationErrorsOverview.svelte +++ b/src/lib/components/controls/ValidationErrorsOverview.svelte @@ -9,7 +9,7 @@ import { isEmpty } from 'lodash-es' import Icon from 'svelte-awesome' import { stringifyJSONPath } from '$lib/utils/pathUtils.js' - import type { ValidationError } from '$lib/types.js' + import { ValidationSeverity, type ValidationError } from '$lib/types.js' import { MAX_VALIDATION_ERRORS } from '$lib/constants.js' import { limit } from '$lib/utils/arrayUtils.js' @@ -27,6 +27,17 @@ function expand() { expanded = true } + + function getValidationClass(errors: ValidationError[]): string { + if (errors.some(e => e.severity === ValidationSeverity.error)) { + return 'error'; + } else if (errors.some(e => e.severity === ValidationSeverity.warning)) { + return 'warning'; + } else if (errors.some(e => e.severity === ValidationSeverity.info)) { + return 'info'; + } + return ''; + } {#if !isEmpty(validationErrors)} @@ -36,7 +47,7 @@ {#each limit(validationErrors, MAX_VALIDATION_ERRORS) as validationError, index} { // trigger on the next tick to prevent the editor not getting focus setTimeout(() => selectError(validationError)) @@ -79,7 +90,7 @@ {:else} - + diff --git a/src/lib/components/modes/textmode/TextMode.svelte b/src/lib/components/modes/textmode/TextMode.svelte index 122b896a..54b9ca9b 100644 --- a/src/lib/components/modes/textmode/TextMode.svelte +++ b/src/lib/components/modes/textmode/TextMode.svelte @@ -633,7 +633,7 @@ } function toRichValidationError(validationError: ValidationError): RichValidationError { - const { path, message } = validationError + const { path, message, severity } = validationError const { line, column, from, to } = findTextLocation(normalization.escapeValue(text), path) return { @@ -643,7 +643,7 @@ from, to, message, - severity: ValidationSeverity.warning, + severity, actions: [] } } diff --git a/src/lib/components/modes/treemode/ValidationErrorIcon.scss b/src/lib/components/modes/treemode/ValidationErrorIcon.scss index bc2b68c8..d01a090f 100644 --- a/src/lib/components/modes/treemode/ValidationErrorIcon.scss +++ b/src/lib/components/modes/treemode/ValidationErrorIcon.scss @@ -9,5 +9,27 @@ button.jse-validation-error { vertical-align: top; display: inline-flex; - color: $warning-color; + color: $error-color; +} + +button.jse-validation-info { + @include jsoneditor-button; + + padding: 0; + margin: 0; + vertical-align: top; + display: inline-flex; + + color: $info-color; } + +button.jse-validation-warning { + @include jsoneditor-button; + + padding: 0; + margin: 0; + vertical-align: top; + display: inline-flex; + + color: $warning-color; +} \ No newline at end of file diff --git a/src/lib/components/modes/treemode/ValidationErrorIcon.svelte b/src/lib/components/modes/treemode/ValidationErrorIcon.svelte index 73c5671c..342e6724 100644 --- a/src/lib/components/modes/treemode/ValidationErrorIcon.svelte +++ b/src/lib/components/modes/treemode/ValidationErrorIcon.svelte @@ -19,7 +19,7 @@