Activity presenters fix (#2511)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-01-16 12:42:08 +06:00 committed by GitHub
parent 69b1371624
commit d5cdf5e80c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 19 deletions

View File

@ -32,7 +32,7 @@
TimeSince TimeSince
} from '@hcengineering/ui' } from '@hcengineering/ui'
import type { AttributeModel } from '@hcengineering/view' import type { AttributeModel } from '@hcengineering/view'
import { getActions } from '@hcengineering/view-resources' import { getActions, ObjectPresenter } from '@hcengineering/view-resources'
import { ActivityKey, DisplayTx } from '../activity' import { ActivityKey, DisplayTx } from '../activity'
import activity from '../plugin' import activity from '../plugin'
import TxViewTx from './TxViewTx.svelte' import TxViewTx from './TxViewTx.svelte'
@ -215,7 +215,11 @@
<div class="strong"> <div class="strong">
<div class="flex flex-wrap gap-2" class:emphasized={value.added.length > 1}> <div class="flex flex-wrap gap-2" class:emphasized={value.added.length > 1}>
{#each value.added as cvalue} {#each value.added as cvalue}
{#if value.isObjectAdded}
<ObjectPresenter value={cvalue} />
{:else}
<svelte:component this={m.presenter} value={cvalue} /> <svelte:component this={m.presenter} value={cvalue} />
{/if}
{/each} {/each}
</div> </div>
</div> </div>
@ -234,11 +238,15 @@
<div class="strong"> <div class="strong">
<div class="flex flex-wrap gap-2 flex-grow" class:emphasized={value.removed.length > 1}> <div class="flex flex-wrap gap-2 flex-grow" class:emphasized={value.removed.length > 1}>
{#each value.removed as cvalue} {#each value.removed as cvalue}
{#if value.isObjectRemoved}
<ObjectPresenter value={cvalue} />
{:else}
<svelte:component this={m.presenter} value={cvalue} /> <svelte:component this={m.presenter} value={cvalue} />
{/if}
{/each} {/each}
</div> </div>
</div> </div>
{:else if value.set === null || value.set === undefined} {:else if value.set === null || value.set === undefined || value.set === ''}
<span class="lower"><Label label={activity.string.Unset} /> <Label label={m.label} /></span> <span class="lower"><Label label={activity.string.Unset} /> <Label label={m.label} /></span>
{:else} {:else}
<span class="lower" class:flex-grow={hasMessageType}> <span class="lower" class:flex-grow={hasMessageType}>
@ -251,11 +259,19 @@
{/if} {/if}
{#if isMessageType(m.attribute)} {#if isMessageType(m.attribute)}
<div class="strong message emphasized"> <div class="strong message emphasized">
{#if value.isObjectSet}
<ObjectPresenter value={value.set} />
{:else}
<svelte:component this={m.presenter} value={value.set} /> <svelte:component this={m.presenter} value={value.set} />
{/if}
</div> </div>
{:else} {:else}
<div class="strong"> <div class="strong">
{#if value.isObjectSet}
<ObjectPresenter value={value.set} />
{:else}
<svelte:component this={m.presenter} value={value.set} /> <svelte:component this={m.presenter} value={value.set} />
{/if}
</div> </div>
{/if} {/if}
{/if} {/if}
@ -264,7 +280,7 @@
{:else if viewlet === undefined && model.length > 0 && tx.mixinTx} {:else if viewlet === undefined && model.length > 0 && tx.mixinTx}
{#each model as m} {#each model as m}
{#await getValue(client, m, tx) then value} {#await getValue(client, m, tx) then value}
{#if value.set === null} {#if value.set === null || value.set === ''}
<span> <span>
<Label label={activity.string.Unset} /> <span class="lower"><Label label={m.label} /></span> <Label label={activity.string.Unset} /> <span class="lower"><Label label={m.label} /></span>
</span> </span>
@ -276,11 +292,19 @@
</span> </span>
{#if isMessageType(m.attribute)} {#if isMessageType(m.attribute)}
<div class="strong message emphasized"> <div class="strong message emphasized">
{#if value.isObjectSet}
<ObjectPresenter value={value.set} />
{:else}
<svelte:component this={m.presenter} value={value.set} /> <svelte:component this={m.presenter} value={value.set} />
{/if}
</div> </div>
{:else} {:else}
<div class="strong"> <div class="strong">
{#if value.isObjectSet}
<ObjectPresenter value={value.set} />
{:else}
<svelte:component this={m.presenter} value={value.set} /> <svelte:component this={m.presenter} value={value.set} />
{/if}
</div> </div>
{/if} {/if}
{/if} {/if}

View File

@ -224,10 +224,14 @@ async function buildRemovedDoc (
return doc return doc
} }
async function getAllRealValues (client: TxOperations, values: any[], _class: Ref<Class<Doc>>): Promise<any[]> { async function getAllRealValues (
if (values.length === 0) return [] client: TxOperations,
values: any[],
_class: Ref<Class<Doc>>
): Promise<[any[], boolean]> {
if (values.length === 0) return [[], false]
if (values.some((value) => typeof value !== 'string')) { if (values.some((value) => typeof value !== 'string')) {
return values return [values, false]
} }
if ( if (
_class === core.class.TypeString || _class === core.class.TypeString ||
@ -235,12 +239,12 @@ async function getAllRealValues (client: TxOperations, values: any[], _class: Re
_class === core.class.TypeNumber || _class === core.class.TypeNumber ||
_class === core.class.TypeDate _class === core.class.TypeDate
) { ) {
return values return [values, false]
} }
const realValues = await client.findAll(_class, { _id: { $in: values } }) const realValues = await client.findAll(_class, { _id: { $in: values } })
const realValuesIds = realValues.map(({ _id }) => _id) const realValuesIds = realValues.map(({ _id }) => _id)
return [ const res = [
...realValues, ...realValues,
...(await Promise.all( ...(await Promise.all(
values values
@ -248,6 +252,7 @@ async function getAllRealValues (client: TxOperations, values: any[], _class: Re
.map(async (value) => await buildRemovedDoc(client, value, _class)) .map(async (value) => await buildRemovedDoc(client, value, _class))
)) ))
].filter((v) => v != null) ].filter((v) => v != null)
return [res, true]
} }
function combineAttributes (attributes: any[], key: string, operator: string, arrayKey: string): any[] { function combineAttributes (attributes: any[], key: string, operator: string, arrayKey: string): any[] {
@ -260,15 +265,31 @@ function combineAttributes (attributes: any[], key: string, operator: string, ar
).filter((v) => v != null) ).filter((v) => v != null)
} }
export async function getValue (client: TxOperations, m: AttributeModel, tx: DisplayTx): Promise<any> { interface TxAttributeValue {
set: any
isObjectSet: boolean
added: any[]
isObjectAdded: boolean
removed: any[]
isObjectRemoved: boolean
}
export async function getValue (client: TxOperations, m: AttributeModel, tx: DisplayTx): Promise<TxAttributeValue> {
const utxs = getModifiedAttributes(tx) const utxs = getModifiedAttributes(tx)
const value = { const added = await getAllRealValues(client, combineAttributes(utxs, m.key, '$push', '$each'), m._class)
const removed = await getAllRealValues(client, combineAttributes(utxs, m.key, '$pull', '$in'), m._class)
const value: TxAttributeValue = {
set: utxs[0][m.key], set: utxs[0][m.key],
added: await getAllRealValues(client, combineAttributes(utxs, m.key, '$push', '$each'), m._class), isObjectSet: false,
removed: await getAllRealValues(client, combineAttributes(utxs, m.key, '$pull', '$in'), m._class) added: added[0],
isObjectAdded: added[1],
removed: removed[0],
isObjectRemoved: removed[1]
} }
if (value.set !== undefined) { if (value.set !== undefined) {
;[value.set] = await getAllRealValues(client, [value.set], m._class) const res = await getAllRealValues(client, [value.set], m._class)
value.set = res[0][0]
value.isObjectSet = res[1]
} }
return value return value
} }