From a4353b0fc7e93a8917847b7dc34458812656ffdb Mon Sep 17 00:00:00 2001 From: Alex <41288429+Dvinyanin@users.noreply.github.com> Date: Wed, 1 Jun 2022 10:21:34 +0700 Subject: [PATCH] Adjust label editors (#1961) Signed-off-by: Dvinyanin Alexandr --- changelog.md | 1 + plugins/activity-resources/src/activity.ts | 2 +- .../src/components/Activity.svelte | 3 +- .../src/components/TxView.svelte | 4 +-- .../src/components/TxViewTx.svelte | 4 +-- .../src/components/utils.ts | 28 ++++++++++++++++++- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/changelog.md b/changelog.md index 7ae42a0669..93b9cb4516 100644 --- a/changelog.md +++ b/changelog.md @@ -8,6 +8,7 @@ Platform: - Adjust label editors design - Allow to define table columns order - Fix skills/labels selection and show real usage counter +- Fix skills/labels activity ## 0.6.22 diff --git a/plugins/activity-resources/src/activity.ts b/plugins/activity-resources/src/activity.ts index f201b0fb1f..cfdc4c7597 100644 --- a/plugins/activity-resources/src/activity.ts +++ b/plugins/activity-resources/src/activity.ts @@ -337,7 +337,7 @@ class ActivityImpl implements Activity { // we have same keys, // Remember previous transactions if (result.txDocIds === undefined) { - result.txDocIds = new Set() + result.txDocIds = new Set(prevTx.txDocIds) } if (prevTx.doc?._id !== undefined) { result.txDocIds?.add(prevTx.doc._id) diff --git a/plugins/activity-resources/src/components/Activity.svelte b/plugins/activity-resources/src/components/Activity.svelte index 8a614f9b53..94f97d8881 100644 --- a/plugins/activity-resources/src/components/Activity.svelte +++ b/plugins/activity-resources/src/components/Activity.svelte @@ -21,6 +21,7 @@ import { Component, Grid, IconActivity, Label, Scroller } from '@anticrm/ui' import { ActivityKey, activityKey, DisplayTx, newActivity } from '../activity' import TxView from './TxView.svelte' + import { filterCollectionTxes } from './utils' export let object: Doc export let integrate: boolean = false @@ -48,7 +49,7 @@ $: activityQuery.update( object, (result) => { - txes = result + txes = filterCollectionTxes(result) }, SortingOrder.Descending, new Map( diff --git a/plugins/activity-resources/src/components/TxView.svelte b/plugins/activity-resources/src/components/TxView.svelte index 35618bf7b5..d4c0980e09 100644 --- a/plugins/activity-resources/src/components/TxView.svelte +++ b/plugins/activity-resources/src/components/TxView.svelte @@ -249,7 +249,7 @@ {/await} {/each} {:else if viewlet && viewlet.display === 'inline' && viewlet.component} - {#if tx.collectionAttribute !== undefined && (tx.txDocIds?.size ?? 0) > 1} + {#if tx.collectionAttribute !== undefined}
@@ -270,7 +270,7 @@ {#if viewlet && viewlet.component && viewlet.display !== 'inline'}
- {#if tx.collectionAttribute !== undefined && (tx.txDocIds?.size ?? 0) > 1} + {#if tx.collectionAttribute !== undefined}
diff --git a/plugins/activity-resources/src/components/TxViewTx.svelte b/plugins/activity-resources/src/components/TxViewTx.svelte index d783ba1508..011870bea7 100644 --- a/plugins/activity-resources/src/components/TxViewTx.svelte +++ b/plugins/activity-resources/src/components/TxViewTx.svelte @@ -22,7 +22,7 @@
- {#each filterTx([tx, ...tx.txes], core.class.TxCreateDoc) as ctx, i} + {#each filterTx([...tx.txes, tx], core.class.TxCreateDoc) as ctx, i} {#if i === 0}
{/if} @@ -34,7 +34,7 @@ {/if}
{/each} - {#each filterTx([tx, ...tx.txes], core.class.TxRemoveDoc) as ctx, i} + {#each filterTx([...tx.txes, tx], core.class.TxRemoveDoc) as ctx, i} {#if i === 0}
{/if} diff --git a/plugins/activity-resources/src/components/utils.ts b/plugins/activity-resources/src/components/utils.ts index 0c3a61a02c..eb7cffe2f9 100644 --- a/plugins/activity-resources/src/components/utils.ts +++ b/plugins/activity-resources/src/components/utils.ts @@ -125,7 +125,7 @@ async function checkInlineViewlets ( client: TxOperations, model: AttributeModel[] ): Promise<{ viewlet: TxDisplayViewlet, model: AttributeModel[] }> { - if (dtx.collectionAttribute !== undefined && (dtx.txDocIds?.size ?? 0) > 1) { + if (dtx.collectionAttribute !== undefined) { // Check if we have a class presenter we could have a pseudo viewlet based on class presenter. viewlet = await createPseudoViewlet(client, dtx, activity.string.CollectionUpdated, 'content') } else if (dtx.tx._class === core.class.TxCreateDoc) { @@ -252,3 +252,29 @@ export async function getValue (client: TxOperations, m: AttributeModel, tx: Dis } return value } + +export function filterCollectionTxes (txes: DisplayTx[]): DisplayTx[] { + return txes.map(filterCollectionTx).filter(Boolean) as DisplayTx[] +} + +function filterCollectionTx (tx: DisplayTx): DisplayTx | undefined { + if (tx.collectionAttribute === undefined) return tx + const txes = tx.txes.reduceRight( + (txes, ctx) => { + const filtredTxes = txes.filter( + ({ tx: { _class }, doc }) => doc?._id !== ctx.doc?._id || _class === core.class.TxUpdateDoc + ) + return ctx.tx._class === core.class.TxUpdateDoc || filtredTxes.length === txes.length + ? [ctx, ...txes] + : filtredTxes + }, + [tx] + ) + const txDocIds = txes.map(({ doc }) => doc?._id).filter(Boolean) as Array> + const ctx = txes.pop() + if (ctx !== undefined) { + ctx.txes = txes + ctx.txDocIds = new Set(txDocIds) + } + return ctx +}