Fix activity (#1998)

Signed-off-by: Dvinyanin Alexandr <dvinyanin.alexandr@gmail.com>
This commit is contained in:
Alex 2022-06-03 11:23:51 +07:00 committed by GitHub
parent 885ceadc86
commit d5cfa868f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 4 deletions

View File

@ -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)

View File

@ -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(

View File

@ -22,7 +22,7 @@
</script>
<div class="flex-row-center flex-grow flex-wrap content">
{#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}
<div class="mr-2"><IconAdd size={'small'} /></div>
{/if}
@ -34,7 +34,7 @@
{/if}
</div>
{/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}
<div class="mr-2"><IconDelete size={'small'} /></div>
{/if}

View File

@ -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<Ref<Doc>>
const ctx = txes.pop()
if (ctx !== undefined) {
ctx.txes = txes
ctx.txDocIds = new Set(txDocIds)
}
return ctx
}