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 #462

Merged
merged 20 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
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
2 changes: 1 addition & 1 deletion src/App.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AppDriver from 'test-support/AppDriver'
import FakeApi from 'test-support/FakeApi'
import { statisticsFactory } from 'test-support/fragment-fixtures'
import { statisticsFactory } from 'test-support/fragment-data-fixtures'
import { tabIds as aboutTabIds } from 'about/ui/about'

test.each([
Expand Down
12 changes: 6 additions & 6 deletions src/chronology/ui/DateEditor/DateSelectionInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ describe('Date Input Groups', () => {
})
)
const yearInput = screen.getByLabelText('Year')
const yearBrokenSwitch = screen.getByLabelText('Year-Broken')
const yearUncertainSwitch = screen.getByLabelText('Year-Uncertain')
const yearBrokenSwitch = screen.getByTestId('year-broken-switch')
const yearUncertainSwitch = screen.getByTestId('year-uncertain-switch')
const monthInput = screen.getByLabelText('Month')
const monthIntercalaryCheckbox = screen.getByLabelText('Intercalary')
const monthBrokenSwitch = screen.getByLabelText('Month-Broken')
const monthUncertainSwitch = screen.getByLabelText('Month-Uncertain')
const monthBrokenSwitch = screen.getByTestId('month-broken-switch')
const monthUncertainSwitch = screen.getByTestId('month-uncertain-switch')
const dayInput = screen.getByLabelText('Day')
const dayBrokenSwitch = screen.getByLabelText('Day-Broken')
const dayUncertainSwitch = screen.getByLabelText('Day-Uncertain')
const dayBrokenSwitch = screen.getByTestId('day-broken-switch')
const dayUncertainSwitch = screen.getByTestId('day-uncertain-switch')

expect(yearInput).toBeInTheDocument()
expect(yearBrokenSwitch).toBeInTheDocument()
Expand Down
34 changes: 19 additions & 15 deletions src/chronology/ui/DateEditor/DateSelectionInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import getDateConfigs from 'chronology/application/DateSelectionInputConfig'
import {
InputGroupProps,
RadioButton,
getBrokenAndUncertainSwitches,
} from 'chronology/ui/DateEditor/DateSelectionInputBase'
import { BrokenAndUncertainSwitches } from 'common/BrokenAndUncertain'

type InputGroupsProps = {
yearValue: string
Expand Down Expand Up @@ -93,13 +93,15 @@ function getKingEponymSelect(
? EponymField({ ...props, assyrianPhase })
: KingField(props)}
<InputGroup size="sm">
{getBrokenAndUncertainSwitches({
name,
isBroken: props[`${name}Broken`] ?? false,
isUncertain: props[`${name}Uncertain`] ?? false,
setBroken: props[`set${_.capitalize(name)}Broken`],
setUncertain: props[`set${_.capitalize(name)}Uncertain`],
})}
<BrokenAndUncertainSwitches
{...{
name,
isBroken: props[`${name}isBroken`] ?? false,
isUncertain: props[`${name}Uncertain`] ?? false,
setBroken: props[`set${_.capitalize(name)}Broken`],
setUncertain: props[`set${_.capitalize(name)}Uncertain`],
}}
/>
</InputGroup>
<br />
</>
Expand Down Expand Up @@ -195,13 +197,15 @@ function getDateInputGroup({
checked={isIntercalary}
/>
)}
{getBrokenAndUncertainSwitches({
name,
isBroken,
isUncertain,
setBroken,
setUncertain,
})}
<BrokenAndUncertainSwitches
{...{
name,
isBroken,
isUncertain,
setBroken,
setUncertain,
}}
/>
</InputGroup>
)
}
Expand Down
37 changes: 1 addition & 36 deletions src/chronology/ui/DateEditor/DateSelectionInputBase.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { BrokenUncertainProps } from 'common/BrokenAndUncertain'
import React from 'react'
import _ from 'lodash'
import { Form } from 'react-bootstrap'

export interface BrokenUncertainProps {
name: string
isBroken: boolean
isUncertain: boolean
setBroken: React.Dispatch<React.SetStateAction<boolean>>
setUncertain: React.Dispatch<React.SetStateAction<boolean>>
}

