From 8eb60968d53d73317f53bf427465ea17d852803b Mon Sep 17 00:00:00 2001 From: Gerard Burns Date: Wed, 3 Apr 2024 10:02:37 +0100 Subject: [PATCH] wip --- .../settings/controls/FieldSelect.svelte | 5 +- .../settings/controls/MultiFieldSelect.svelte | 5 +- .../design/settings/fieldValidator.js | 82 ++++++++++++------- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/FieldSelect.svelte b/packages/builder/src/components/design/settings/controls/FieldSelect.svelte index 9b636b20c2..3f39c12800 100644 --- a/packages/builder/src/components/design/settings/controls/FieldSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/FieldSelect.svelte @@ -3,7 +3,7 @@ import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding" import { selectedScreen } from "stores/builder" import { createEventDispatcher } from "svelte" - import { validators, supported, partialSupport, unsupported } from "../fieldValidator"; + import { validators, constants as validatorConstants } from "../fieldValidator"; export let componentInstance = {} export let value = "" @@ -52,6 +52,7 @@ } const getOptionIcon = option => { + /* const support = fieldSupport[option]?.support; if (support == null) return null; @@ -59,12 +60,14 @@ if (support === partialSupport) return "Warning" if (support === unsupported) return "Error" +*/ } const getOptionIconTooltip = option => { } const isOptionEnabled = option => { + return true const support = fieldSupport[option]?.support; if (support == null) return true diff --git a/packages/builder/src/components/design/settings/controls/MultiFieldSelect.svelte b/packages/builder/src/components/design/settings/controls/MultiFieldSelect.svelte index a0ffaad6fa..a2f3dfe24f 100644 --- a/packages/builder/src/components/design/settings/controls/MultiFieldSelect.svelte +++ b/packages/builder/src/components/design/settings/controls/MultiFieldSelect.svelte @@ -3,7 +3,7 @@ import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding" import { selectedScreen } from "stores/builder" import { createEventDispatcher } from "svelte" - import { validators, supported, partialSupport, unsupported } from "../fieldValidator"; + import { validators, constants as validatorConstants } from "../fieldValidator"; export let componentInstance = {} export let value = "" @@ -77,6 +77,7 @@ } const foo = () => { + /* const support = fieldSupport[option]?.support; if (support == null) return null; @@ -84,6 +85,7 @@ if (support === partialSupport) return "AlertCircleFilled" if (support === unsupported) return "AlertCircleFilled" + */ } const getOptionIcon = optionKey => { @@ -115,6 +117,7 @@ } const isOptionEnabled = optionKey => { + return true; // Remain enabled if already selected, so it can be deselected if (value?.includes(optionKey)) return true const support = fieldSupport[optionKey]?.support; diff --git a/packages/builder/src/components/design/settings/fieldValidator.js b/packages/builder/src/components/design/settings/fieldValidator.js index 8a3eb89691..5bbbaae659 100644 --- a/packages/builder/src/components/design/settings/fieldValidator.js +++ b/packages/builder/src/components/design/settings/fieldValidator.js @@ -1,40 +1,64 @@ -export const unsupported = Symbol("values-validator-unsupported") -export const partialSupport = Symbol("values-validator-partial-support") -export const supported = Symbol("values-validator-supported") +export const constants = { + warning: Symbol("values-validator-warning"), + error: Symbol("values-validator-error"), + unsupported: Symbol("values-validator-unsupported"), + partialSupport: Symbol("values-validator-partialSupport"), + supported: Symbol("values-validator-supported") +} export const validators = { chart: (fieldSchema) => { - if ( - fieldSchema.type === "json" || - fieldSchema.type === "array" || - fieldSchema.type === "attachment" || - fieldSchema.type === "barcodeqr" || - fieldSchema.type === "link" || - fieldSchema.type === "bb_reference" - ) { - return { - support: unsupported, - message: `"${fieldSchema.type}" columns cannot be used as a chart value long long long long long long long long long` + try { + const response = { + support: null, + message: null, + warnings: [], + errors: [] } - } - - if (fieldSchema.type === "string") { - return { - support: partialSupport, - message: "This field can be used as a chart value, but non-numeric values will not be parsed correctly" + const generalUnsupportedFields = ["array", "attachment", "barcodeqr", "link", "bb_reference"] + if (generalUnsupportedFields.includes(fieldSchema.type)) { + response.errors.push(`${fieldSchema.type} columns can not be used as chart inputs.`) } - } - if (fieldSchema.type === "number") { - return { - support: supported, - message: "This field can be used for chart values" + if (fieldSchema.type === "json") { + response.errors.push(`JSON columns can not be used as chart inputs, but individual properties of this JSON field can be be used if supported.`) } - } - return { - support: partialSupport, - message: "This field can be used as a chart value, but it may not be parsed correctly" + if (fieldSchema.type === "string") { + response.warnings.push( + "This column can be used as input for a chart, but non-numeric values may cause unexpected behavior.") + } + if (fieldSchema.type === "date") { + response.warnings.push( + "This column can be used as input for a chart, but it is parsed differently for various charts.") + } + + const isRequired = fieldSchema?.constraints?.presence?.allowEmpty === false + if (!isRequired) { + response.warnings.push( + "This column is optional, and some rows may not have a value.") + } + + if (response.errors.length > 0) { + response.support = constants.unsupported + response.message = "This column can not be used as a chart input." + } else if (response.warnings.length > 0) { + response.support = constants.partialSupport + response.message = "This column can be used as a chart input, but certain values may cause issues." + } else { + response.support = constants.supported + response.message = "This column can be used as a chart input." + } + + return response + } catch (e) { + console.log(e) + return { + support: constants.partialSupport, + message: "There was an issue validating this field, it may not be fully supported for use with charts.", + warnings: [], + errors: [] + } } } };