Merge pull request #7879 from Budibase/bug/sev2/is-in-filter-startswith-crash
Is in filter - only call startsWith if string type
This commit is contained in:
commit
bad09dd0cc
|
@ -43,7 +43,7 @@
|
||||||
let helpers = handlebarsCompletions()
|
let helpers = handlebarsCompletions()
|
||||||
let getCaretPosition
|
let getCaretPosition
|
||||||
let search = ""
|
let search = ""
|
||||||
let initialValueJS = value?.startsWith("{{ js ")
|
let initialValueJS = typeof value === "string" && value?.startsWith("{{ js ")
|
||||||
let mode = initialValueJS ? "JavaScript" : "Handlebars"
|
let mode = initialValueJS ? "JavaScript" : "Handlebars"
|
||||||
let jsValue = initialValueJS ? value : null
|
let jsValue = initialValueJS ? value : null
|
||||||
let hbsValue = initialValueJS ? null : value
|
let hbsValue = initialValueJS ? null : value
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
import { createEventDispatcher, onMount } from "svelte"
|
import { createEventDispatcher, onMount } from "svelte"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
const { OperatorOptions } = Constants
|
||||||
|
const { getValidOperatorsForType } = LuceneUtils
|
||||||
|
|
||||||
export let schemaFields
|
export let schemaFields
|
||||||
export let filters = []
|
export let filters = []
|
||||||
|
@ -45,7 +47,7 @@
|
||||||
{
|
{
|
||||||
id: generate(),
|
id: generate(),
|
||||||
field: null,
|
field: null,
|
||||||
operator: Constants.OperatorOptions.Equals.value,
|
operator: OperatorOptions.Equals.value,
|
||||||
value: null,
|
value: null,
|
||||||
valueType: "Value",
|
valueType: "Value",
|
||||||
},
|
},
|
||||||
|
@ -66,49 +68,60 @@
|
||||||
return schemaFields.find(field => field.name === filter.field)
|
return schemaFields.find(field => field.name === filter.field)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onFieldChange = (expression, field) => {
|
const santizeTypes = filter => {
|
||||||
// Update the field types
|
// Update type based on field
|
||||||
expression.type = enrichedSchemaFields.find(x => x.name === field)?.type
|
const fieldSchema = enrichedSchemaFields.find(x => x.name === filter.field)
|
||||||
expression.externalType = getSchema(expression)?.externalType
|
filter.type = fieldSchema?.type
|
||||||
|
|
||||||
// Ensure a valid operator is set
|
// Update external type based on field
|
||||||
const validOperators = LuceneUtils.getValidOperatorsForType(
|
filter.externalType = getSchema(filter)?.externalType
|
||||||
expression.type
|
}
|
||||||
).map(x => x.value)
|
|
||||||
if (!validOperators.includes(expression.operator)) {
|
const santizeOperator = filter => {
|
||||||
expression.operator =
|
// Ensure a valid operator is selected
|
||||||
validOperators[0] ?? Constants.OperatorOptions.Equals.value
|
const operators = getValidOperatorsForType(filter.type).map(x => x.value)
|
||||||
onOperatorChange(expression, expression.operator)
|
if (!operators.includes(filter.operator)) {
|
||||||
|
filter.operator = operators[0] ?? OperatorOptions.Equals.value
|
||||||
}
|
}
|
||||||
|
|
||||||
// if changed to an array, change default value to empty array
|
// Update the noValue flag if the operator does not take a value
|
||||||
const idx = filters.findIndex(x => x.id === expression.id)
|
const noValueOptions = [
|
||||||
if (expression.type === "array") {
|
OperatorOptions.Empty.value,
|
||||||
filters[idx].value = []
|
OperatorOptions.NotEmpty.value,
|
||||||
} else {
|
]
|
||||||
filters[idx].value = null
|
filter.noValue = noValueOptions.includes(filter.operator)
|
||||||
|
}
|
||||||
|
|
||||||
|
const santizeValue = filter => {
|
||||||
|
// Check if the operator allows a value at all
|
||||||
|
if (filter.noValue) {
|
||||||
|
filter.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure array values are properly set and cleared
|
||||||
|
if (Array.isArray(filter.value)) {
|
||||||
|
if (filter.valueType !== "Value" || filter.type !== "array") {
|
||||||
|
filter.value = null
|
||||||
|
}
|
||||||
|
} else if (filter.type === "array" && filter.valueType === "Value") {
|
||||||
|
filter.value = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onOperatorChange = (expression, operator) => {
|
const onFieldChange = filter => {
|
||||||
const noValueOptions = [
|
santizeTypes(filter)
|
||||||
Constants.OperatorOptions.Empty.value,
|
santizeOperator(filter)
|
||||||
Constants.OperatorOptions.NotEmpty.value,
|
santizeValue(filter)
|
||||||
]
|
}
|
||||||
expression.noValue = noValueOptions.includes(operator)
|
|
||||||
if (expression.noValue) {
|
const onOperatorChange = filter => {
|
||||||
expression.value = null
|
santizeOperator(filter)
|
||||||
}
|
santizeValue(filter)
|
||||||
if (
|
}
|
||||||
operator === Constants.OperatorOptions.In.value &&
|
|
||||||
!Array.isArray(expression.value)
|
const onValueTypeChange = filter => {
|
||||||
) {
|
santizeValue(filter)
|
||||||
if (expression.value) {
|
|
||||||
expression.value = [expression.value]
|
|
||||||
} else {
|
|
||||||
expression.value = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFieldOptions = field => {
|
const getFieldOptions = field => {
|
||||||
|
@ -153,23 +166,24 @@
|
||||||
<Select
|
<Select
|
||||||
bind:value={filter.field}
|
bind:value={filter.field}
|
||||||
options={fieldOptions}
|
options={fieldOptions}
|
||||||
on:change={e => onFieldChange(filter, e.detail)}
|
on:change={() => onFieldChange(filter)}
|
||||||
placeholder="Column"
|
placeholder="Column"
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
disabled={!filter.field}
|
disabled={!filter.field}
|
||||||
options={LuceneUtils.getValidOperatorsForType(filter.type)}
|
options={getValidOperatorsForType(filter.type)}
|
||||||
bind:value={filter.operator}
|
bind:value={filter.operator}
|
||||||
on:change={e => onOperatorChange(filter, e.detail)}
|
on:change={() => onOperatorChange(filter)}
|
||||||
placeholder={null}
|
placeholder={null}
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
disabled={filter.noValue || !filter.field}
|
disabled={filter.noValue || !filter.field}
|
||||||
options={valueTypeOptions}
|
options={valueTypeOptions}
|
||||||
bind:value={filter.valueType}
|
bind:value={filter.valueType}
|
||||||
|
on:change={() => onValueTypeChange(filter)}
|
||||||
placeholder={null}
|
placeholder={null}
|
||||||
/>
|
/>
|
||||||
{#if filter.valueType === "Binding"}
|
{#if filter.field && filter.valueType === "Binding"}
|
||||||
<DrawerBindableInput
|
<DrawerBindableInput
|
||||||
disabled={filter.noValue}
|
disabled={filter.noValue}
|
||||||
title={`Value for "${filter.field}"`}
|
title={`Value for "${filter.field}"`}
|
||||||
|
@ -250,7 +264,7 @@
|
||||||
column-gap: var(--spacing-l);
|
column-gap: var(--spacing-l);
|
||||||
row-gap: var(--spacing-s);
|
row-gap: var(--spacing-s);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
grid-template-columns: 1fr 120px 120px 1fr auto auto;
|
grid-template-columns: 1fr 150px 120px 1fr 16px 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.filter-label {
|
.filter-label {
|
||||||
|
|
|
@ -40,7 +40,7 @@ export const OperatorOptions = {
|
||||||
},
|
},
|
||||||
NotContains: {
|
NotContains: {
|
||||||
value: "notContains",
|
value: "notContains",
|
||||||
label: "Does Not Contain",
|
label: "Does not contain",
|
||||||
},
|
},
|
||||||
In: {
|
In: {
|
||||||
value: "oneOf",
|
value: "oneOf",
|
||||||
|
|
Loading…
Reference in New Issue