diff --git a/src/dossiers/application/DossiersService.test.ts b/src/dossiers/application/DossiersService.test.ts new file mode 100644 index 000000000..002304fe4 --- /dev/null +++ b/src/dossiers/application/DossiersService.test.ts @@ -0,0 +1,47 @@ +import { testDelegation, TestData } from 'test-support/utils' +import DossiersRepository from 'dossiers/infrastructure/DossiersRepository' +import DossierRecord from 'dossiers/domain/DossierRecord' +import DossiersService from 'dossiers/application/DossiersService' +import { stringify } from 'query-string' +import { ReferenceType } from 'bibliography/domain/Reference' +import { Provenances } from 'corpus/domain/provenance' +import { PeriodModifiers, Periods } from 'common/period' + +jest.mock('dossiers/infrastructure/DossiersRepository') +const dossiersRepository = new (DossiersRepository as jest.Mock)() + +const dossiersService = new DossiersService(dossiersRepository) + +const resultStub = { + id: 'test', + description: 'some desciption', + isApproximateDate: true, + yearRangeFrom: -500, + yearRangeTo: -470, + relatedKings: [10.2, 11], + provenance: Provenances.Assyria, + script: { + period: Periods['Neo-Assyrian'], + periodModifier: PeriodModifiers.None, + uncertain: false, + }, + references: ['EDITION' as ReferenceType, 'DISCUSSION' as ReferenceType], +} + +const query = { ids: ['test'] } +const entry = new DossierRecord(resultStub) + +const testData: TestData[] = [ + new TestData( + 'queryByIds', + [stringify(query)], + dossiersRepository.queryByIds, + [entry], + [stringify(query)], + Promise.resolve([entry]) + ), +] + +describe('DossiersService', () => { + testDelegation(dossiersService, testData) +}) diff --git a/src/dossiers/application/DossiersService.ts b/src/dossiers/application/DossiersService.ts new file mode 100644 index 000000000..7a543c6a1 --- /dev/null +++ b/src/dossiers/application/DossiersService.ts @@ -0,0 +1,18 @@ +import DossiersRepository from 'dossiers/infrastructure/DossiersRepository' +import DossierRecord from 'dossiers/domain/DossierRecord' + +export interface DossiersSearch { + queryByIds(query: string[]): Promise +} + +export default class DossiersService implements DossiersSearch { + private readonly dossiersRepository: DossiersRepository + + constructor(afoRegisterRepository: DossiersRepository) { + this.dossiersRepository = afoRegisterRepository + } + + queryByIds(query: string[]): Promise { + return this.dossiersRepository.queryByIds(query) + } +} diff --git a/src/dossiers/domain/DossierRecord.test.ts b/src/dossiers/domain/DossierRecord.test.ts new file mode 100644 index 000000000..7ac5438da --- /dev/null +++ b/src/dossiers/domain/DossierRecord.test.ts @@ -0,0 +1,41 @@ +import DossierRecord from 'dossiers/domain/DossierRecord' +import { ReferenceType } from 'bibliography/domain/Reference' +import { PeriodModifiers, Periods } from 'common/period' +import { Provenances } from 'corpus/domain/provenance' + +describe('DossierRecord', () => { + const mockRecord = { + id: 'test', + description: 'some desciption', + isApproximateDate: true, + yearRangeFrom: -500, + yearRangeTo: -470, + relatedKings: [10.2, 11], + provenance: Provenances.Assyria, + script: { + period: Periods['Neo-Assyrian'], + periodModifier: PeriodModifiers.None, + uncertain: false, + }, + references: ['EDITION' as ReferenceType, 'DISCUSSION' as ReferenceType], + } + + describe('constructor', () => { + it('should initialize properties correctly', () => { + const record = new DossierRecord(mockRecord) + expect(record.id).toEqual('test') + expect(record.description).toEqual('some desciption') + expect(record.isApproximateDate).toEqual(true) + expect(record.yearRangeFrom).toEqual(-500) + expect(record.yearRangeTo).toEqual(-470) + expect(record.relatedKings).toEqual([10.2, 11]) + expect(record.provenance).toEqual(Provenances.Assyria) + expect(record.script).toEqual({ + period: Periods['Neo-Assyrian'], + periodModifier: PeriodModifiers.None, + uncertain: false, + }) + expect(record.references).toEqual(['EDITION', 'DISCUSSION']) + }) + }) +}) diff --git a/src/dossiers/domain/DossierRecord.ts b/src/dossiers/domain/DossierRecord.ts new file mode 100644 index 000000000..31ba8d2f9 --- /dev/null +++ b/src/dossiers/domain/DossierRecord.ts @@ -0,0 +1,94 @@ +import { immerable } from 'immer' +import { ReferenceType } from 'bibliography/domain/Reference' +import { Provenance } from 'corpus/domain/provenance' +import { Script } from 'fragmentarium/domain/fragment' + +interface DossierRecordData { + readonly id: string + readonly description?: string + readonly isApproximateDate?: boolean + readonly yearRangeFrom?: number + readonly yearRangeTo?: number + readonly relatedKings?: number[] + readonly provenance?: Provenance + readonly script?: Script + readonly references?: ReferenceType[] +} + +export default class DossierRecord { + [immerable] = true + + readonly id: string + readonly description?: string + readonly isApproximateDate: boolean + readonly yearRangeFrom?: number + readonly yearRangeTo?: number + readonly relatedKings: number[] + readonly provenance?: Provenance + readonly script?: Script + readonly references: ReferenceType[] + + constructor({ + id, + description, + isApproximateDate = false, + yearRangeFrom, + yearRangeTo, + relatedKings = [], + provenance, + script, + references = [], + }: DossierRecordData) { + this.id = id + this.description = description + this.isApproximateDate = isApproximateDate + this.yearRangeFrom = yearRangeFrom + this.yearRangeTo = yearRangeTo + this.relatedKings = relatedKings + this.provenance = provenance + this.script = script + this.references = references + } + + toMarkdownString(): string { + return `${this.YearsToMarkdownString()}` + } + + private YearsToMarkdownString(): string { + const yearRangeFrom = this.formatYear(this.yearRangeFrom) + const yearRangeTo = this.formatYear(this.yearRangeTo) + + if (!yearRangeFrom) { + return '' + } + + if (this.isApproximateDate) { + return this.formatApproximateRange(yearRangeFrom, yearRangeTo) + } + + return this.formatExactRange(yearRangeFrom, yearRangeTo) + } + + private formatYear(year: number | undefined): string { + if (year === undefined) return '' + const prefix = year < 0 ? 'BCE' : 'CE' + return `${Math.abs(year)} ${prefix}` + } + + private formatApproximateRange( + yearRangeFrom: string, + yearRangeTo: string + ): string { + if (yearRangeFrom === yearRangeTo || !yearRangeTo) { + return `ca. ${yearRangeFrom}` + } + return `ca. ${yearRangeFrom} - ${yearRangeTo}` + } + + private formatExactRange(yearRangeFrom: string, yearRangeTo: string): string { + if (yearRangeFrom === yearRangeTo || !yearRangeTo) { + return yearRangeFrom + } + return `${yearRangeFrom} - ${yearRangeTo}` + } +} diff --git a/src/dossiers/domain/DossierReference.ts b/src/dossiers/domain/DossierReference.ts new file mode 100644 index 000000000..1c677dd90 --- /dev/null +++ b/src/dossiers/domain/DossierReference.ts @@ -0,0 +1,4 @@ +export interface DossierReference { + readonly dossierId: string + readonly isUncertain?: boolean +} diff --git a/src/dossiers/infrastructure/DossiersRepository.test.ts b/src/dossiers/infrastructure/DossiersRepository.test.ts new file mode 100644 index 000000000..a0eb01538 --- /dev/null +++ b/src/dossiers/infrastructure/DossiersRepository.test.ts @@ -0,0 +1,91 @@ +import { testDelegation, TestData } from 'test-support/utils' +import DossiersRepository from 'dossiers/infrastructure/DossiersRepository' +import DossierRecord from 'dossiers/domain/DossierRecord' +import { stringify } from 'query-string' +import ApiClient from 'http/ApiClient' +import { PeriodModifiers, Periods } from 'common/period' +import { ReferenceType } from 'bibliography/domain/Reference' +import { Provenances } from 'corpus/domain/provenance' + +jest.mock('http/ApiClient') +jest.mock('dossiers/application/DossiersService') + +const apiClient = new (ApiClient as jest.Mock>)() +const dossiersRepository = new DossiersRepository(apiClient) + +const resultStub = { + id: 'test', + description: 'some description', + isApproximateDate: true, + yearRangeFrom: -500, + yearRangeTo: -470, + relatedKings: [10.2, 11], + provenance: Provenances.Assyria, + script: { + period: Periods['Neo-Assyrian'], + periodModifier: PeriodModifiers.None, + uncertain: false, + }, + references: ['EDITION' as ReferenceType, 'DISCUSSION' as ReferenceType], +} + +const query = ['test', 'test2'] +const record = new DossierRecord(resultStub) + +const testData: TestData[] = [ + new TestData( + 'queryByIds', + [stringify(query)], + apiClient.fetchJson, + [record], + ['/dossiers?ids=0%3Dtest%261%3Dtest2', false], + Promise.resolve([resultStub]) + ), +] + +describe('dossiersService', () => testDelegation(dossiersRepository, testData)) + +describe('DossiersRepository - search by ids', () => { + it('handles search without errors', () => { + apiClient.fetchJson.mockResolvedValueOnce([resultStub]) + const response = dossiersRepository.queryByIds(query) + response.then((resolvedResponse) => { + expect(resolvedResponse).toEqual([record]) + }) + + expect(apiClient.fetchJson).toHaveBeenCalledWith( + '/dossiers?ids=test&ids=test2', + false + ) + }) + + it('handles different query strings', async () => { + const query2 = ['test2'] + const resultStub2 = { + ...resultStub, + id: 'test2', + description: 'another description', + } + const record2 = new DossierRecord(resultStub2) + apiClient.fetchJson.mockResolvedValueOnce([resultStub, resultStub2]) + const response = dossiersRepository.queryByIds(query2) + response.then((resolvedResponse) => { + expect(resolvedResponse).toEqual([record, record2]) + }) + }) + + it('handles empty response', async () => { + apiClient.fetchJson.mockResolvedValueOnce([]) + const response = dossiersRepository.queryByIds(query) + response.then((resolvedResponse) => { + expect(resolvedResponse).toEqual([]) + }) + }) + + it('handles API errors', async () => { + apiClient.fetchJson.mockRejectedValueOnce(new Error('API Error')) + await expect(dossiersRepository.queryByIds(query)).rejects.toThrow( + 'API Error' + ) + }) +}) diff --git a/src/dossiers/infrastructure/DossiersRepository.ts b/src/dossiers/infrastructure/DossiersRepository.ts new file mode 100644 index 000000000..8fa947430 --- /dev/null +++ b/src/dossiers/infrastructure/DossiersRepository.ts @@ -0,0 +1,19 @@ +import DossierRecord from 'dossiers/domain/DossierRecord' +import Promise from 'bluebird' +import ApiClient from 'http/ApiClient' +import { stringify } from 'query-string' + +export default class DossiersRepository { + private readonly apiClient: ApiClient + + constructor(apiClient: ApiClient) { + this.apiClient = apiClient + } + + queryByIds(query: string[]): Promise { + const queryString = stringify({ ids: query }, { arrayFormat: 'index' }) + return this.apiClient + .fetchJson(`/dossiers?${queryString}`, false) + .then((result) => result.map((data) => new DossierRecord(data))) + } +} diff --git a/src/dossiers/ui/DossierDisplay.test.tsx b/src/dossiers/ui/DossierDisplay.test.tsx new file mode 100644 index 000000000..c3e9b1243 --- /dev/null +++ b/src/dossiers/ui/DossierDisplay.test.tsx @@ -0,0 +1,84 @@ +import React from 'react' +import { render, screen } from '@testing-library/react' +import '@testing-library/jest-dom' +import DossierRecord from 'dossiers/domain/DossierRecord' +import DossiersService from 'dossiers/application/DossiersService' +import { Fragment } from 'fragmentarium/domain/fragment' +import FragmentDossierRecordsDisplay, { + DossierRecordDisplay, + DossierRecordsListDisplay, +} from './DossiersDisplay' +import { Provenances } from 'corpus/domain/provenance' +import { PeriodModifiers, Periods } from 'common/period' +import { fragmentFactory } from 'test-support/fragment-fixtures' + +jest.mock('common/MarkdownAndHtmlToHtml', () => ({ + __esModule: true, + default: ({ markdownAndHtml }: { markdownAndHtml: string }) => ( +
{markdownAndHtml}
+ ), +})) + +const mockRecord = new DossierRecord({ + id: 'test', + description: 'Test description', + isApproximateDate: true, + yearRangeFrom: -500, + yearRangeTo: -470, + relatedKings: [10.2, 11], + provenance: Provenances['Assyria'], + script: { + period: Periods['Neo-Assyrian'], + periodModifier: PeriodModifiers.None, + uncertain: false, + }, + references: ['EDITION', 'DISCUSSION'], +}) + +describe('DossierRecordDisplay', () => { + it('renders correctly with a record', () => { + render() + expect(screen.getByText(mockRecord.toMarkdownString())).toBeInTheDocument() + }) +}) + +describe('DossierRecordsListDisplay', () => { + it('renders an empty component when no records are present', () => { + render() + expect(screen.queryByRole('list')).not.toBeInTheDocument() + }) + + it('renders a list of records', () => { + const records = [ + mockRecord, + new DossierRecord({ ...mockRecord, id: 'test2' }), + ] + render() + + expect(screen.getAllByRole('listitem')).toHaveLength(records.length) + expect(screen.getAllByText('ca. 500 BCE - 470 BCE')).toHaveLength( + records.length + ) + }) +}) + +describe('withData HOC integration', () => { + it('fetches data and passes it to the wrapped component', async () => { + const mockDossiersService = { + queryByIds: jest.fn().mockResolvedValueOnce([mockRecord]), + } + const mockFragment = fragmentFactory.build({ + dossiers: [{ dossierId: 'test', isUncertain: true }], + }) + + render( + + ) + + await screen.findByText(mockRecord.toMarkdownString()) + expect(mockDossiersService.queryByIds).toHaveBeenCalledWith(['test']) + }) +}) diff --git a/src/dossiers/ui/DossiersDisplay.tsx b/src/dossiers/ui/DossiersDisplay.tsx new file mode 100644 index 000000000..76a9758eb --- /dev/null +++ b/src/dossiers/ui/DossiersDisplay.tsx @@ -0,0 +1,72 @@ +import React from 'react' +import DossierRecord from 'dossiers/domain/DossierRecord' +import MarkdownAndHtmlToHtml from 'common/MarkdownAndHtmlToHtml' +import { Fragment } from 'fragmentarium/domain/fragment' +import withData from 'http/withData' +import DossiersService from 'dossiers/application/DossiersService' +import _ from 'lodash' +import Bluebird from 'bluebird' + +export function DossierRecordDisplay({ + record, + index, +}: { + record: DossierRecord + index: string | number +}): JSX.Element { + return ( + + ) +} + +export function DossierRecordsListDisplay({ + data, +}: { + data: { records: readonly DossierRecord[] } +} & React.OlHTMLAttributes): JSX.Element { + const { records } = data + + if (records.length < 1) { + return <> + } + return ( +
    + {records.map((record, index) => ( +
  1. + +
  2. + ))} +
+ ) +} + +const FragmentDossierRecordsDisplay = withData< + unknown, + { + dossiersService: DossiersService + fragment: Fragment + }, + { records: readonly DossierRecord[] } +>( + DossierRecordsListDisplay, + (props) => { + return Bluebird.resolve( + props.dossiersService + .queryByIds([ + ...props.fragment.dossiers.map((record) => record.dossierId), + ]) + .then((records) => ({ records })) + ) + }, + { + watch: (props) => [...props.fragment.dossiers], + filter: (props) => !_.isEmpty(props.fragment.dossiers), + defaultData: () => ({ records: [] }), + } +) + +export default FragmentDossierRecordsDisplay diff --git a/src/fragmentarium/domain/FragmentDtos.ts b/src/fragmentarium/domain/FragmentDtos.ts index 16600e15a..dbffa8065 100644 --- a/src/fragmentarium/domain/FragmentDtos.ts +++ b/src/fragmentarium/domain/FragmentDtos.ts @@ -11,6 +11,7 @@ import { import { ArchaeologyDto } from './archaeologyDtos' import { MuseumKey } from './museum' import { ColophonDto } from 'fragmentarium/domain/Colophon' +import { DossierReference } from 'dossiers/domain/DossierReference' interface MeasureDto { value?: number @@ -116,6 +117,7 @@ export default interface FragmentDto { script: ScriptDto externalNumbers: ExternalNumbers projects: readonly string[] + dossiers: readonly DossierReference[] date?: MesopotamianDateDto datesInText?: readonly MesopotamianDateDto[] archaeology?: Omit & { diff --git a/src/fragmentarium/domain/fragment.ts b/src/fragmentarium/domain/fragment.ts index 645b4065b..52e0f166f 100644 --- a/src/fragmentarium/domain/fragment.ts +++ b/src/fragmentarium/domain/fragment.ts @@ -20,6 +20,7 @@ import { ResearchProject } from 'research-projects/researchProject' import { MesopotamianDate } from 'chronology/domain/Date' import { Archaeology } from './archaeology' import { Colophon } from 'fragmentarium/domain/Colophon' +import { DossierReference } from 'dossiers/domain/DossierReference' export interface FragmentInfo { readonly number: string @@ -106,6 +107,7 @@ interface FragmentProps { archaeology?: Archaeology colophon?: Colophon authorizedScopes?: string[] + dossiers: ReadonlyArray } export class Fragment { @@ -135,6 +137,7 @@ export class Fragment { readonly script: Script, readonly externalNumbers: ExternalNumbers, readonly projects: ReadonlyArray, + readonly dossiers: ReadonlyArray, readonly date?: MesopotamianDate, readonly datesInText?: ReadonlyArray, readonly archaeology?: Archaeology, @@ -167,6 +170,7 @@ export class Fragment { props.script, props.externalNumbers, props.projects, + props.dossiers, props.date, props.datesInText, props.archaeology, diff --git a/src/fragmentarium/ui/fragment/CuneiformFragment.tsx b/src/fragmentarium/ui/fragment/CuneiformFragment.tsx index aa6625ce9..cc60d9a78 100644 --- a/src/fragmentarium/ui/fragment/CuneiformFragment.tsx +++ b/src/fragmentarium/ui/fragment/CuneiformFragment.tsx @@ -16,11 +16,13 @@ import ErrorBoundary from 'common/ErrorBoundary' import { FindspotService } from 'fragmentarium/application/FindspotService' import AfoRegisterService from 'afo-register/application/AfoRegisterService' import { EditorTabs } from 'fragmentarium/ui/fragment/CuneiformFragmentEditor' +import DossiersService from 'dossiers/application/DossiersService' type CuneiformFragmentProps = { fragment: Fragment fragmentService: FragmentService fragmentSearchService: FragmentSearchService + dossiersService: DossiersService afoRegisterService: AfoRegisterService wordService: WordService findspotService: FindspotService @@ -35,6 +37,7 @@ const CuneiformFragment: FunctionComponent = ({ fragment, fragmentService, fragmentSearchService, + dossiersService, afoRegisterService, wordService, findspotService, @@ -53,6 +56,7 @@ const CuneiformFragment: FunctionComponent = ({ @@ -97,6 +101,7 @@ type ControllerProps = { fragment: Fragment fragmentService: FragmentService fragmentSearchService: FragmentSearchService + dossiersService: DossiersService afoRegisterService: AfoRegisterService wordService: WordService findspotService: FindspotService @@ -108,6 +113,7 @@ const CuneiformFragmentController: FunctionComponent = ({ fragment, fragmentService, fragmentSearchService, + dossiersService, afoRegisterService, wordService, findspotService, @@ -145,6 +151,7 @@ const CuneiformFragmentController: FunctionComponent = ({ fragment={currentFragment} fragmentService={fragmentService} fragmentSearchService={fragmentSearchService} + dossiersService={dossiersService} afoRegisterService={afoRegisterService} wordService={wordService} findspotService={findspotService} diff --git a/src/fragmentarium/ui/fragment/FragmentView.tsx b/src/fragmentarium/ui/fragment/FragmentView.tsx index 27bac7a42..6a6df868f 100644 --- a/src/fragmentarium/ui/fragment/FragmentView.tsx +++ b/src/fragmentarium/ui/fragment/FragmentView.tsx @@ -19,6 +19,7 @@ import { Session } from 'auth/Session' import { HeadTags } from 'router/head' import { FindspotService } from 'fragmentarium/application/FindspotService' import AfoRegisterService from 'afo-register/application/AfoRegisterService' +import DossiersService from 'dossiers/application/DossiersService' function TagSignsButton({ number, @@ -40,6 +41,7 @@ type Props = { fragment: Fragment fragmentService: FragmentService fragmentSearchService: FragmentSearchService + dossiersService: DossiersService wordService: WordService findspotService: FindspotService afoRegisterService: AfoRegisterService @@ -67,6 +69,7 @@ function FragmentView({ fragment, fragmentService, fragmentSearchService, + dossiersService, afoRegisterService, wordService, findspotService, @@ -109,6 +112,7 @@ function FragmentView({ fragment={fragment} fragmentService={fragmentService} fragmentSearchService={fragmentSearchService} + dossiersService={dossiersService} wordService={wordService} findspotService={findspotService} activeFolio={activeFolio} diff --git a/src/fragmentarium/ui/info/Details.test.tsx b/src/fragmentarium/ui/info/Details.test.tsx index 28c1a2f4c..d19301f9f 100644 --- a/src/fragmentarium/ui/info/Details.test.tsx +++ b/src/fragmentarium/ui/info/Details.test.tsx @@ -19,13 +19,18 @@ import { joinFactory } from 'test-support/join-fixtures' import { PartialDate } from 'fragmentarium/domain/archaeology' import { Periods } from 'common/period' import FragmentService from 'fragmentarium/application/FragmentService' +import DossiersService from 'dossiers/application/DossiersService' jest.mock('fragmentarium/application/FragmentService') const MockFragmentService = FragmentService as jest.Mock< jest.Mocked > +const MockDossiersService = DossiersService as jest.Mock< + jest.Mocked +> const fragmentService = new MockFragmentService() +const dossiersService = new MockDossiersService() const updateGenres = jest.fn() const updateScript = jest.fn() @@ -44,6 +49,7 @@ async function renderDetails() { updateDate={updateDate} updateDatesInText={updateDatesInText} fragmentService={fragmentService} + dossiersService={dossiersService} /> ) diff --git a/src/fragmentarium/ui/info/Details.tsx b/src/fragmentarium/ui/info/Details.tsx index 789eec8cc..cc823e7b3 100644 --- a/src/fragmentarium/ui/info/Details.tsx +++ b/src/fragmentarium/ui/info/Details.tsx @@ -13,6 +13,8 @@ import Bluebird from 'bluebird' import { MesopotamianDate } from 'chronology/domain/Date' import DatesInTextSelection from 'chronology/ui/DateEditor/DatesInTextSelection' import { DateRange, PartialDate } from 'fragmentarium/domain/archaeology' +import FragmentDossierRecordsDisplay from 'dossiers/ui/DossiersDisplay' +import DossiersService from 'dossiers/application/DossiersService' interface Props { readonly fragment: Fragment @@ -152,6 +154,7 @@ interface DetailsProps { datesInText: readonly MesopotamianDate[] ) => Bluebird readonly fragmentService: FragmentService + readonly dossiersService: DossiersService } function Details({ @@ -161,6 +164,7 @@ function Details({ updateDate, updateDatesInText, fragmentService, + dossiersService, }: DetailsProps): JSX.Element { const findspotString = fragment.archaeology?.findspot?.toString() return ( @@ -194,6 +198,12 @@ function Details({ )}
  • {`Findspot: ${findspotString || '-'}`}
  • +
  • + +
  • ) => void } @@ -29,6 +31,7 @@ interface Props { export default function Info({ fragment, fragmentService, + dossiersService, afoRegisterService, onSave, }: Props): JSX.Element { @@ -49,6 +52,7 @@ export default function Info({ updateDate={updateDate} updateDatesInText={updateDatesInText} fragmentService={fragmentService} + dossiersService={dossiersService} />
    diff --git a/src/index.tsx b/src/index.tsx index 8998d7064..18c4f906a 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -31,6 +31,8 @@ import AfoRegisterService from 'afo-register/application/AfoRegisterService' import './index.sass' import { FindspotService } from 'fragmentarium/application/FindspotService' import { ApiFindspotRepository } from 'fragmentarium/infrastructure/FindspotRepository' +import DossiersService from 'dossiers/application/DossiersService' +import DossiersRepository from 'dossiers/infrastructure/DossiersRepository' if (process.env.REACT_APP_SENTRY_DSN && process.env.NODE_ENV) { SentryErrorReporter.init( @@ -64,6 +66,7 @@ function InjectedApp(): JSX.Element { const bibliographyRepository = new BibliographyRepository(apiClient) const afoRegisterRepository = new AfoRegisterRepository(apiClient) const findspotRepository = new ApiFindspotRepository(apiClient) + const dossiersRepository = new DossiersRepository(apiClient) const bibliographyService = new BibliographyService(bibliographyRepository) const fragmentService = new FragmentService( @@ -87,6 +90,7 @@ function InjectedApp(): JSX.Element { bibliographyService ) const afoRegisterService = new AfoRegisterService(afoRegisterRepository) + const dossiersService = new DossiersService(dossiersRepository) const findspotService = new FindspotService(findspotRepository) return ( ) diff --git a/src/router/fragmentariumRoutes.tsx b/src/router/fragmentariumRoutes.tsx index a5df00dff..0a9aeea14 100644 --- a/src/router/fragmentariumRoutes.tsx +++ b/src/router/fragmentariumRoutes.tsx @@ -22,6 +22,7 @@ import BibliographyService from 'bibliography/application/BibliographyService' import { FindspotService } from 'fragmentarium/application/FindspotService' import AfoRegisterService from 'afo-register/application/AfoRegisterService' import NotFoundPage from 'NotFoundPage' +import DossiersService from 'dossiers/application/DossiersService' function parseStringParam(location: Location, param: string): string | null { const value = parse(location.search)[param] return _.isArray(value) ? value.join('') : value @@ -51,6 +52,7 @@ export default function FragmentariumRoutes({ fragmentService, fragmentSearchService, afoRegisterService, + dossiersService, textService, wordService, findspotService, @@ -65,6 +67,7 @@ export default function FragmentariumRoutes({ wordService: WordService findspotService: FindspotService afoRegisterService: AfoRegisterService + dossiersService: DossiersService signService: SignService bibliographyService: BibliographyService fragmentSlugs?: FragmentSlugs @@ -141,6 +144,7 @@ export default function FragmentariumRoutes({ wordService={wordService} findspotService={findspotService} afoRegisterService={afoRegisterService} + dossiersService={dossiersService} session={session} {...parseFragmentParams(match, location)} /> diff --git a/src/router/router.tsx b/src/router/router.tsx index 871534cf4..f927ce0eb 100644 --- a/src/router/router.tsx +++ b/src/router/router.tsx @@ -32,6 +32,7 @@ import { HelmetProvider } from 'react-helmet-async' import { FindspotService } from 'fragmentarium/application/FindspotService' import Footer from 'Footer' import './router.sass' +import DossiersService from 'dossiers/application/DossiersService' export interface Services { wordService: WordService @@ -43,6 +44,7 @@ export interface Services { markupService: MarkupService cachedMarkupService: CachedMarkupService afoRegisterService: AfoRegisterService + dossiersService: DossiersService findspotService: FindspotService } diff --git a/src/test-support/AppDriver.tsx b/src/test-support/AppDriver.tsx index dc04e688c..ac7b85f94 100644 --- a/src/test-support/AppDriver.tsx +++ b/src/test-support/AppDriver.tsx @@ -35,6 +35,8 @@ import AfoRegisterService from 'afo-register/application/AfoRegisterService' import { FindspotService } from 'fragmentarium/application/FindspotService' import { ApiFindspotRepository } from 'fragmentarium/infrastructure/FindspotRepository' import FakeApi from 'test-support/FakeApi' +import DossiersService from 'dossiers/application/DossiersService' +import DossiersRepository from 'dossiers/infrastructure/DossiersRepository' export function getServices( api: any = FakeApi @@ -48,6 +50,7 @@ export function getServices( markupService: MarkupService cachedMarkupService: CachedMarkupService afoRegisterService: AfoRegisterService + dossiersService: DossiersService findspotService: FindspotService } { const wordRepository = new WordRepository(api) @@ -73,10 +76,12 @@ export function getServices( ) const signsRepository = new SignRepository(api) const afoRegisterRepository = new AfoRegisterRepository(api) + const dossiersRepository = new DossiersRepository(api) const signService = new SignService(signsRepository) const markupService = new MarkupService(api, bibliographyService) const cachedMarkupService = new CachedMarkupService(api, bibliographyService) const afoRegisterService = new AfoRegisterService(afoRegisterRepository) + const dossiersService = new DossiersService(dossiersRepository) const findspotService = new FindspotService(findspotRepository) return { signService, @@ -88,6 +93,7 @@ export function getServices( markupService, cachedMarkupService, afoRegisterService, + dossiersService, findspotService, } } diff --git a/src/test-support/fragment-fixtures.ts b/src/test-support/fragment-fixtures.ts index 7ebc67c0b..2b297af12 100644 --- a/src/test-support/fragment-fixtures.ts +++ b/src/test-support/fragment-fixtures.ts @@ -86,6 +86,7 @@ export const fragmentFactory = Factory.define( externalNumbersFactory.build({}, { transient: { chance } }), associations.projects ?? [], + associations.dossiers ?? [], associations.date ?? new MesopotamianDate({ year: { value: '1' }, diff --git a/src/test-support/test-fragment.ts b/src/test-support/test-fragment.ts index aa4096d2b..556c60daf 100644 --- a/src/test-support/test-fragment.ts +++ b/src/test-support/test-fragment.ts @@ -415,6 +415,7 @@ export const fragmentDto: FragmentDto = { }, externalNumbers, projects: [], + dossiers: [], date: { year: { value: '1' }, month: { value: '1' }, @@ -518,6 +519,7 @@ export const fragment = new Fragment( }, externalNumbers, [], + [], new MesopotamianDate({ year: { value: '1' }, month: { value: '1' },