Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colophons fix #507

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/fragmentarium/domain/Colophon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import produce, { Draft, castDraft, immerable } from 'immer'
import _ from 'lodash'

export enum ColophonStatus {
Yes = 'Yes',
Expand Down Expand Up @@ -145,22 +146,40 @@ export class IndividualAttestation {
return this?.type?.value ? `${this.type.value}: ` : ''
}
private get nameString(): string {
return this?.name?.value ?? ''
return this.formatItemString(this.name, '')
}

private get sonOfString(): string {
return this?.sonOf?.value ? `s. ${this.sonOf.value}` : ''
return this.formatItemString(this.sonOf, 's.')
}
private get grandsonOfString(): string {
return this?.grandsonOf?.value ? `gs. ${this.grandsonOf.value}` : ''
return this.formatItemString(this.grandsonOf, 'gs.')
}

private get familyString(): string {
return this?.family?.value ? `f. ${this.family.value}` : ''
return this.formatItemString(this.family, 'f.')
}

private get nativeOfString(): string {
return this?.nativeOf?.value ? `n. ${this.nativeOf.value}` : ''
return this.formatItemString(this.nativeOf, 'n.')
}

private formatItemString(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function formatItemString has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

item?: NameAttestation | ProvenanceAttestation,
prefix?: string
): string {
if (!item || _.isEmpty(item) || _.every(item, (val) => val === false)) {
return ''
}
const { isBroken, isUncertain } = item
const prefixString = prefix ? prefix + ' ' : ''
const valueString = item?.value ?? '…'
const brokenUncertainValueString = `${
isBroken === true ? '[' : ''
}${valueString}${isUncertain === true ? '?' : ''}${
isBroken === true ? ']' : ''
}`
return `${prefixString}${brokenUncertainValueString}`
}
}

Expand Down
16 changes: 10 additions & 6 deletions src/fragmentarium/ui/info/Colophon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const getGeneralInfoItems = (colophon: Colophon) =>
const getLocationItems = (colophon: Colophon) =>
['originalFrom', 'writtenIn']
.map((key) => [key, colophon[key]?.value])
.filter(([key, value]) => !!value)
.filter(([, value]) => !!value)
.map(([key, value]) => `${_.startCase(key)}: ${value}`)

const getTypesItem = (colophon: Colophon) =>
colophon?.colophonTypes
colophon?.colophonTypes && colophon?.colophonTypes.length > 0
? [`Types: ${colophon?.colophonTypes.join(', ')}`]
: []

Expand All @@ -31,17 +31,21 @@ const ColophonInfo = ({ fragment }: { fragment: Fragment }): JSX.Element => {
if (!colophon) {
return <></>
}
const mapToList = (text, index) => <li key={index}>{text}</li>
const individuals = colophon?.individuals && colophon?.individuals.length > 0 && (
<li>
Individuals: <ol>{getIndividualsItems(colophon).map(mapToList)}</ol>
</li>
)

return (
<ul className="ColophonInfo__items">
{[
...getGeneralInfoItems(colophon),
...getTypesItem(colophon),
...getLocationItems(colophon),
...getIndividualsItems(colophon),
].map((text, index) => (
<li key={index}>{text}</li>
))}
].map(mapToList)}
{individuals}
</ul>
)
}
Expand Down
Loading