Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Mar 8, 2024
1 parent 7d1b903 commit d46fb73
Show file tree
Hide file tree
Showing 26 changed files with 485 additions and 531 deletions.
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
75 changes: 0 additions & 75 deletions src/colophons/domain/Colophons.ts

This file was deleted.

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
2 changes: 1 addition & 1 deletion 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
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
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 { ApiFindspotRepository } from './FindspotRepository'
import { testDelegation, TestData } from 'test-support/utils'
import { toFindspotDto } from 'fragmentarium/domain/archaeologyDtos'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { queryItemFactory } from 'test-support/query-item-factory'
import { museumNumberToString } from 'fragmentarium/domain/MuseumNumber'
import { Genre, Genres } from 'fragmentarium/domain/Genres'
import { mesopotamianDateFactory } from 'test-support/date-fixtures'
import { archaeologyFactory } from 'test-support/fragment-fixtures'
import { archaeologyFactory } from 'test-support/fragment-data-fixtures'
import { FragmentInfo, FragmentInfoDto } from 'fragmentarium/domain/fragment'

const apiClient = {
Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/infrastructure/ImageRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Promise from 'bluebird'
import ApiImageRepository from './ImageRepository'
import Folio from 'fragmentarium/domain/Folio'
import { folioFactory } from 'test-support/fragment-fixtures'
import { folioFactory } from 'test-support/fragment-data-fixtures'

const image = new Blob([''], { type: 'image/jpeg' })

Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/createFragmentUrl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Chance from 'chance'
import { createFragmentUrl, createFragmentUrlWithFolio } from './FragmentLink'
import { parseUrl } from 'query-string'
import { folioFactory } from 'test-support/fragment-fixtures'
import { folioFactory } from 'test-support/fragment-data-fixtures'

const chance = new Chance()

Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/fragment/ArchaeologyEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ArchaeologyEditor from './ArchaeologyEditor'
import {
archaeologyFactory,
findspotFactory,
} from 'test-support/fragment-fixtures'
} from 'test-support/fragment-data-fixtures'
import {
Archaeology,
Findspot,
Expand Down
175 changes: 175 additions & 0 deletions src/fragmentarium/ui/fragment/ColophonEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import React, { FormEvent, useState } from 'react'
import { Form, Button, Row } from 'react-bootstrap'
import { Provenance } from 'corpus/domain/provenance'
import { Fragment } from 'fragmentarium/domain/fragment'
import {
ColophonIndividualsInput,
ColophonOwnershipInput,
ColophonStatusInput,
ColophonTypeInput,
} from './ColophonEditorInputs'

export enum ColophonStatus {
Yes = 'Yes',
No = 'No',
Broken = 'Broken',
OnlyColophon = 'Only Colophon',
}

export enum ColophonType {
AsbA = 'Asb a',
AsbB = 'Asb b',
AsbC = 'Asb c',
AsbD = 'Asb d',
AsbE = 'Asb e',
AsbF = 'Asb f',
AsbG = 'Asb g', // BAK 321
AsbH = 'Asb h',
AsbI = 'Asb i',
AsbK = 'Asb k',
AsbL = 'Asb l',
AsbM = 'Asb m',
AsbN = 'Asb n',
AsbO = 'Asb o',
AsbP = 'Asb p',
AsbQ = 'Asb q',
AsbRS = 'Asb r/s',
AsbT = 'Asb t',
AsbU = 'Asb u',
AsbV = 'Asb v',
AsbW = 'Asb w',
AsbUnclear = 'Asb Unclear',
NzkBAK293 = 'Nzk BAK 293',
NzkBAK294 = 'Nzk BAK 294',
NzkBAK295 = 'Nzk BAK 295',
NzkBAK296 = 'Nzk BAK 296',
NzkBAK297 = 'Nzk BAK 297',
}

export enum ColophonOwnership {
Library = 'Library',
Private = 'Private',
Individual = 'Individual',
}

export enum IndividualType {
Owner = 'Owner',
Scribe = 'Scribe',
Other = 'Other',
}

export interface Name {
value: string
isBroken: boolean
isUncertain: boolean
}

export interface Individual {
name?: Name
sonOf?: Name
grandsonOf?: Name
family?: Name
nativeOf?: Provenance
type?: IndividualType
}

export interface Colophon {
colophonStatus: ColophonStatus
colophonOwnership?: ColophonOwnership
colophonType?: ColophonType
originalFrom?: Provenance
writtenIn?: Provenance
notesToScribalProcess?: string
individuals?: Individual[]
}

interface Props {
fragment: Fragment
updateColophon: (colophon: Colophon) => Promise<void>
disabled?: boolean
}

const ColophonEditor: React.FC<Props> = ({
fragment,
disabled,
updateColophon,
}) => {
// ToDo: Implement commented out
//const { colophon } = fragment
const [formData, setFormData] = useState<Colophon>({
colophonStatus: ColophonStatus.No, //colophon?.colophonStatus || ColophonStatus.No,
colophonOwnership: ColophonOwnership.Library, //fragment.colophon?.colophonOwnership || ColophonOwnership.Library,
colophonType: ColophonType.AsbA, //fragment.colophon?.colophonType,
originalFrom: undefined, //colophon?.originalFrom,
writtenIn: undefined, //colophon?.writtenIn,
notesToScribalProcess: undefined, //colophon?.notesToScribalProcess,
individuals: [], //colophon?.individuals,
})
const [error, setError] = useState<Error | null>(null)

/*
const handleInputChange = (
event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
const { name, value } = event.target
setFormData((prevState) => ({
...prevState,
[name]: value,
}))
}
*/

const handleSelectChange = (name: string) => (selectedOption: any) => {
setFormData((prevState) => ({
...prevState,
[name]: selectedOption?.value,
}))
}

const submit = async (event: FormEvent<HTMLFormElement>): Promise<void> => {
event.preventDefault()
try {
await updateColophon(formData)
} catch (error) {
setError(error as Error)
}
}

return (
<Form onSubmit={submit}>
<Row>
<ColophonStatusInput
colophonStatus={formData.colophonStatus}
onChange={handleSelectChange}
/>
</Row>
<Row>
<ColophonOwnershipInput
colophonOwnership={formData.colophonOwnership}
onChange={handleSelectChange}
/>
</Row>
<Row>
<ColophonTypeInput
colophonType={formData.colophonType}
onChange={handleSelectChange('colophonType')}
/>
</Row>
<Row>
<ColophonIndividualsInput
individuals={formData.individuals ?? []}
onChange={handleSelectChange('colophonType')}
/>
</Row>
<Button
variant="primary"
type="submit"
disabled={disabled || error !== null}
>
Save
</Button>
</Form>
)
}

export default ColophonEditor
Loading

0 comments on commit d46fb73

Please sign in to comment.