Skip to content

Commit

Permalink
Filter Indirect Joins (#463)
Browse files Browse the repository at this point in the history
* add functioning prototype of excludeIndirectJoins functions

* redesign duplicate detection
- the typecast in l. 50 is necessary to bribe TS into compiling
- on usage of xor, see lodash/lodash#4852

* redesign duplicate detection
- the typecast in l. 50 is necessary to bribe TS into compiling
- on usage of xor, see lodash/lodash#4852

* refactor th components

* Revert "refactor th components"

This reverts commit 6a5eca6.
  • Loading branch information
fsimonjetz authored Mar 12, 2024
1 parent 4511ee8 commit 5cdd5a6
Showing 1 changed file with 73 additions and 39 deletions.
112 changes: 73 additions & 39 deletions src/corpus/ui/Chapters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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[]
Expand Down Expand Up @@ -121,46 +151,50 @@ const Manuscripts = withData<
<ProvenanceHeading id={provenanceId}>
{provenance}
</ProvenanceHeading>
{manuscripts.map((manuscript, index) => {
const rowId = _.uniqueId('row-')
return (
<tr key={`${provenance} ${index}`}>
<th
id={rowId}
headers={[provenanceId, siglumId].join(' ')}
scope="row"
className="list-of-manuscripts__siglum-heading"
>
{manuscript.siglum}
</th>
<td
headers={[provenanceId, rowId, museumNumberId].join(
' '
)}
className="list-of-manuscripts__museum-numbers"
>
<ManuscriptJoins manuscript={manuscript} />
<ManuscriptReferences
references={manuscript.references}
/>
</td>
<td
headers={[extantLinesId, rowId, museumNumberId].join(
' '
)}
className="list-of-manuscripts__extant-lines"
>
{extantLines ? (
<ExtantLinesList
extantLines={extantLines[manuscript.siglum]}
{excludeIndirectJoins(manuscripts).map(
(manuscript, index) => {
const rowId = _.uniqueId('row-')
return (
<tr key={`${provenance} ${index}`}>
<th
id={rowId}
headers={[provenanceId, siglumId].join(' ')}
scope="row"
className="list-of-manuscripts__siglum-heading"
>
{manuscript.siglum}
</th>
<td
headers={[provenanceId, rowId, museumNumberId].join(
' '
)}
className="list-of-manuscripts__museum-numbers"
>
<ManuscriptJoins manuscript={manuscript} />
<ManuscriptReferences
references={manuscript.references}
/>
) : (
<Spinner />
)}
</td>
</tr>
)
})}
</td>
<td
headers={[
extantLinesId,
rowId,
museumNumberId,
].join(' ')}
className="list-of-manuscripts__extant-lines"
>
{extantLines ? (
<ExtantLinesList
extantLines={extantLines[manuscript.siglum]}
/>
) : (
<Spinner />
)}
</td>
</tr>
)
}
)}
</React.Fragment>
)
})
Expand Down

0 comments on commit 5cdd5a6

Please sign in to comment.