Type branch filters
This commit is contained in:
parent
d2da61e4e1
commit
7aad0d6e92
|
@ -23,9 +23,10 @@ import {
|
|||
AutomationStatus,
|
||||
AutomationStep,
|
||||
AutomationStepStatus,
|
||||
BranchSearchFilters,
|
||||
BranchStep,
|
||||
LogicalOperator,
|
||||
LoopStep,
|
||||
SearchFilters,
|
||||
UserBindings,
|
||||
} from "@budibase/types"
|
||||
import { AutomationContext, TriggerOutput } from "../definitions/automations"
|
||||
|
@ -546,12 +547,31 @@ class Orchestrator {
|
|||
)
|
||||
}
|
||||
|
||||
private recurseSearchFilters(
|
||||
filters: BranchSearchFilters,
|
||||
processFn: (filter: BranchSearchFilters) => BranchSearchFilters
|
||||
): BranchSearchFilters {
|
||||
// Process the current level
|
||||
filters = processFn(filters)
|
||||
|
||||
// Recurse through logical operators
|
||||
for (const logical of Object.values(LogicalOperator)) {
|
||||
if (filters[logical]) {
|
||||
filters[logical]!.conditions = filters[logical]!.conditions.map(
|
||||
condition => this.recurseSearchFilters(condition, processFn)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return filters
|
||||
}
|
||||
|
||||
private async evaluateBranchCondition(
|
||||
conditions: SearchFilters
|
||||
conditions: BranchSearchFilters
|
||||
): Promise<boolean> {
|
||||
const toFilter: Record<string, any> = {}
|
||||
|
||||
const processedConditions = dataFilters.recurseSearchFilters(
|
||||
const processedConditions = this.recurseSearchFilters(
|
||||
conditions,
|
||||
filter => {
|
||||
Object.entries(filter).forEach(([_, value]) => {
|
||||
|
|
|
@ -142,25 +142,6 @@ export function recurseLogicalOperators(
|
|||
return filters
|
||||
}
|
||||
|
||||
export function recurseSearchFilters(
|
||||
filters: SearchFilters,
|
||||
processFn: (filter: SearchFilters) => SearchFilters
|
||||
): SearchFilters {
|
||||
// Process the current level
|
||||
filters = processFn(filters)
|
||||
|
||||
// Recurse through logical operators
|
||||
for (const logical of LOGICAL_OPERATORS) {
|
||||
if (filters[logical]) {
|
||||
filters[logical]!.conditions = filters[logical]!.conditions.map(
|
||||
condition => recurseSearchFilters(condition, processFn)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return filters
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any fields that contain empty strings that would cause inconsistent
|
||||
* behaviour with how backend tables are filtered (no value means no filter).
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import { SortOrder } from "../../../api"
|
||||
import { SearchFilters, EmptyFilterOption } from "../../../sdk"
|
||||
import {
|
||||
SearchFilters,
|
||||
EmptyFilterOption,
|
||||
BasicOperator,
|
||||
LogicalOperator,
|
||||
} from "../../../sdk"
|
||||
import { HttpMethod } from "../query"
|
||||
import { Row } from "../row"
|
||||
import { LoopStepType, EmailAttachment, AutomationResults } from "./automation"
|
||||
|
@ -118,9 +123,17 @@ export type BranchStepInputs = {
|
|||
export type Branch = {
|
||||
id: any
|
||||
name: string
|
||||
condition: SearchFilters
|
||||
condition: BranchSearchFilters
|
||||
}
|
||||
|
||||
export type BranchSearchFilters = Pick<
|
||||
SearchFilters,
|
||||
| BasicOperator.EQUAL
|
||||
| BasicOperator.NOT_EQUAL
|
||||
| LogicalOperator.AND
|
||||
| LogicalOperator.OR
|
||||
>
|
||||
|
||||
export type MakeIntegrationInputs = {
|
||||
url: string
|
||||
body: any
|
||||
|
|
Loading…
Reference in New Issue