Smarter getValidOperatorsForType
This commit is contained in:
parent
b2429e1fe0
commit
c84d2449f2
|
@ -184,26 +184,22 @@
|
|||
}
|
||||
|
||||
const getValidOperatorsForType = filter => {
|
||||
const fieldSchema = getSchema(filter)
|
||||
const type =
|
||||
fieldSchema.type !== FieldType.BB_REFERENCE
|
||||
? field.type
|
||||
: {
|
||||
type: fieldSchema.type,
|
||||
multiple:
|
||||
fieldSchema.relationshipType === RelationshipType.MANY_TO_MANY,
|
||||
}
|
||||
|
||||
let operators = LuceneUtils.getValidOperatorsForType(
|
||||
filter.type,
|
||||
type,
|
||||
filter.field,
|
||||
datasource
|
||||
)
|
||||
|
||||
const fieldSchema = getSchema(filter)
|
||||
if (
|
||||
fieldSchema.type === FieldType.BB_REFERENCE &&
|
||||
fieldSchema.relationshipType !== RelationshipType.MANY_TO_MANY
|
||||
) {
|
||||
operators = operators.filter(
|
||||
o =>
|
||||
![
|
||||
OperatorOptions.Contains.value,
|
||||
OperatorOptions.NotContains.value,
|
||||
].includes(o.value)
|
||||
)
|
||||
}
|
||||
|
||||
return operators
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -12,12 +12,22 @@ import { deepGet } from "./helpers"
|
|||
|
||||
const HBS_REGEX = /{{([^{].*?)}}/g
|
||||
|
||||
type RequestedFieldType =
|
||||
| Exclude<FieldType, FieldType.BB_REFERENCE>
|
||||
| { type: FieldType.BB_REFERENCE; multiple: boolean }
|
||||
|
||||
export function isFieldType(
|
||||
r: RequestedFieldType
|
||||
): r is Exclude<FieldType, FieldType.BB_REFERENCE> {
|
||||
return typeof r === "string" && Object.values(FieldType).includes(r)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the valid operator options for a certain data type
|
||||
* @param type the data type
|
||||
*/
|
||||
export const getValidOperatorsForType = (
|
||||
type: FieldType,
|
||||
type: RequestedFieldType,
|
||||
field: string,
|
||||
datasource: Datasource & { tableId: any } // TODO: is this table id ever populated?
|
||||
) => {
|
||||
|
@ -60,16 +70,12 @@ export const getValidOperatorsForType = (
|
|||
ops = numOps
|
||||
} else if (type === FieldType.FORMULA) {
|
||||
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
|
||||
} else if (type === FieldType.BB_REFERENCE) {
|
||||
ops = [
|
||||
Op.Equals,
|
||||
Op.NotEquals,
|
||||
Op.Empty,
|
||||
Op.NotEmpty,
|
||||
Op.Contains,
|
||||
Op.NotContains,
|
||||
Op.ContainsAny,
|
||||
]
|
||||
} else if (!isFieldType(type) && type.type === FieldType.BB_REFERENCE) {
|
||||
if (type.multiple) {
|
||||
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
||||
} else {
|
||||
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.ContainsAny]
|
||||
}
|
||||
}
|
||||
|
||||
// Only allow equal/not equal for _id in SQL tables
|
||||
|
|
Loading…
Reference in New Issue