1
0
Fork 0
mirror of synced 2024-08-01 03:11:26 +12:00

Handle formulas for getValidOperatorsForType

This commit is contained in:
Adria Navarro 2024-04-11 11:37:59 +02:00
parent 63dd0b5d65
commit a4a095b6a1

View file

@ -2,6 +2,7 @@ import {
Datasource, Datasource,
FieldSubtype, FieldSubtype,
FieldType, FieldType,
FormulaType,
SearchFilter, SearchFilter,
SearchQuery, SearchQuery,
SearchQueryFields, SearchQueryFields,
@ -19,7 +20,11 @@ const HBS_REGEX = /{{([^{].*?)}}/g
* Returns the valid operator options for a certain data type * Returns the valid operator options for a certain data type
*/ */
export const getValidOperatorsForType = ( export const getValidOperatorsForType = (
fieldType: { type: FieldType; subtype?: FieldSubtype }, fieldType: {
type: FieldType
subtype?: FieldSubtype
formulaType?: FormulaType
},
field: string, field: string,
datasource: Datasource & { tableId: any } datasource: Datasource & { tableId: any }
) => { ) => {
@ -46,7 +51,7 @@ export const getValidOperatorsForType = (
value: string value: string
label: string label: string
}[] = [] }[] = []
const { type, subtype } = fieldType const { type, subtype, formulaType } = fieldType
if (type === FieldType.STRING) { if (type === FieldType.STRING) {
ops = stringOps ops = stringOps
} else if (type === FieldType.NUMBER || type === FieldType.BIGINT) { } else if (type === FieldType.NUMBER || type === FieldType.BIGINT) {
@ -61,7 +66,7 @@ export const getValidOperatorsForType = (
ops = stringOps ops = stringOps
} else if (type === FieldType.DATETIME) { } else if (type === FieldType.DATETIME) {
ops = numOps ops = numOps
} else if (type === FieldType.FORMULA) { } else if (type === FieldType.FORMULA && formulaType === FormulaType.STATIC) {
ops = stringOps.concat([Op.MoreThan, Op.LessThan]) ops = stringOps.concat([Op.MoreThan, Op.LessThan])
} else if (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USER) { } else if (type === FieldType.BB_REFERENCE && subtype == FieldSubtype.USER) {
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In] ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]