wip
This commit is contained in:
parent
96001dd409
commit
8eb60968d5
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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: []
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue