From cacb6036eeadc4cbfbfc4f00e665d1387405fa32 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 3 Apr 2025 12:57:15 +0500 Subject: [PATCH] Fix duplication of views (#8450) Signed-off-by: Denis Bykhov --- models/card/src/migration.ts | 16 ++++++++++++++++ .../components/settings/view/ViewsSection.svelte | 6 ++---- server-plugins/card-resources/src/index.ts | 5 ++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/models/card/src/migration.ts b/models/card/src/migration.ts index 02752234a4..7d111617c3 100644 --- a/models/card/src/migration.ts +++ b/models/card/src/migration.ts @@ -40,11 +40,27 @@ export const cardOperation: MigrateOperation = { { state: 'migrateViewlets-v2', func: migrateViewlets + }, + { + state: 'removeVariantViewlets', + func: removeVariantViewlets } ]) } } +async function removeVariantViewlets (client: Client): Promise { + const txOp = new TxOperations(client, core.account.System) + const desc = client + .getHierarchy() + .getDescendants(card.class.Card) + .filter((c) => c !== card.class.Card) + const viewlets = await client.findAll(view.class.Viewlet, { attachTo: { $in: desc }, variant: { $exists: true } }) + for (const viewlet of viewlets) { + await txOp.remove(viewlet) + } +} + async function setParentInfo (client: MigrationClient): Promise { await client.update( DOMAIN_CARD, diff --git a/plugins/card-resources/src/components/settings/view/ViewsSection.svelte b/plugins/card-resources/src/components/settings/view/ViewsSection.svelte index df976649b1..52a6e3ff08 100644 --- a/plugins/card-resources/src/components/settings/view/ViewsSection.svelte +++ b/plugins/card-resources/src/components/settings/view/ViewsSection.svelte @@ -17,7 +17,7 @@ import { MasterTag } from '@hcengineering/card' import { WithLookup } from '@hcengineering/core' - import { createQuery, getClient } from '@hcengineering/presentation' + import { createQuery } from '@hcengineering/presentation' import setting from '@hcengineering/setting' import { clearSettingsStore, settingsStore } from '@hcengineering/setting-resources' import { ButtonIcon, Icon, IconAdd, Label, showPopup } from '@hcengineering/ui' @@ -29,14 +29,12 @@ export let masterTag: MasterTag let viewlets: WithLookup[] = [] - const client = getClient() - const hierarchy = client.getHierarchy() const query = createQuery() $: query.query( view.class.Viewlet, - { attachTo: { $in: hierarchy.getDescendants(masterTag._id) } }, + { attachTo: masterTag._id, variant: { $exists: false } }, (res) => { viewlets = res }, diff --git a/server-plugins/card-resources/src/index.ts b/server-plugins/card-resources/src/index.ts index b998e4047e..7c183c0987 100644 --- a/server-plugins/card-resources/src/index.ts +++ b/server-plugins/card-resources/src/index.ts @@ -216,7 +216,10 @@ async function OnMasterTagCreate (ctx: TxCreateDoc[], control: control.txFactory.createTxMixin(createTx.objectId, core.class.Mixin, core.space.Model, setting.mixin.UserMixin, {}) ) if (tag._class === card.class.MasterTag) { - const viewlets = await control.findAll(control.ctx, view.class.Viewlet, { attachTo: tag.extends }) + const viewlets = await control.findAll(control.ctx, view.class.Viewlet, { + attachTo: tag.extends, + variant: { $exists: false } + }) for (const viewlet of viewlets) { const base = extractObjectProps(viewlet) res.push(