fix: deduplicate object and document lists in DocTable and RelationEditor to prevent rendering issues (#10958)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov
2026-07-06 12:08:03 +07:00
committed by GitHub
parent 5c48abda35
commit d2e92134cc
2 changed files with 33 additions and 7 deletions
@@ -47,7 +47,20 @@
const refs: HTMLElement[] = []
$: refs.length = objects.length
$: uniqueObjects = deduplicate(objects)
function deduplicate (list: Doc[] | undefined): Doc[] {
if (!list) return []
const seen = new Set<string>()
return list.filter((item) => {
if (item?._id == null) return false
if (seen.has(item._id)) return false
seen.add(item._id)
return true
})
}
$: refs.length = uniqueObjects.length
$: viewlet = getViewlet(_class)
@@ -210,9 +223,9 @@
</tr>
</thead>
{/if}
{#if objects.length > 0}
{#if uniqueObjects.length > 0}
<tbody>
{#each objects as object, row (object._id)}
{#each uniqueObjects as object, row (object._id)}
<tr
class="antiTable-body__row"
class:fixed={row === selection}
@@ -23,6 +23,19 @@
$: _class = direction === 'B' ? association.classB : association.classA
$: uniqueDocs = deduplicate(docs)
function deduplicate (list: Doc[] | undefined): Doc[] {
if (!list) return []
const seen = new Set<string>()
return list.filter((item) => {
if (item?._id == null) return false
if (seen.has(item._id)) return false
seen.add(item._id)
return true
})
}
function getCreate (): ObjectCreate | undefined {
const factory = client.getHierarchy().classHierarchyMixin(_class, view.mixin.ObjectFactory)
if (factory) {
@@ -53,7 +66,7 @@
function add (): void {
const create = getCreate()
const isVersionable = client.getHierarchy().classHierarchyMixin(_class, core.mixin.VersionableClass) !== undefined
const baseQuery = { _id: { $nin: docs.map((p) => p._id) } }
const baseQuery = { _id: { $nin: uniqueDocs.map((p) => p._id) } }
const docQuery = isVersionable ? { isLatest: true, ...baseQuery } : baseQuery
showPopup(
ObjectBoxPopup,
@@ -120,7 +133,7 @@
return direction === 'B'
}
$: allowToCreate = isAllowedToCreate(association, docs, direction)
$: allowToCreate = isAllowedToCreate(association, uniqueDocs, direction)
$: classLabel = client.getHierarchy().getClass(_class).label
</script>
@@ -139,9 +152,9 @@
</svelte:fragment>
<svelte:fragment slot="content">
{#if docs?.length > 0 && config != null}
{#if uniqueDocs?.length > 0 && config != null}
<Scroller horizontal>
<DocTable objects={docs} {_class} {config} {onContextMenu} />
<DocTable objects={uniqueDocs} {_class} {config} {onContextMenu} />
</Scroller>
{:else if !readonly}
<div