export interface InputGroupProps extends BrokenUncertainProps {
value: string
isIntercalary?: boolean
Expand Down Expand Up @@ -42,30 +34,3 @@ export const RadioButton = ({
onChange={onChange}
/>
)

export function getBrokenAndUncertainSwitches({
name,
isBroken,
isUncertain,
setBroken,
setUncertain,
}: BrokenUncertainProps): JSX.Element {
return (
<>
<Form.Switch
label={`${_.startCase(name)}-Broken`}
id={`${name}_broken`}
style={{ marginLeft: '10px' }}
onChange={(event) => setBroken(event.target.checked)}
checked={isBroken}
/>
<Form.Switch
label={`${_.startCase(name)}-Uncertain`}
id={`${name}_uncertain`}
style={{ marginLeft: '10px' }}
onChange={(event) => setUncertain(event.target.checked)}
checked={isUncertain}
/>
</>
)
}
45 changes: 45 additions & 0 deletions src/common/BrokenAndUncertain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react'
import { Form } from 'react-bootstrap'

export interface BrokenUncertainProps {
name: string
isBroken?: boolean
isUncertain?: boolean
setBroken:
| React.Dispatch<React.SetStateAction<boolean>>
| ((isBroken: boolean) => void)
setUncertain:
| React.Dispatch<React.SetStateAction<boolean>>
| ((isUncertain: boolean) => void)
}

export function BrokenAndUncertainSwitches({
name,
isBroken = false,
isUncertain = false,
setBroken,
setUncertain,
}: BrokenUncertainProps): JSX.Element {
return (
<>
<Form.Switch
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

label={`Broken`}
id={`${name}_broken`}
aria-label={`${name}-broken-switch`}
data-testid={`${name}-broken-switch`}
style={{ marginLeft: '10px' }}
onChange={(event) => setBroken(event.target.checked)}
checked={isBroken}
/>
<Form.Switch
Copy link

Choose a reason for hiding this comment

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

Similar blocks of code found in 2 locations. Consider refactoring.

label={`Uncertain`}
id={`${name}_uncertain`}
aria-label={`${name}-uncertain-switch`}
data-testid={`${name}-uncertain-switch`}
style={{ marginLeft: '10px' }}
onChange={(event) => setUncertain(event.target.checked)}
checked={isUncertain}
/>
</>
)
}
2 changes: 1 addition & 1 deletion src/fragmentarium/application/FindspotService.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findspotFactory } from 'test-support/fragment-fixtures'
import { findspotFactory } from 'test-support/fragment-data-fixtures'
import { FindspotService } from './FindspotService'
import { testDelegation, TestData } from 'test-support/utils'

Expand Down
23 changes: 20 additions & 3 deletions src/fragmentarium/application/FragmentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import LemmatizationFactory from './LemmatizationFactory'
import BibliographyService from 'bibliography/application/BibliographyService'
import WordRepository from 'dictionary/infrastructure/WordRepository'
import {
archaeologyFactory,
fragmentFactory,
manuscriptAttestationFactory,
} from 'test-support/fragment-fixtures'
import { archaeologyFactory } from 'test-support/fragment-data-fixtures'
import {
bibliographyEntryFactory,
referenceFactory,
Expand Down Expand Up @@ -58,15 +58,17 @@ const fragmentRepository = {
updateIntroduction: jest.fn(),
updateNotes: jest.fn(),
updateLemmatization: jest.fn(),
fetchGenres: jest.fn(),
fetchProvenances: jest.fn(),
updateGenres: jest.fn(),
updateScript: jest.fn(),
updateDate: jest.fn(),
updateDatesInText: jest.fn(),
fetchGenres: jest.fn(),
fetchProvenances: jest.fn(),
fetchPeriods: jest.fn(),
fetchColophonNames: jest.fn(),
updateReferences: jest.fn(),
updateArchaeology: jest.fn(),
updateColophon: jest.fn(),
folioPager: jest.fn(),
fragmentPager: jest.fn(),
findLemmas: jest.fn(),
Expand Down Expand Up @@ -199,13 +201,15 @@ describe('methods returning fragment', () => {
let fragment: Fragment
let result: Fragment
let genreResult: string[][]
let colophonNamesResult: string[]
const genreOptions = [['ARCHIVE', 'Administrative']]
const genres: Genres = Genres.fromJson([
{
category: ['ARCHIVE', 'Administrative'],
uncertain: false,
},
])
const colophonNamesOptions = [['Humbaba', 'Enkidu']]
const date: MesopotamianDate = MesopotamianDate.fromJson({
year: { value: '1' },
month: { value: '1' },
Expand Down Expand Up @@ -373,6 +377,19 @@ describe('methods returning fragment', () => {
expect(fragmentRepository.fetchGenres).toHaveBeenCalled())
})

describe('fetch colophon names', () => {
beforeEach(async () => {
fragmentRepository.fetchColophonNames.mockReturnValue(
Promise.resolve(colophonNamesOptions)
)
colophonNamesResult = await fragmentService.fetchColophonNames('u')
})
test('returns names', () =>
expect(colophonNamesResult).toEqual(colophonNamesOptions))
test('calls repository with correct parameters', () =>
expect(fragmentRepository.fetchColophonNames).toHaveBeenCalled())
})

describe('update genre', () => {
let expectedFragment: Fragment

Expand Down
14 changes: 14 additions & 0 deletions src/fragmentarium/application/FragmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FragmentQuery } from 'query/FragmentQuery'
import { MesopotamianDate } from 'chronology/domain/Date'
import { FragmentAfoRegisterQueryResult, QueryResult } from 'query/QueryResult'
import { ArchaeologyDto } from 'fragmentarium/domain/archaeologyDtos'
import { Colophon } from 'fragmentarium/ui/fragment/ColophonEditor'

export type ThumbnailSize = 'small' | 'medium' | 'large'

Expand Down Expand Up @@ -65,6 +66,7 @@ export interface FragmentRepository {
fetchGenres(): Bluebird<string[][]>
fetchProvenances(): Bluebird<string[][]>
fetchPeriods(): Bluebird<string[]>
fetchColophonNames(query: string): Bluebird<string[]>
updateGenres(number: string, genres: Genres): Bluebird<Fragment>
updateScript(number: string, script: Script): Bluebird<Fragment>
updateDate(number: string, date: MesopotamianDate): Bluebird<Fragment>
Expand All @@ -90,6 +92,7 @@ export interface FragmentRepository {
number: string,
archaeology: ArchaeologyDto
): Bluebird<Fragment>
updateColophon(number: string, colophon: Colophon): Bluebird<Fragment>
folioPager(folio: Folio, fragmentNumber: string): Bluebird<FolioPagerData>
fragmentPager(fragmentNumber: string): Bluebird<FragmentPagerData>
findLemmas(lemma: string, isNormalized: boolean): Bluebird<Word[][]>
Expand Down Expand Up @@ -184,6 +187,7 @@ export class FragmentService {
fetchGenres(): Bluebird<string[][]> {
return this.fragmentRepository.fetchGenres()
}

fetchProvenances(): Bluebird<string[][]> {
return this.fragmentRepository.fetchProvenances()
}
Expand All @@ -192,6 +196,10 @@ export class FragmentService {
return this.fragmentRepository.fetchPeriods()
}

fetchColophonNames(query: string): Bluebird<string[]> {
return this.fragmentRepository.fetchColophonNames(query)
}

listAllFragments(): Bluebird<string[]> {
return this.fragmentRepository.listAllFragments()
}
Expand Down Expand Up @@ -262,6 +270,12 @@ export class FragmentService {
.then((fragment: Fragment) => this.injectReferences(fragment))
}

updateColophon(number: string, colophon: Colophon): Bluebird<Fragment> {
return this.fragmentRepository
.updateColophon(number, colophon)
.then((fragment: Fragment) => this.injectReferences(fragment))
}

findInCorpus(number: string): Bluebird<ReadonlyArray<ManuscriptAttestation>> {
return this.fragmentRepository.findInCorpus(number)
}
Expand Down
2 changes: 2 additions & 0 deletions src/fragmentarium/domain/FragmentDtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from 'chronology/domain/DateParameters'
import { ArchaeologyDto } from './archaeologyDtos'
import { MuseumKey } from './museum'
import { ColophonDto } from 'fragmentarium/ui/fragment/ColophonEditor'

interface MeasureDto {
value?: number
Expand Down Expand Up @@ -117,4 +118,5 @@ export default interface FragmentDto {
archaeology?: Omit<ArchaeologyDto, 'excavationNumber'> & {
excavationNumber?: MuseumNumber
}
colophon?: ColophonDto
}
2 changes: 1 addition & 1 deletion src/fragmentarium/domain/archaeology.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
archaeologyFactory,
dateRangeFactory,
findspotFactory,
} from 'test-support/fragment-fixtures'
} from 'test-support/fragment-data-fixtures'
import {
BuildingType,
Findspot,
Expand Down
Loading
Loading