Skip to content

Commit

Permalink
more card fixes (#8077)
Browse files Browse the repository at this point in the history
  • Loading branch information
BykhovDenis authored Feb 24, 2025
1 parent ce10156 commit 355025d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 19 deletions.
9 changes: 9 additions & 0 deletions models/server-card/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/query/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
})
Expand Down
2 changes: 1 addition & 1 deletion plugins/card/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 34 additions & 1 deletion server-plugins/card-resources/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
)
}
Expand Down Expand Up @@ -72,6 +104,7 @@ async function OnMasterTagRemove (ctx: TxRemoveDoc<MasterTag>[], control: Trigge
export default async () => ({
trigger: {
OnAttribute,
OnAttributeRemove,
OnMasterTagRemove
}
})
1 change: 1 addition & 0 deletions server-plugins/card/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
}
})
38 changes: 24 additions & 14 deletions server/middleware/src/domainTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import core, {
Domain,
DOMAIN_MODEL,
groupByArray,
TxProcessor,
withContext,
Expand Down Expand Up @@ -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 }
)

for (const ddoc of todel) {
ctx.contextData.removedMap.set(ddoc._id, ddoc)
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)
}
}
}
}
Expand Down

0 comments on commit 355025d

Please sign in to comment.