Process middleware fixes (#10687)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2026-03-26 10:38:34 +07:00
committed by GitHub
parent 7bdf8170a7
commit b932bfd6bf
2 changed files with 37 additions and 12 deletions
+2 -1
View File
@@ -120,13 +120,14 @@ export class ProcessMiddleware extends BasePresentationMiddleware implements Pre
},
{ sort: { rank: SortingOrder.Ascending } }
)
if (transitions.length === 0) continue
const inputContext = {
...execution.context,
card: updated,
operations: isUpdateTx(updateTx) ? updateTx.operations : updateTx.attributes
}
const transition = await pickTransition(this.client, execution, transitions, inputContext)
if (transition === undefined) return
if (transition === undefined) continue
const result = await getNextStateUserInput(execution, transition, execution.context, inputContext)
if (result?.changed === true) {
preTx.push(
+35 -11
View File
@@ -463,11 +463,12 @@ export async function requestUserInput (
target: Transition,
execution: Execution,
userContext: ExecutionContext,
inputContext: Record<string, any> = {}
inputContext: Record<string, any> = {},
skipExisting: boolean = false
): Promise<{ context: ExecutionContext, state: Ref<State>, changed: boolean }> {
const client = getClient()
let changed = false
const tr = await getTransitionUserInput(processId, space, target, userContext)
const tr = await getTransitionUserInput(processId, space, target, userContext, skipExisting)
if (tr !== undefined) {
userContext = { ...userContext, ...tr }
changed = true
@@ -485,7 +486,9 @@ export async function requestUserInput (
process: processId,
from: target.to
})
.filter((t) => client.getModel().findObject(t.trigger)?.auto === true)
.filter(
(t) => client.getModel().findObject(t.trigger)?.auto === true && t.trigger !== process.trigger.OnSubProcessesDone
)
if (nextAutoTransitions.length > 0) {
const newExecution = {
@@ -518,7 +521,8 @@ export async function getTransitionUserInput (
processId: Ref<Process>,
space: Ref<Space>,
transition: Transition,
userContext: ExecutionContext
userContext: ExecutionContext,
skipExisting: boolean = false
): Promise<ExecutionContext | undefined> {
let changed = false
for (const action of transition.actions) {
@@ -526,9 +530,20 @@ export async function getTransitionUserInput (
const inputs: SelectedUserRequest[] = []
for (const key in action.params) {
const value = (action.params as any)[key]
const context = parseContext(value)
if (context !== undefined && context.type === 'userRequest') {
inputs.push(context)
if (typeof value === 'string') {
const context = parseContext(value)
if (context !== undefined && context.type === 'userRequest') {
if (skipExisting && userContext[context.id] !== undefined) continue
inputs.push(context)
}
} else if (typeof value === 'object' && !Array.isArray(value)) {
for (const element of Object.values(value)) {
const context = parseContext(element)
if (context !== undefined && context.type === 'userRequest') {
if (skipExisting && userContext[context.id] !== undefined) continue
inputs.push(context)
}
}
}
}
if (inputs.length > 0) {
@@ -576,7 +591,14 @@ export async function getSubProcessesUserInput (
if (action.methodId !== process.method.RunSubProcess) continue
const processId = action.params._id as Ref<Process>
if (processId === undefined) continue
const context: ExecutionContext = action.params.context ?? getEmptyContext()
const context: ExecutionContext = JSON.parse(JSON.stringify(action.params.context ?? getEmptyContext()))
for (const [k, v] of Object.entries(context)) {
const c = parseContext(v)
if (c !== undefined && c.type === 'userRequest') {
if (userContext[c.id] !== undefined) continue
;(context as any)[k] = userContext[c.id]
}
}
const initTransition = getClient().getModel().findAllSync(process.class.Transition, {
process: processId,
from: null
@@ -597,9 +619,10 @@ export async function getSubProcessesUserInput (
modifiedOn: 0,
modifiedBy: client.user
}
const res = await newExecutionUserInput(processId, space, mockExecution)
const res = await newExecutionUserInput(processId, space, mockExecution, true)
if (action.context == null || res === undefined) continue
userContext[action.context._id] = res
userContext = { ...userContext, ...res.context }
changed = true
}
return changed ? userContext : undefined
@@ -608,7 +631,8 @@ export async function getSubProcessesUserInput (
export async function newExecutionUserInput (
_id: Ref<Process>,
space: Ref<Space>,
execution: Execution
execution: Execution,
skipExisting: boolean = false
): Promise<{ context: ExecutionContext, state: Ref<State>, changed: boolean } | undefined> {
const client = getClient()
const initTransition = client.getModel().findAllSync(process.class.Transition, {
@@ -616,7 +640,7 @@ export async function newExecutionUserInput (
from: null
})[0]
if (initTransition === undefined) return undefined
return await requestUserInput(_id, space, initTransition, execution, execution.context)
return await requestUserInput(_id, space, initTransition, execution, execution.context, {}, skipExisting)
}
export async function getNextStateUserInput (