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