Sanitise field

This commit is contained in:
Adria Navarro 2023-10-03 17:35:36 +02:00
parent 83790bc324
commit 0da029c896
1 changed files with 21 additions and 11 deletions

View File

@ -146,7 +146,7 @@
filter.noValue = noValueOptions.includes(filter.operator)
}
const santizeValue = filter => {
const santizeValue = (filter, previousType) => {
// Check if the operator allows a value at all
if (filter.noValue) {
filter.value = null
@ -160,13 +160,20 @@
}
} else if (filter.type === "array" && filter.valueType === "Value") {
filter.value = []
} else if (
previousType !== filter.type &&
previousType === FieldType.BB_REFERENCE &&
filter.type === FieldType.BB_REFERENCE
) {
filter.value = filter.type === "array" ? [] : null
}
}
const onFieldChange = filter => {
const previousType = filter.type
santizeTypes(filter)
santizeOperator(filter)
santizeValue(filter)
santizeValue(filter, previousType)
}
const onOperatorChange = filter => {
@ -185,18 +192,21 @@
const getValidOperatorsForType = filter => {
const fieldSchema = getSchema(filter)
if (!fieldSchema) {
if (!filter) {
return []
}
const type =
fieldSchema.type !== FieldType.BB_REFERENCE
? field.type
: {
let type = filter.type
if (type === FieldType.BB_REFERENCE) {
const fieldSchema = getSchema(filter)
if (fieldSchema) {
type = {
type: fieldSchema.type,
multiple:
fieldSchema.relationshipType === RelationshipType.MANY_TO_MANY,
}
}
}
const operators = LuceneUtils.getValidOperatorsForType(
type,