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

Update Accession Interface #409

Merged
merged 8 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions src/fragmentarium/application/FragmentSearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import _ from 'lodash'
import Promise from 'bluebird'
import {
FragmentInfo,
FragmentInfoDto,
FragmentInfosPagination,
} from 'fragmentarium/domain/fragment'

export type FragmentInfosPromise = Promise<ReadonlyArray<FragmentInfo>>
export type FragmentInfosDtoPromise = Promise<ReadonlyArray<FragmentInfoDto>>
export type FragmentInfoPromise = Promise<FragmentInfo>
export type FragmentInfosPaginationPromise = Promise<FragmentInfosPagination>

Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/domain/FragmentDtos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type ExternalNumbers = {

export default interface FragmentDto {
museumNumber: MuseumNumber
accession: string
accession: MuseumNumber | null
editedInOraccProject: string
publication: string
description: string
Expand Down
5 changes: 4 additions & 1 deletion src/fragmentarium/domain/fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Joins } from './join'
import { MarkupPart } from 'transliteration/domain/markup'
import { Period, PeriodModifier } from 'common/period'
import { Session } from 'auth/Session'
import {
import FragmentDto, {
ExternalNumber,
ExternalNumbers,
ExternalNumberTypes,
Expand All @@ -33,6 +33,9 @@ export interface FragmentInfo {
readonly genres: Genres
}

export type FragmentInfoDto = Omit<FragmentInfo, 'script' | 'accession'> &
Pick<FragmentDto, 'script' | 'accession'>

export interface FragmentInfosPagination {
fragmentInfos: readonly FragmentInfo[]
totalCount: number
Expand Down
115 changes: 83 additions & 32 deletions src/fragmentarium/infrastructure/FragmentRepository.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Promise from 'bluebird'
import { testDelegation, TestData } from 'test-support/utils'
import FragmentRepository, {
createFragmentInfo,
createScript,
} from './FragmentRepository'
import FragmentRepository, { createScript } from './FragmentRepository'
import Folio from 'fragmentarium/domain/Folio'
import { fragment, fragmentDto } from 'test-support/test-fragment'
import { ApiError } from 'http/ApiClient'
Expand All @@ -13,6 +10,10 @@ import { QueryResult } from 'query/QueryResult'
import { FragmentQuery } from 'query/FragmentQuery'
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 { FragmentInfo, FragmentInfoDto } from 'fragmentarium/domain/fragment'

const apiClient = {
fetchJson: jest.fn(),
Expand All @@ -30,6 +31,12 @@ const folio = new Folio({ name: 'MJG', number: 'K1' })
const word = 'šim'
const introduction = 'Introduction'
const lemmas = 'foo I+bar II'
const genres: Genre[] = [
new Genre(['ARCHIVE', 'Letter'], false),
new Genre(['CANONICAL', 'Divination'], true),
]
const mesopotamianDate = mesopotamianDateFactory.build()
const archaeology = archaeologyFactory.build()
const museumNumber = { prefix: 'A', number: '7', suffix: '' }
const queryResult: QueryResult = {
items: [
Expand Down Expand Up @@ -76,32 +83,27 @@ const lineToVecRankingDto = {
scoreWeighted: [lineToVecScoreDto],
}

const date = {
day: {
value: '1',
},
isSeleucidEra: true,
month: {
value: '1',
},
year: {
value: '1',
},
}

const fragmentInfo = {
const fragmentInfo: FragmentInfo = {
number: 'K.1',
accession: '1234',
script: script,
accession: 'A.1234',
script: createScript(script),
description: 'a fragment',
matchingLines: null,
editor: 'Editor',
// eslint-disable-next-line camelcase
edition_date: '2019-09-10T13:03:37.575580',
references: [],
genres: [],
date: date,
dates: [date],
genres: new Genres([]),
}

const fragmentInfoDto: FragmentInfoDto = {
...fragmentInfo,
script,
accession: {
prefix: 'A',
number: '1234',
suffix: '',
},
}

const testData: TestData<FragmentRepository>[] = [
Expand Down Expand Up @@ -154,33 +156,33 @@ const testData: TestData<FragmentRepository>[] = [
'random',
[],
apiClient.fetchJson,
[createFragmentInfo(fragmentInfo)],
[fragmentInfo],
['/fragments?random=true', false],
Promise.resolve([fragmentInfo])
Promise.resolve([fragmentInfoDto])
),
new TestData(
'interesting',
[],
apiClient.fetchJson,
[createFragmentInfo(fragmentInfo)],
[fragmentInfo],
['/fragments?interesting=true', false],
Promise.resolve([fragmentInfo])
Promise.resolve([fragmentInfoDto])
),
new TestData(
'fetchLatestTransliterations',
[],
apiClient.fetchJson,
[createFragmentInfo(fragmentInfo)],
[fragmentInfo],
['/fragments?latest=true', false],
Promise.resolve([fragmentInfo])
Promise.resolve([fragmentInfoDto])
),
new TestData(
'fetchNeedsRevision',
[],
apiClient.fetchJson,
[createFragmentInfo(fragmentInfo)],
[fragmentInfo],
['/fragments?needsRevision=true', false],
Promise.resolve([fragmentInfo])
Promise.resolve([fragmentInfoDto])
),
new TestData(
'updateTransliteration',
Expand Down Expand Up @@ -314,7 +316,56 @@ const testData: TestData<FragmentRepository>[] = [
fragment,
[
`/fragments/${encodeURIComponent(fragmentId)}/introduction`,
{ introduction: introduction },
{ introduction },
],
Promise.resolve(fragmentDto)
),
new TestData(
'updateGenres',
[fragmentId, new Genres(genres)],
apiClient.postJson,
fragment,
[`/fragments/${encodeURIComponent(fragmentId)}/genres`, { genres }],
Promise.resolve(fragmentDto)
),
new TestData(
'updateDate',
[fragmentId, mesopotamianDate],
apiClient.postJson,
fragment,
[
`/fragments/${encodeURIComponent(fragmentId)}/date`,
{ date: mesopotamianDate },
],
Promise.resolve(fragmentDto)
),
new TestData(
'updateDatesInText',
[fragmentId, [mesopotamianDate]],
apiClient.postJson,
fragment,
[
`/fragments/${encodeURIComponent(fragmentId)}/dates_in_text`,
{ datesInText: [mesopotamianDate] },
],
Promise.resolve(fragmentDto)
),
new TestData(
'updateNotes',
[fragmentId, notes],
apiClient.postJson,
fragment,
[`/fragments/${encodeURIComponent(fragmentId)}/notes`, { notes }],
Promise.resolve(fragmentDto)
),
new TestData(
'updateArchaeology',
[fragmentId, archaeology],
apiClient.postJson,
fragment,
[
`/fragments/${encodeURIComponent(fragmentId)}/archaeology`,
{ archaeology },
],
Promise.resolve(fragmentDto)
),
Expand Down
13 changes: 10 additions & 3 deletions src/fragmentarium/infrastructure/FragmentRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import produce from 'immer'
import {
Fragment,
FragmentInfo,
FragmentInfoDto,
Script,
ScriptDto,
} from 'fragmentarium/domain/fragment'
Expand All @@ -19,6 +20,7 @@ import {
import Annotation from 'fragmentarium/domain/annotation'
import {
FragmentInfoRepository,
FragmentInfosDtoPromise,
FragmentInfosPromise,
} from 'fragmentarium/application/FragmentSearchService'
import Reference from 'bibliography/domain/Reference'
Expand Down Expand Up @@ -81,6 +83,7 @@ function createFragment(dto: FragmentDto): Fragment {
return Fragment.create({
...dto,
number: museumNumberToString(dto.museumNumber),
accession: dto.accession ? museumNumberToString(dto.accession) : '',
museum: Museum.of(dto.museum),
joins: createJoins(dto.joins),
measures: {
Expand All @@ -106,8 +109,12 @@ function createFragment(dto: FragmentDto): Fragment {
})
}

export function createFragmentInfo(dto): FragmentInfo {
return { ...dto, script: createScript(dto.script) }
export function createFragmentInfo(dto: FragmentInfoDto): FragmentInfo {
return {
...dto,
script: createScript(dto.script),
accession: dto.accession ? museumNumberToString(dto.accession) : '',
}
}

function createFragmentPath(number: string, ...subResources: string[]): string {
Expand Down Expand Up @@ -178,7 +185,7 @@ class ApiFragmentRepository
)
}

_fetch(params: Record<string, unknown>): FragmentInfosPromise {
_fetch(params: Record<string, unknown>): FragmentInfosDtoPromise {
return this.apiClient.fetchJson(`/fragments?${stringify(params)}`, false)
}

Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SearchForm extends Component<Props, State> {
type="text"
name="number"
value={this.state.number || ''}
placeholder="Museum, accession, or CDLI number"
placeholder="Museum, accession, CDLI, or ecavation number"
aria-label="Number"
onChange={(
event: React.ChangeEvent<HTMLTextAreaElement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
class="form-control"
id="number"
name="number"
placeholder="Museum, accession, or CDLI number"
placeholder="Museum, accession, CDLI, or ecavation number"
type="text"
value=""
/>
Expand Down
2 changes: 1 addition & 1 deletion src/test-support/fragment-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const fragmentFactory = Factory.define<Fragment>(
const museumNumber = `${chance.word()}.${sequence}`
return new Fragment(
museumNumber,
chance.word(),
`${chance.word()}.${sequence}`,
chance.sentence({ words: 4 }),
associations.joins ?? [
[
Expand Down
8 changes: 6 additions & 2 deletions src/test-support/test-fragment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ export const fragmentDto: FragmentDto = {
number: 'Fragment',
suffix: '',
},
accession: '',
accession: {
prefix: 'A',
number: '38',
suffix: 'b',
},
publication: 'electronic Babylonian Library',
description: 'A fragment to be used when testing the eBL application',
joins: [
Expand Down Expand Up @@ -423,7 +427,7 @@ export const fragmentDto: FragmentDto = {

export const fragment = new Fragment(
'Test.Fragment',
'',
'A.38.b',
'electronic Babylonian Library',
[
[
Expand Down
Loading