Allow filtering
This commit is contained in:
parent
ee11ebf8e4
commit
39b5a2b539
|
@ -126,6 +126,7 @@
|
|||
// Update type based on field
|
||||
const fieldSchema = enrichedSchemaFields.find(x => x.name === filter.field)
|
||||
filter.type = fieldSchema?.type
|
||||
filter.subtype = fieldSchema?.subtype
|
||||
|
||||
// Update external type based on field
|
||||
filter.externalType = getSchema(filter)?.externalType
|
||||
|
@ -196,7 +197,7 @@
|
|||
}
|
||||
|
||||
return LuceneUtils.getValidOperatorsForType(
|
||||
filter.type,
|
||||
{ type: filter.type, subtype: filter.subtype },
|
||||
filter.field,
|
||||
datasource
|
||||
)
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
}
|
||||
|
||||
const getOperatorOptions = condition => {
|
||||
return LuceneUtils.getValidOperatorsForType(condition.valueType)
|
||||
return LuceneUtils.getValidOperatorsForType({ type: condition.valueType })
|
||||
}
|
||||
|
||||
const onOperatorChange = (condition, newOperator) => {
|
||||
|
@ -137,9 +137,9 @@
|
|||
condition.referenceValue = null
|
||||
|
||||
// Ensure a valid operator is set
|
||||
const validOperators = LuceneUtils.getValidOperatorsForType(newType).map(
|
||||
x => x.value
|
||||
)
|
||||
const validOperators = LuceneUtils.getValidOperatorsForType({
|
||||
type: newType,
|
||||
}).map(x => x.value)
|
||||
if (!validOperators.includes(condition.operator)) {
|
||||
condition.operator =
|
||||
validOperators[0] ?? Constants.OperatorOptions.Equals.value
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
|
||||
// Ensure a valid operator is set
|
||||
const validOperators = LuceneUtils.getValidOperatorsForType(
|
||||
expression.type,
|
||||
{ type: expression.type },
|
||||
expression.field,
|
||||
datasource
|
||||
).map(x => x.value)
|
||||
|
@ -125,7 +125,7 @@
|
|||
<Select
|
||||
disabled={!filter.field}
|
||||
options={LuceneUtils.getValidOperatorsForType(
|
||||
filter.type,
|
||||
{ type: filter.type, subtype: filter.subtype },
|
||||
filter.field,
|
||||
datasource
|
||||
)}
|
||||
|
|
|
@ -6,6 +6,7 @@ import {
|
|||
SearchFilter,
|
||||
SearchQuery,
|
||||
SearchQueryFields,
|
||||
FieldSubtype,
|
||||
} from "@budibase/types"
|
||||
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
|
||||
import { deepGet } from "./helpers"
|
||||
|
@ -17,7 +18,7 @@ const HBS_REGEX = /{{([^{].*?)}}/g
|
|||
* @param type the data type
|
||||
*/
|
||||
export const getValidOperatorsForType = (
|
||||
type: FieldType,
|
||||
fieldType: { type: FieldType; subtype?: FieldSubtype },
|
||||
field: string,
|
||||
datasource: Datasource & { tableId: any } // TODO: is this table id ever populated?
|
||||
) => {
|
||||
|
@ -44,6 +45,7 @@ export const getValidOperatorsForType = (
|
|||
value: string
|
||||
label: string
|
||||
}[] = []
|
||||
const { type, subtype } = fieldType
|
||||
if (type === FieldType.STRING) {
|
||||
ops = stringOps
|
||||
} else if (type === FieldType.NUMBER || type === FieldType.BIGINT) {
|
||||
|
@ -60,8 +62,10 @@ export const getValidOperatorsForType = (
|
|||
ops = numOps
|
||||
} else if (type === FieldType.FORMULA) {
|
||||
ops = stringOps.concat([Op.MoreThan, Op.LessThan])
|
||||
} else if (type === FieldType.BB_REFERENCE) {
|
||||
} else if (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USER) {
|
||||
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
||||
} else if (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USERS) {
|
||||
ops = [Op.Contains, Op.NotContains, Op.ContainsAny, Op.Empty, Op.NotEmpty]
|
||||
}
|
||||
|
||||
// Only allow equal/not equal for _id in SQL tables
|
||||
|
|
Loading…
Reference in New Issue