Clean multiple user checks to simplify

This commit is contained in:
Adria Navarro 2023-10-03 18:29:35 +02:00
parent 07dd0bc1ae
commit 02bfaa4378
2 changed files with 4 additions and 31 deletions

View File

@ -195,20 +195,8 @@
return [] return []
} }
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( const operators = LuceneUtils.getValidOperatorsForType(
type, filter.type,
filter.field, filter.field,
datasource datasource
) )

View File

@ -12,22 +12,12 @@ import { deepGet } from "./helpers"
const HBS_REGEX = /{{([^{].*?)}}/g 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 * Returns the valid operator options for a certain data type
* @param type the data type * @param type the data type
*/ */
export const getValidOperatorsForType = ( export const getValidOperatorsForType = (
type: RequestedFieldType, type: FieldType,
field: string, field: string,
datasource: Datasource & { tableId: any } // TODO: is this table id ever populated? datasource: Datasource & { tableId: any } // TODO: is this table id ever populated?
) => { ) => {
@ -70,14 +60,9 @@ export const getValidOperatorsForType = (
ops = numOps ops = numOps
} else if (type === FieldType.FORMULA) { } else if (type === FieldType.FORMULA) {
ops = stringOps.concat([Op.MoreThan, Op.LessThan]) ops = stringOps.concat([Op.MoreThan, Op.LessThan])
} else if (!isFieldType(type) && type.type === FieldType.BB_REFERENCE) { } else if (type === FieldType.BB_REFERENCE) {
if (type.multiple) {
// Temporally disabled
ops = []
} else {
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In] ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
} }
}
// Only allow equal/not equal for _id in SQL tables // Only allow equal/not equal for _id in SQL tables
const externalTable = datasource?.tableId?.includes("datasource_plus") const externalTable = datasource?.tableId?.includes("datasource_plus")