diff --git a/src/corpus/ui/Chapters.tsx b/src/corpus/ui/Chapters.tsx
index b210a87c2..40a6f9a2c 100644
--- a/src/corpus/ui/Chapters.tsx
+++ b/src/corpus/ui/Chapters.tsx
@@ -18,6 +18,8 @@ import { ChapterId } from 'transliteration/domain/chapter-id'
import './Chapters.sass'
import ManuscriptJoins from './ManuscriptJoins'
import ManuscriptReferences from './ManuscriptReferences'
+import produce, { castDraft } from 'immer'
+import { Join } from 'fragmentarium/domain/join'
function ProvenanceHeading({
id,
@@ -40,6 +42,34 @@ function ProvenanceHeading({
)
}
+function excludeIndirectJoins(manuscripts: Manuscript[]): Manuscript[] {
+ type JoinGroup = readonly Join[]
+ const uniqueJoinGroups: JoinGroup[] = _(manuscripts)
+ .flatMap('joins')
+ .map((join) => [join])
+ .thru((values) => _.xorWith(...(values as [JoinGroup[]]), _.isEqual))
+ .value()
+
+ function isUniqueJoin(other: JoinGroup): boolean {
+ return _.some(uniqueJoinGroups, (group) => _.isEqual(group, other))
+ }
+
+ return manuscripts.map((manuscript) =>
+ produce(manuscript, (draft) => {
+ function isPrimaryJoin(joins: JoinGroup): boolean {
+ return _.some(
+ joins.map((join) => join.museumNumber === manuscript.museumNumber)
+ )
+ }
+ draft.joins = castDraft(
+ manuscript.joins.filter(
+ (joinGroup) => isPrimaryJoin(joinGroup) || isUniqueJoin(joinGroup)
+ )
+ )
+ })
+ )
+}
+
const Manuscripts = withData<
{
uncertainFragments: readonly UncertainFragment[]
@@ -121,46 +151,50 @@ const Manuscripts = withData<