Merge pull request #11965 from Budibase/fix/clean-multiple-users-filter-checks
Simplify code around multiple user dataprovider filters
This commit is contained in:
commit
3532d1a045
|
@ -3,19 +3,19 @@
|
||||||
Body,
|
Body,
|
||||||
Button,
|
Button,
|
||||||
Combobox,
|
Combobox,
|
||||||
Multiselect,
|
|
||||||
DatePicker,
|
DatePicker,
|
||||||
DrawerContent,
|
DrawerContent,
|
||||||
Icon,
|
Icon,
|
||||||
Input,
|
Input,
|
||||||
Layout,
|
|
||||||
Select,
|
|
||||||
Label,
|
Label,
|
||||||
|
Layout,
|
||||||
|
Multiselect,
|
||||||
|
Select,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
|
||||||
import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte"
|
import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
import { LuceneUtils, Constants } from "@budibase/frontend-core"
|
import { Constants, LuceneUtils } from "@budibase/frontend-core"
|
||||||
import { getFields } from "helpers/searchFields"
|
import { getFields } from "helpers/searchFields"
|
||||||
import { FieldType } from "@budibase/types"
|
import { FieldType } from "@budibase/types"
|
||||||
import { createEventDispatcher, onMount } from "svelte"
|
import { createEventDispatcher, onMount } from "svelte"
|
||||||
|
@ -122,7 +122,7 @@
|
||||||
return enrichedSchemaFields.find(field => field.name === filter.field)
|
return enrichedSchemaFields.find(field => field.name === filter.field)
|
||||||
}
|
}
|
||||||
|
|
||||||
const santizeTypes = filter => {
|
const sanitizeTypes = filter => {
|
||||||
// Update type based on field
|
// Update type based on field
|
||||||
const fieldSchema = enrichedSchemaFields.find(x => x.name === filter.field)
|
const fieldSchema = enrichedSchemaFields.find(x => x.name === filter.field)
|
||||||
filter.type = fieldSchema?.type
|
filter.type = fieldSchema?.type
|
||||||
|
@ -131,7 +131,7 @@
|
||||||
filter.externalType = getSchema(filter)?.externalType
|
filter.externalType = getSchema(filter)?.externalType
|
||||||
}
|
}
|
||||||
|
|
||||||
const santizeOperator = filter => {
|
const sanitizeOperator = filter => {
|
||||||
// Ensure a valid operator is selected
|
// Ensure a valid operator is selected
|
||||||
const operators = getValidOperatorsForType(filter).map(x => x.value)
|
const operators = getValidOperatorsForType(filter).map(x => x.value)
|
||||||
if (!operators.includes(filter.operator)) {
|
if (!operators.includes(filter.operator)) {
|
||||||
|
@ -146,7 +146,7 @@
|
||||||
filter.noValue = noValueOptions.includes(filter.operator)
|
filter.noValue = noValueOptions.includes(filter.operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
const santizeValue = (filter, previousType) => {
|
const sanitizeValue = (filter, previousType) => {
|
||||||
// Check if the operator allows a value at all
|
// Check if the operator allows a value at all
|
||||||
if (filter.noValue) {
|
if (filter.noValue) {
|
||||||
filter.value = null
|
filter.value = null
|
||||||
|
@ -171,18 +171,18 @@
|
||||||
|
|
||||||
const onFieldChange = filter => {
|
const onFieldChange = filter => {
|
||||||
const previousType = filter.type
|
const previousType = filter.type
|
||||||
santizeTypes(filter)
|
sanitizeTypes(filter)
|
||||||
santizeOperator(filter)
|
sanitizeOperator(filter)
|
||||||
santizeValue(filter, previousType)
|
sanitizeValue(filter, previousType)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onOperatorChange = filter => {
|
const onOperatorChange = filter => {
|
||||||
santizeOperator(filter)
|
sanitizeOperator(filter)
|
||||||
santizeValue(filter)
|
sanitizeValue(filter, filter.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
const onValueTypeChange = filter => {
|
const onValueTypeChange = filter => {
|
||||||
santizeValue(filter)
|
sanitizeValue(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFieldOptions = field => {
|
const getFieldOptions = field => {
|
||||||
|
@ -195,25 +195,11 @@
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
let type = filter.type
|
return LuceneUtils.getValidOperatorsForType(
|
||||||
if (type === FieldType.BB_REFERENCE) {
|
filter.type,
|
||||||
const fieldSchema = getSchema(filter)
|
|
||||||
if (fieldSchema) {
|
|
||||||
type = {
|
|
||||||
type: fieldSchema.type,
|
|
||||||
multiple:
|
|
||||||
fieldSchema.relationshipType === RelationshipType.MANY_TO_MANY,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const operators = LuceneUtils.getValidOperatorsForType(
|
|
||||||
type,
|
|
||||||
filter.field,
|
filter.field,
|
||||||
datasource
|
datasource
|
||||||
)
|
)
|
||||||
|
|
||||||
return operators
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -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,13 +60,8 @@ 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) {
|
ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In]
|
||||||
// Temporally disabled
|
|
||||||
ops = []
|
|
||||||
} else {
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in New Issue