wip
This commit is contained in:
parent
6bedafbdb1
commit
e08d745360
4 changed files with 84 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import ExplanationModal from './ExplanationModal/index.svelte'
|
import ExplanationModal from './ExplanationModal/index.svelte'
|
||||||
import { warnings, errors } from "../../fieldValidator";
|
import { warnings, errors } from "./validator";
|
||||||
import { Column, Support, NotRequired, StringNumber } from "./lines"
|
import { Column, Support, NotRequired, StringNumber } from "./lines"
|
||||||
import subjects from './subjects';
|
import subjects from './subjects';
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,82 @@
|
||||||
|
import { capitalize } from 'lodash';
|
||||||
|
|
||||||
|
export const errors = {
|
||||||
|
general: Symbol("values-validator-general"),
|
||||||
|
jsonPrimitivesOnly: Symbol("values-validator-json-primitives-only"),
|
||||||
|
}
|
||||||
|
|
||||||
|
export const warnings = {
|
||||||
|
stringAsNumber: Symbol("values-validator-string-as-number"),
|
||||||
|
chartDatetime: Symbol("values-validator-chart-datetime"),
|
||||||
|
notRequired: Symbol("values-validator-not-required"),
|
||||||
|
}
|
||||||
|
|
||||||
|
export const constants = {
|
||||||
|
unsupported: Symbol("values-validator-unsupported"),
|
||||||
|
partialSupport: Symbol("values-validator-partialSupport"),
|
||||||
|
supported: Symbol("values-validator-supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
export const validators = {
|
||||||
|
chart: (fieldSchema) => {
|
||||||
|
try {
|
||||||
|
const response = {
|
||||||
|
level: null,
|
||||||
|
warnings: [],
|
||||||
|
errors: [],
|
||||||
|
text: "",
|
||||||
|
icon: "",
|
||||||
|
iconColor: ""
|
||||||
|
}
|
||||||
|
const generalUnsupportedFields = ["array", "attachment", "barcodeqr", "link", "bb_reference"]
|
||||||
|
if (generalUnsupportedFields.includes(fieldSchema.type)) {
|
||||||
|
response.errors.push(errors.general)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldSchema.type === "json") {
|
||||||
|
response.errors.push(errors.jsonPrimitivesOnly)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fieldSchema.type === "string") {
|
||||||
|
response.warnings.push(warnings.stringAsNumber)
|
||||||
|
}
|
||||||
|
if (fieldSchema.type === "datetime") {
|
||||||
|
response.warnings.push(warnings.chartDatetime);
|
||||||
|
//"This column can be used as an input for a chart, but it may be parsed differently depending on which is used.
|
||||||
|
}
|
||||||
|
|
||||||
|
const isRequired = fieldSchema?.constraints?.presence?.allowEmpty === false
|
||||||
|
if (!isRequired) {
|
||||||
|
response.warnings.push(warnings.notRequired);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.errors.length > 0) {
|
||||||
|
response.level = constants.unsupported
|
||||||
|
response.text = "Not compatible"
|
||||||
|
response.icon = "Alert"
|
||||||
|
response.iconColor = "var(--red)"
|
||||||
|
} else if (response.warnings.length > 0) {
|
||||||
|
response.level = constants.partialSupport
|
||||||
|
response.text = "Partially compatible"
|
||||||
|
response.icon = "AlertCheck"
|
||||||
|
response.iconColor = "var(--yellow)"
|
||||||
|
} else {
|
||||||
|
response.level = constants.supported
|
||||||
|
response.text = "Compatible"
|
||||||
|
response.icon = "CheckmarkCircle"
|
||||||
|
response.iconColor = "var(--green)"
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
|
} catch (e) {
|
||||||
|
return {
|
||||||
|
level: constants.partialSupport,
|
||||||
|
warnings: [],
|
||||||
|
errors: [],
|
||||||
|
text: "Partially compatible",
|
||||||
|
icon: "AlertCheck",
|
||||||
|
iconColor: "var(--yellow)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -3,7 +3,7 @@
|
||||||
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
|
import { getDatasourceForProvider, getSchemaForDatasource } from "dataBinding"
|
||||||
import { selectedScreen } from "stores/builder"
|
import { selectedScreen } from "stores/builder"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import { validators, constants as validatorConstants } from "../fieldValidator";
|
import { validators } from "./FieldContext/Validator";
|
||||||
import ChartFieldContext from './FieldContext/Chart.svelte'
|
import ChartFieldContext from './FieldContext/Chart.svelte'
|
||||||
import { FIELDS } from 'constants/backend'
|
import { FIELDS } from 'constants/backend'
|
||||||
import { goto, params } from "@roxi/routify"
|
import { goto, params } from "@roxi/routify"
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { capitalize } from 'lodash';
|
import { capitalize } from 'lodash';
|
||||||
|
|
||||||
export const errors = {
|
export const errors = {
|
||||||
// fail without explanation
|
|
||||||
general: Symbol("values-validator-general"),
|
general: Symbol("values-validator-general"),
|
||||||
jsonPrimitivesOnly: Symbol("values-validator-json-primitives-only"),
|
jsonPrimitivesOnly: Symbol("values-validator-json-primitives-only"),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue