mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-19 23:00:13 +00:00
Activity presenters fix (#2511)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
69b1371624
commit
d5cdf5e80c
@ -32,7 +32,7 @@
|
||||
TimeSince
|
||||
} from '@hcengineering/ui'
|
||||
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 activity from '../plugin'
|
||||
import TxViewTx from './TxViewTx.svelte'
|
||||
@ -215,7 +215,11 @@
|
||||
<div class="strong">
|
||||
<div class="flex flex-wrap gap-2" class:emphasized={value.added.length > 1}>
|
||||
{#each value.added as cvalue}
|
||||
{#if value.isObjectAdded}
|
||||
<ObjectPresenter value={cvalue} />
|
||||
{:else}
|
||||
<svelte:component this={m.presenter} value={cvalue} />
|
||||
{/if}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
@ -234,11 +238,15 @@
|
||||
<div class="strong">
|
||||
<div class="flex flex-wrap gap-2 flex-grow" class:emphasized={value.removed.length > 1}>
|
||||
{#each value.removed as cvalue}
|
||||
{#if value.isObjectRemoved}
|
||||
<ObjectPresenter value={cvalue} />
|
||||
{:else}
|
||||
<svelte:component this={m.presenter} value={cvalue} />
|
||||
{/if}
|
||||
{/each}
|
||||
</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>
|
||||
{:else}
|
||||
<span class="lower" class:flex-grow={hasMessageType}>
|
||||
@ -251,11 +259,19 @@
|
||||
{/if}
|
||||
{#if isMessageType(m.attribute)}
|
||||
<div class="strong message emphasized">
|
||||
{#if value.isObjectSet}
|
||||
<ObjectPresenter value={value.set} />
|
||||
{:else}
|
||||
<svelte:component this={m.presenter} value={value.set} />
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="strong">
|
||||
{#if value.isObjectSet}
|
||||
<ObjectPresenter value={value.set} />
|
||||
{:else}
|
||||
<svelte:component this={m.presenter} value={value.set} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
@ -264,7 +280,7 @@
|
||||
{:else if viewlet === undefined && model.length > 0 && tx.mixinTx}
|
||||
{#each model as m}
|
||||
{#await getValue(client, m, tx) then value}
|
||||
{#if value.set === null}
|
||||
{#if value.set === null || value.set === ''}
|
||||
<span>
|
||||
<Label label={activity.string.Unset} /> <span class="lower"><Label label={m.label} /></span>
|
||||
</span>
|
||||
@ -276,11 +292,19 @@
|
||||
</span>
|
||||
{#if isMessageType(m.attribute)}
|
||||
<div class="strong message emphasized">
|
||||
{#if value.isObjectSet}
|
||||
<ObjectPresenter value={value.set} />
|
||||
{:else}
|
||||
<svelte:component this={m.presenter} value={value.set} />
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="strong">
|
||||
{#if value.isObjectSet}
|
||||
<ObjectPresenter value={value.set} />
|
||||
{:else}
|
||||
<svelte:component this={m.presenter} value={value.set} />
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
@ -224,10 +224,14 @@ async function buildRemovedDoc (
|
||||
return doc
|
||||
}
|
||||
|
||||
async function getAllRealValues (client: TxOperations, values: any[], _class: Ref<Class<Doc>>): Promise<any[]> {
|
||||
if (values.length === 0) return []
|
||||
async function getAllRealValues (
|
||||
client: TxOperations,
|
||||
values: any[],
|
||||
_class: Ref<Class<Doc>>
|
||||
): Promise<[any[], boolean]> {
|
||||
if (values.length === 0) return [[], false]
|
||||
if (values.some((value) => typeof value !== 'string')) {
|
||||
return values
|
||||
return [values, false]
|
||||
}
|
||||
if (
|
||||
_class === core.class.TypeString ||
|
||||
@ -235,12 +239,12 @@ async function getAllRealValues (client: TxOperations, values: any[], _class: Re
|
||||
_class === core.class.TypeNumber ||
|
||||
_class === core.class.TypeDate
|
||||
) {
|
||||
return values
|
||||
return [values, false]
|
||||
}
|
||||
|
||||
const realValues = await client.findAll(_class, { _id: { $in: values } })
|
||||
const realValuesIds = realValues.map(({ _id }) => _id)
|
||||
return [
|
||||
const res = [
|
||||
...realValues,
|
||||
...(await Promise.all(
|
||||
values
|
||||
@ -248,6 +252,7 @@ async function getAllRealValues (client: TxOperations, values: any[], _class: Re
|
||||
.map(async (value) => await buildRemovedDoc(client, value, _class))
|
||||
))
|
||||
].filter((v) => v != null)
|
||||
return [res, true]
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
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 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],
|
||||
added: await getAllRealValues(client, combineAttributes(utxs, m.key, '$push', '$each'), m._class),
|
||||
removed: await getAllRealValues(client, combineAttributes(utxs, m.key, '$pull', '$in'), m._class)
|
||||
isObjectSet: false,
|
||||
added: added[0],
|
||||
isObjectAdded: added[1],
|
||||
removed: removed[0],
|
||||
isObjectRemoved: removed[1]
|
||||
}
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user