Process copy markup when card creating (#10149)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2025-10-25 11:33:12 +05:00
committed by GitHub
parent d952aa15b6
commit 6f5740fba2
11 changed files with 492 additions and 428 deletions
+2 -1
View File
@@ -694,7 +694,8 @@
"ACCOUNTS_URL": "http://localhost:3000",
"QUEUE_CONFIG": "localhost:19092",
"QUEUE_REGION": "cockroach",
"TEMPORAL_ADDRESS": "localhost:7233"
"TEMPORAL_ADDRESS": "localhost:7233",
"COLLABORATOR_URL": "ws://localhost:3078"
},
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"runtimeVersion": "20",
+425 -423
View File
File diff suppressed because it is too large Load Diff
@@ -59,7 +59,7 @@
}
function getKeys (_class: Ref<Class<MasterTag>>): AnyAttribute[] {
const ignoreKeys = ['_class', 'content', 'parent', 'attachments', 'todos']
const ignoreKeys = ['_class', 'parent', 'attachments', 'todos']
const attributes = hierarchy.getAllAttributes(_class, core.class.Doc)
const res: AnyAttribute[] = []
for (const [key, attr] of attributes) {
@@ -28,6 +28,6 @@
}
</script>
<span class="overflow-label" use:tooltip={tooltipParams}>
<span class="overflow-label px-3" use:tooltip={tooltipParams}>
{value ?? ''}
</span>
@@ -17,11 +17,13 @@ import cardPlugin, { Card, MasterTag, Tag } from '@hcengineering/card'
import core, {
Association,
checkMixinKey,
Class,
Data,
Doc,
findProperty,
generateId,
getObjectValue,
makeDocCollabId,
matchQuery,
Ref,
Relation,
@@ -428,12 +430,41 @@ export async function CreateToDo (
}
}
async function getContent (
control: ProcessControl,
source: string,
_id: Ref<Card>,
_class: Ref<Class<Card>>
): Promise<string> {
const collabClient = control.collaboratorFactory()
const data = source.split('-')
const sourceId = data[0]
const sourceAttr = data[1]
if (isEmpty(sourceId) || isEmpty(sourceAttr)) {
throw processError(process.error.RequiredParamsNotProvided, { params: 'content' })
}
const sourceCard = await control.client.findOne(cardPlugin.class.Card, { _id: sourceId as Ref<Card> })
if (sourceCard === undefined) {
throw processError(process.error.ObjectNotFound, { _id: sourceId })
}
const markup = await collabClient.getMarkup(makeDocCollabId(sourceCard, sourceAttr))
const ref = await collabClient.createMarkup(
{
objectClass: _class,
objectId: _id,
objectAttr: 'content'
},
markup
)
return ref
}
export async function CreateCard (
params: MethodParams<Card>,
execution: Execution,
control: ProcessControl
): Promise<ExecuteResult> {
const { _class, title, ...attrs } = params
const { _class, title, content, ...attrs } = params
for (const key in { _class, title }) {
const val = (params as any)[key]
if (isEmpty(val)) {
@@ -441,10 +472,15 @@ export async function CreateCard (
}
}
const _id = generateId<Card>()
const newContent =
content !== undefined ? await getContent(control, content, _id, _class as Ref<Class<Card>>) : undefined
const data = {
title,
...attrs
} as any
if (newContent !== undefined) {
data.content = content
}
const tx = control.client.txFactory.createTxCreateDoc(_class as Ref<MasterTag>, execution.space, data, _id)
const res: Tx[] = [tx]
const rollback: Tx[] = [control.client.txFactory.createTxRemoveDoc(_class as Ref<MasterTag>, execution.space, _id)]
+1
View File
@@ -42,6 +42,7 @@
"@hcengineering/card": "^0.7.0",
"@hcengineering/process": "^0.7.0",
"@hcengineering/platform": "^0.7.5",
"@hcengineering/collaborator-client": "^0.7.5",
"@hcengineering/server-core": "^0.7.8"
}
}
+2
View File
@@ -1,6 +1,7 @@
import { Card } from '@hcengineering/card'
import { Doc, MeasureContext, PersonId, Ref, Timestamp, Tx, TxOperations, WorkspaceUuid } from '@hcengineering/core'
import { Execution, ExecutionError, MethodParams, Trigger, UserResult } from '@hcengineering/process'
import { CollaboratorClient } from '@hcengineering/collaborator-client'
export type ExecuteFunc = (
params: MethodParams<Doc>,
@@ -41,6 +42,7 @@ export interface ProcessMessage {
export interface ProcessControl {
ctx: MeasureContext
client: TxOperations
collaboratorFactory: () => CollaboratorClient
cache: Map<string, any>
messageContext: Record<string, any>
workspace: WorkspaceUuid
+1
View File
@@ -60,6 +60,7 @@
"@hcengineering/platform": "^0.7.5",
"@hcengineering/card": "^0.7.0",
"@hcengineering/process": "^0.7.0",
"@hcengineering/collaborator-client": "^0.7.5",
"@hcengineering/server-process": "^0.7.0",
"@hcengineering/server-process-resources": "^0.7.0",
"@hcengineering/server-core": "^0.7.8",
+17
View File
@@ -0,0 +1,17 @@
//
// Copyright © 2024 Hardcore Engineering Inc.
//
//
import { CollaboratorClient, getClient as getCollaboratorClient } from '@hcengineering/collaborator-client'
import { systemAccountUuid, WorkspaceUuid } from '@hcengineering/core'
import { generateToken } from '@hcengineering/server-token'
import config from './config'
/**
* @public
*/
export function createCollaboratorClient (workspaceId: WorkspaceUuid): CollaboratorClient {
const token = generateToken(systemAccountUuid, workspaceId, { service: 'processor', mode: 'processor' })
return getCollaboratorClient(workspaceId, token, config.CollaboratorURL)
}
+3 -1
View File
@@ -23,6 +23,7 @@ export interface Config {
AccountsUrl: string
TemporalAddress: string
TemporalNamespace: string
CollaboratorURL: string
}
const config: Config = {
@@ -31,7 +32,8 @@ const config: Config = {
QueueRegion: process.env.QUEUE_REGION ?? '',
AccountsUrl: process.env.ACCOUNTS_URL ?? '',
TemporalAddress: process.env.TEMPORAL_ADDRESS ?? 'localhost:7233',
TemporalNamespace: process.env.TEMPORAL_NAMESPACE ?? 'huly'
TemporalNamespace: process.env.TEMPORAL_NAMESPACE ?? 'huly',
CollaboratorURL: process.env.COLLABORATOR_URL ?? ''
}
export default config
+2
View File
@@ -62,6 +62,7 @@ import { getTemporalClient } from './temporal'
import { getClient, releaseClient } from './utils'
import { CreateMessageEvent, MessageEventType } from '@hcengineering/communication-sdk-types'
import { ActivityUpdateType, ActivityProcess, MessageType } from '@hcengineering/communication-types'
import { createCollaboratorClient } from './collaborator'
const activeExecutions = new Set<Ref<Execution>>()
@@ -72,6 +73,7 @@ export async function messageHandler (record: ProcessMessage, ws: WorkspaceUuid,
const control: ProcessControl = {
ctx,
client,
collaboratorFactory: () => createCollaboratorClient(ws),
cache: new Map<string, any>(),
messageContext: record.context,
workspace: ws,