Related subprocesses (#9097)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-05-26 22:36:48 +07:00
committed by GitHub
parent 9017ad2310
commit 4785a7acc5
6 changed files with 101 additions and 28 deletions
+28 -1
View File
@@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { type Card } from '@hcengineering/card'
import { type Card, type MasterTag } from '@hcengineering/card'
import core, {
generateId,
type AnyAttribute,
@@ -42,6 +42,7 @@ import {
type Process,
type ProcessFunction,
type RelatedContext,
type SelectedContext,
type SelectedUserRequest,
type State,
type Step,
@@ -67,6 +68,32 @@ export function generateContextId (): ContextId {
return generateId() as string as ContextId
}
export function getContextAttribute (
client: Client,
context: SelectedContext | undefined,
masterTag: Ref<MasterTag>
): AnyAttribute | undefined {
if (context === undefined) return
const h = client.getHierarchy()
const model = client.getModel()
if (context.type === 'attribute') {
return h.findAttribute(masterTag, context.key)
}
if (context.type === 'nested') {
const attr = h.findAttribute(masterTag, context.path)
if (attr === undefined) return
const parentType = attr.type._class === core.class.ArrOf ? (attr.type as ArrOf<Doc>).of : attr.type
const targetClass = parentType._class === core.class.RefTo ? (parentType as RefTo<Doc>).to : parentType._class
return h.findAttribute(targetClass, context.key)
}
if (context.type === 'relation') {
const assoc = model.findObject(context.association)
if (assoc === undefined) return
const targetClass = context.direction === 'A' ? assoc.classA : assoc.classB
return h.findAttribute(targetClass, context.key)
}
}
export async function pickTransition (
model: ModelDb,
execution: Execution,