From ec2cc96aac91c9eb47d99894b3bfee9185ae73e7 Mon Sep 17 00:00:00 2001 From: anlinguist Date: Thu, 14 Mar 2024 11:19:04 -0600 Subject: [PATCH 1/2] feat(validation): pass validation severity into UI, see discussion #369 and issue # 148 --- .../controls/ValidationErrorsOverview.scss | 19 ++++++++++++--- .../controls/ValidationErrorsOverview.svelte | 4 ++-- .../components/modes/textmode/TextMode.svelte | 2 +- .../modes/treemode/ValidationErrorIcon.scss | 24 ++++++++++++++++++- .../modes/treemode/ValidationErrorIcon.svelte | 2 +- src/lib/themes/defaults.scss | 1 + 6 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/lib/components/controls/ValidationErrorsOverview.scss b/src/lib/components/controls/ValidationErrorsOverview.scss index cf4b6ade..57476fe0 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; @@ -16,7 +14,7 @@ cursor: pointer; &:hover { - background-color: rgba(255, 255, 255, 0.1); + filter: brightness(110%); } td { @@ -56,3 +54,18 @@ } } } + +.error { + background: $message-error-background; + color: $message-error-color; +} + +.warning { + background: $message-warning-background; + color: $message-warning-color; +} + +.info { + background: $message-info-background; + color: $message-info-color; +} \ No newline at end of file diff --git a/src/lib/components/controls/ValidationErrorsOverview.svelte b/src/lib/components/controls/ValidationErrorsOverview.svelte index 66615382..f2438c81 100644 --- a/src/lib/components/controls/ValidationErrorsOverview.svelte +++ b/src/lib/components/controls/ValidationErrorsOverview.svelte @@ -36,7 +36,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)) @@ -77,7 +77,7 @@ {:else} - +
{#each limit(validationErrors, MAX_VALIDATION_ERRORS) as validationError, index} { // trigger on the next tick to prevent the editor not getting focus setTimeout(() => selectError(validationError)) @@ -77,9 +88,9 @@
diff --git a/src/lib/components/modes/textmode/TextMode.svelte b/src/lib/components/modes/textmode/TextMode.svelte index 122b896a..170019f0 100644 --- a/src/lib/components/modes/textmode/TextMode.svelte +++ b/src/lib/components/modes/textmode/TextMode.svelte @@ -643,7 +643,7 @@ from, to, message, - severity: ValidationSeverity.warning, + severity: validationError.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 @@
{:else} - +
- + diff --git a/src/lib/components/modes/textmode/TextMode.svelte b/src/lib/components/modes/textmode/TextMode.svelte index 170019f0..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: validationError.severity, + severity, actions: [] } } diff --git a/src/routes/examples/custom_validation/+page.svelte b/src/routes/examples/custom_validation/+page.svelte index b67ef166..9a1b0b63 100644 --- a/src/routes/examples/custom_validation/+page.svelte +++ b/src/routes/examples/custom_validation/+page.svelte @@ -56,7 +56,7 @@ // check whether the team consists of exactly four members if (json.team.length !== 4) { - errors.push({ path: ['team'], message: 'A team must have 4 members', severity: 'warning' }) + errors.push({ path: ['team'], message: 'A team must have 4 members', severity: 'error' }) } // check whether there is at least one adult member in the team @@ -67,7 +67,7 @@ errors.push({ path: ['team'], message: 'A team must have at least one adult person (age >= 18)', - severity: 'warning' + severity: 'info' }) } } else {