more card fixes (#8077)
Some checks are pending
CI / build (push) Waiting to run
CI / uitest-qms (push) Waiting to run
CI / svelte-check (push) Blocked by required conditions
CI / formatting (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / uitest (push) Waiting to run
CI / uitest-pg (push) Waiting to run
CI / uitest-workspaces (push) Waiting to run
CI / docker-build (push) Blocked by required conditions
CI / dist-build (push) Blocked by required conditions

This commit is contained in:
Denis Bykhov 2025-02-24 08:27:06 +05:00 committed by GitHub
parent ce10156fe4
commit 355025d56a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 71 additions and 18 deletions

View File

@ -32,6 +32,15 @@ export function createModel (builder: Builder): void {
}
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverCard.trigger.OnAttributeRemove,
isAsync: true,
txMatch: {
_class: core.class.TxRemoveDoc,
objectClass: core.class.Attribute
}
})
builder.createDoc(serverCore.class.Trigger, core.space.Model, {
trigger: serverCard.trigger.OnMasterTagRemove,
isAsync: true,

View File

@ -760,7 +760,7 @@ export class LiveQuery implements WithTx, Client {
}
const docs = q.result.getDocs()
for (const doc of docs) {
const docToUpdate = doc.$associations?.[association._id].find((it) => it._id === tx.objectId)
const docToUpdate = doc.$associations?.[association._id]?.find((it) => it._id === tx.objectId)
if (docToUpdate !== undefined) {
if (tx._class === core.class.TxMixin) {
TxProcessor.updateMixin4Doc(docToUpdate, tx as TxMixin<Doc, Doc>)

View File

@ -14,7 +14,7 @@
-->
<script lang="ts">
import { MasterTag } from '@hcengineering/card'
import { Ref } from '@hcengineering/core'
import core, { Ref } from '@hcengineering/core'
import { createQuery, getClient } from '@hcengineering/presentation'
import {
BreadcrumbItem,
@ -46,7 +46,7 @@
const hierarchy = client.getHierarchy()
const query = createQuery()
$: query.query(card.class.MasterTag, { _id: selectedTagId }, (res) => {
$: query.query(core.class.Class, { _id: selectedTagId }, (res) => {
masterTag = res[0]
})

View File

@ -19,7 +19,7 @@ export * from './analytics'
export interface MasterTag extends Class<Card> {}
export interface Tag extends Mixin<Card> {}
export interface Tag extends MasterTag, Mixin<Card> {}
export interface Card extends Doc {
attachments?: number

View File

@ -34,9 +34,41 @@ async function OnAttribute (ctx: TxCreateDoc<AnyAttribute>[], control: TriggerCo
)
const prefs = await control.findAll(control.ctx, view.class.ViewletPreference, { attachedTo: viewlet._id })
for (const pref of prefs) {
pref.config.push(attr.name)
res.push(
control.txFactory.createTxUpdateDoc(pref._class, pref.space, pref._id, {
config: viewlet.config
config: pref.config
})
)
}
}
}
return res
}
return []
}
async function OnAttributeRemove (ctx: TxRemoveDoc<AnyAttribute>[], control: TriggerControl): Promise<Tx[]> {
const attr = control.removedMap.get(ctx[0].objectId) as AnyAttribute
if (attr === undefined) return []
if (control.hierarchy.isDerived(attr.attributeOf, card.class.Card)) {
const desc = control.hierarchy.getDescendants(attr.attributeOf)
const res: Tx[] = []
for (const des of desc) {
const viewlets = control.modelDb.findAllSync(view.class.Viewlet, { attachTo: des })
for (const viewlet of viewlets) {
viewlet.config = viewlet.config.filter((p) => p !== attr.name)
res.push(
control.txFactory.createTxUpdateDoc(viewlet._class, viewlet.space, viewlet._id, {
config: viewlet.config
})
)
const prefs = await control.findAll(control.ctx, view.class.ViewletPreference, { attachedTo: viewlet._id })
for (const pref of prefs) {
pref.config = pref.config.filter((p) => p !== attr.name)
res.push(
control.txFactory.createTxUpdateDoc(pref._class, pref.space, pref._id, {
config: pref.config
})
)
}
@ -72,6 +104,7 @@ async function OnMasterTagRemove (ctx: TxRemoveDoc<MasterTag>[], control: Trigge
export default async () => ({
trigger: {
OnAttribute,
OnAttributeRemove,
OnMasterTagRemove
}
})

View File

@ -28,6 +28,7 @@ export const serverCardId = 'server-card' as Plugin
export default plugin(serverCardId, {
trigger: {
OnAttribute: '' as Resource<TriggerFunc>,
OnAttributeRemove: '' as Resource<TriggerFunc>,
OnMasterTagRemove: '' as Resource<TriggerFunc>
}
})

View File

@ -15,6 +15,7 @@
import core, {
Domain,
DOMAIN_MODEL,
groupByArray,
TxProcessor,
withContext,
@ -86,20 +87,29 @@ export class DomainTxMiddleware extends BaseMiddleware implements Middleware {
const deleteByDomain = groupByArray(toDelete, (it) => this.context.hierarchy.getDomain(it.objectClass))
for (const [domain, domainTxes] of deleteByDomain.entries()) {
const todel = await ctx.with(
'adapter-load',
{},
() =>
adapter.load(
ctx,
domain,
domainTxes.map((it) => it.objectId)
),
{ count: toDelete.length }
)
if (domain === DOMAIN_MODEL) {
for (const tx of domainTxes) {
const ddoc = this.context.modelDb.findObject(tx.objectId)
if (ddoc !== undefined) {
ctx.contextData.removedMap.set(ddoc._id, ddoc)
}
}
} else {
const todel = await ctx.with(
'adapter-load',
{},
() =>
adapter.load(
ctx,
domain,
domainTxes.map((it) => it.objectId)
),
{ count: toDelete.length }
)
for (const ddoc of todel) {
ctx.contextData.removedMap.set(ddoc._id, ddoc)
for (const ddoc of todel) {
ctx.contextData.removedMap.set(ddoc._id, ddoc)
}
}
}
}