mirror of
https://github.com/hcengineering/platform.git
synced 2026-08-17 18:05:42 +02:00
Fix subprocess params (#9805)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
@@ -473,6 +473,11 @@ export async function getTransitionUserInput (
|
||||
return changed ? userContext : undefined
|
||||
}
|
||||
|
||||
function getEmptyContext (): ExecutionContext {
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
return {} as ExecutionContext
|
||||
}
|
||||
|
||||
export async function getSubProcessesUserInput (
|
||||
transition: Transition,
|
||||
userContext: ExecutionContext
|
||||
@@ -482,7 +487,8 @@ export async function getSubProcessesUserInput (
|
||||
if (action.methodId !== process.method.RunSubProcess) continue
|
||||
const processId = action.params._id as Ref<Process>
|
||||
if (processId === undefined) continue
|
||||
const res = await newExecutionUserInput(processId)
|
||||
const context = action.params.context ?? getEmptyContext()
|
||||
const res = await newExecutionUserInput(processId, context)
|
||||
if (action.context == null || res === undefined) continue
|
||||
userContext[action.context._id] = res
|
||||
changed = true
|
||||
@@ -500,9 +506,7 @@ export async function newExecutionUserInput (
|
||||
from: null
|
||||
})[0]
|
||||
if (initTransition === undefined) return userContext
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const emptyContext: ExecutionContext = {} as ExecutionContext
|
||||
return await requestUserInput(_id, initTransition, userContext ?? emptyContext)
|
||||
return await requestUserInput(_id, initTransition, userContext ?? getEmptyContext())
|
||||
}
|
||||
|
||||
export async function getNextStateUserInput (
|
||||
@@ -527,14 +531,12 @@ export async function createExecution (card: Ref<Card>, _id: Ref<Process>, space
|
||||
from: null
|
||||
})[0]
|
||||
if (initTransition === undefined) return
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const emptyContext: ExecutionContext = {} as ExecutionContext
|
||||
await client.createDoc(process.class.Execution, space, {
|
||||
process: _id,
|
||||
currentState: initTransition.to,
|
||||
card,
|
||||
rollback: [],
|
||||
context: context ?? emptyContext,
|
||||
context: context ?? getEmptyContext(),
|
||||
status: ExecutionStatus.Active
|
||||
})
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ export async function RunSubProcess (
|
||||
const target = control.client.getModel().findObject(processId)
|
||||
if (target === undefined) return
|
||||
const res: Tx[] = []
|
||||
const context: Ref<Execution>[] = []
|
||||
const resultContext: Ref<Execution>[] = []
|
||||
for (const _card of Array.isArray(card) ? card : [card]) {
|
||||
if (target.parallelExecutionForbidden === true) {
|
||||
const currentExecution = await control.client.findAll(process.class.Execution, {
|
||||
@@ -127,7 +127,7 @@ export async function RunSubProcess (
|
||||
.getModel()
|
||||
.findAllSync(process.class.Transition, { process: target._id, from: null })[0]
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
const emptyContext = {} as ExecutionContext
|
||||
const context = params.context ?? ({} as ExecutionContext)
|
||||
const id = generateId<Execution>()
|
||||
res.push(
|
||||
control.client.txFactory.createTxCreateDoc(
|
||||
@@ -137,7 +137,7 @@ export async function RunSubProcess (
|
||||
process: processId,
|
||||
currentState: initTransition.to,
|
||||
card: _card,
|
||||
context: emptyContext,
|
||||
context,
|
||||
status: ExecutionStatus.Active,
|
||||
rollback: [],
|
||||
parentId: execution._id
|
||||
@@ -145,9 +145,9 @@ export async function RunSubProcess (
|
||||
id
|
||||
)
|
||||
)
|
||||
context.push(id)
|
||||
resultContext.push(id)
|
||||
}
|
||||
return { txes: res, rollback: undefined, context }
|
||||
return { txes: res, rollback: undefined, context: resultContext }
|
||||
}
|
||||
|
||||
export async function CreateToDo (
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
//
|
||||
|
||||
import cardPlugin from '@hcengineering/card'
|
||||
import {
|
||||
import core, {
|
||||
Doc,
|
||||
generateId,
|
||||
getDiffUpdate,
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
Ref,
|
||||
Tx,
|
||||
TxProcessor,
|
||||
TxUpdateDoc,
|
||||
WorkspaceUuid
|
||||
} from '@hcengineering/core'
|
||||
import { getResource } from '@hcengineering/platform'
|
||||
@@ -255,6 +256,16 @@ async function executeTransition (execution: Execution, transition: Transition,
|
||||
rollback.push(...actionResult.rollback)
|
||||
}
|
||||
res.push(...actionResult.txes)
|
||||
for (const tx of actionResult.txes) {
|
||||
const updateTx = tx as TxUpdateDoc<Doc>
|
||||
if (updateTx._class === core.class.TxUpdateDoc && updateTx.objectId === execution.card) {
|
||||
const updatedCard = TxProcessor.updateDoc2Doc(
|
||||
control.client.getHierarchy().clone(control.cache.get(execution.card)),
|
||||
updateTx
|
||||
)
|
||||
control.cache.set(execution.card, updatedCard)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!disableRollback) {
|
||||
|
||||
Reference in New Issue
Block a user