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

Revise 'About' Section #426

Merged
merged 24 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
181 changes: 154 additions & 27 deletions src/about/ui/bibliography.tsx

Large diffs are not rendered by default.

771 changes: 530 additions & 241 deletions src/about/ui/fragmentarium.tsx

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/bibliography/application/BibliographyService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jest.mock('bibliography/infrastructure/BibliographyRepository', () => {
return function () {
return {
find: jest.fn(),
findMany: jest.fn(),
search: jest.fn(),
update: jest.fn(),
create: jest.fn(),
Expand All @@ -20,6 +21,9 @@ const bibliographyService = new BibliographyService(bibliographyRepository)

const testData: TestData<BibliographyService>[] = [
new TestData('find', ['RN2020'], bibliographyRepository.find, [resultStub]),
new TestData('findMany', [['RN2020']], bibliographyRepository.findMany, [
[resultStub],
]),
new TestData('update', [resultStub], bibliographyRepository.update, [
resultStub,
]),
Expand Down
4 changes: 4 additions & 0 deletions src/bibliography/application/BibliographyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default class BibliographyService implements BibliographySearch {
return this.bibliographyRepository.find(id)
}

findMany(ids: readonly string[]): Promise<readonly BibliographyEntry[]> {
return this.bibliographyRepository.findMany(ids)
}

update(entry: BibliographyEntry): Promise<BibliographyEntry> {
return this.bibliographyRepository.update(entry)
}
Expand Down
15 changes: 15 additions & 0 deletions src/bibliography/infrastructure/BibliographyRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { testDelegation, TestData } from 'test-support/utils'
import BibliographyRepository from './BibliographyRepository'
import BibliographyEntry from 'bibliography/domain/BibliographyEntry'
import ApiClient from 'http/ApiClient'
import { stringify } from 'query-string'

jest.mock('http/ApiClient')

Expand All @@ -25,6 +26,20 @@ const testData: TestData<BibliographyRepository>[] = [
[`/bibliography/${encodeURIComponent(id)}`, false],
Promise.resolve(resultStub)
),
new TestData(
'findMany',
[[id]],
apiClient.fetchJson,
[entry],
[
`/bibliography/list?${stringify(
{ ids: [id] },
{ arrayFormat: 'comma' }
)}`,
false,
],
Promise.resolve([resultStub])
),
new TestData(
'search',
[query],
Expand Down
10 changes: 10 additions & 0 deletions src/bibliography/infrastructure/BibliographyRepository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BibliographyEntry from 'bibliography/domain/BibliographyEntry'
import Promise from 'bluebird'
import ApiClient from 'http/ApiClient'
import { stringify } from 'query-string'

function createEntry(cslData) {
return new BibliographyEntry(cslData)
Expand All @@ -19,6 +20,15 @@ export default class BibliographyRepository {
.then(createEntry)
}

findMany(ids: readonly string[]): Promise<readonly BibliographyEntry[]> {
return this.apiClient
.fetchJson(
`/bibliography/list?${stringify({ ids }, { arrayFormat: 'comma' })}`,
false
)
.then((result) => result.map(createEntry))
}

search(query: string): Promise<BibliographyEntry[]> {
return this.apiClient
.fetchJson(`/bibliography?query=${encodeURIComponent(query)}`, false)
Expand Down
6 changes: 6 additions & 0 deletions src/common/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ export function Markdown({
</ReactMarkdown>
)
}

export function MarkdownParagraph(
props: Omit<MarkdownProps, 'paragraph'>
): JSX.Element {
return <Markdown paragraph={'p'} {...props} />
}
45 changes: 33 additions & 12 deletions src/corpus/application/TextService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ChapterDisplay } from 'corpus/domain/chapter'
import textLineFixture, { textLineDto } from 'test-support/lines/text-line'
import { chapterDisplayDtoFactory } from 'test-support/chapter-fixtures'
import {
bibliographyEntryFactory,
cslDataFactory,
referenceDtoFactory,
referenceFactory,
Expand Down Expand Up @@ -582,8 +583,28 @@ test('inject ChapterDisplay', async () => {
}
}

const translationReference = referenceFactory.build()
const intertextReference = referenceFactory.build()
const translationReference = referenceFactory.build(
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.

{},
{
associations: {
document: bibliographyEntryFactory.build(
{},
{ associations: { id: 'XY1' } }
),
},
}
)
const intertextReference = referenceFactory.build(
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.

{},
{
associations: {
document: bibliographyEntryFactory.build(
{},
{ associations: { id: 'XY2' } }
),
},
}
)
const chapterWithReferences = produce(chapterDisplay, (draft) => {
draft.lines[0].translation[0].parts = [
createInjectedPart(translationReference),
Expand All @@ -607,11 +628,11 @@ test('inject ChapterDisplay', async () => {
]
})
apiClient.fetchJson.mockReturnValue(Bluebird.resolve(chapterWithReferences))
bibliographyServiceMock.find.mockReturnValueOnce(
Bluebird.resolve(translationReference.document)
bibliographyServiceMock.findMany.mockReturnValueOnce(
Bluebird.resolve([translationReference.document])
)
bibliographyServiceMock.find.mockReturnValueOnce(
Bluebird.resolve(intertextReference.document)
bibliographyServiceMock.findMany.mockReturnValueOnce(
Bluebird.resolve([intertextReference.document])
)
await expect(testService.findChapterDisplay(chapterId)).resolves.toEqual(
injectedChapter
Expand All @@ -620,12 +641,12 @@ test('inject ChapterDisplay', async () => {
`${chapterUrl}/display`,
false
)
expect(bibliographyServiceMock.find).toHaveBeenCalledWith(
translationReference.id
)
expect(bibliographyServiceMock.find).toHaveBeenCalledWith(
intertextReference.id
)
expect(bibliographyServiceMock.findMany).toHaveBeenCalledWith([
translationReference.id,
])
expect(bibliographyServiceMock.findMany).toHaveBeenCalledWith([
intertextReference.id,
])
})

test('listAllTexts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`Show manuscript line details 1`] = `
<span
class="reference-popover__citation"
>
Estrada & Wolfe, 2068: 7477711662481408-4847418310918144
Estrada & Wolfe, 2069: 7477711662481408-4847418310918144
[
l. 4'.2., 3'.
]
Expand Down
5 changes: 4 additions & 1 deletion src/fragmentarium/application/FragmentService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jest.mock('./LemmatizationFactory')

jest.mock('bibliography/application/BibliographyService', () => {
return function () {
return { find: jest.fn(), search: jest.fn() }
return { find: jest.fn(), findMany: jest.fn(), search: jest.fn() }
}
})

Expand Down Expand Up @@ -229,6 +229,9 @@ describe('methods returning fragment', () => {
bibliographyService.find.mockImplementation((id: string) =>
Promise.reject(new Error(`${id} not found.`))
)
bibliographyService.findMany.mockImplementation((ids: string[]) =>
Promise.reject(new Error(`${ids} not found.`))
)
silenceConsoleErrors()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ exports[`Snapshot 1`] = `
,

<time
datetime="2096-10-04"
datetime="2097-10-04"
>
4/10/2096
4/10/2097
</time>
)
</li>
Expand Down Expand Up @@ -108,7 +108,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
Fanti & Carr, 2036: 8970824935538688-3796097900216320
Fanti & Carr, 2037: 8970824935538688-3796097900216320
[
l. 4'.2., 2.
]
Expand All @@ -123,7 +123,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
Hall & Reid, 2089: 7020923936833536-4895425479835648
Hall & Reid, 2090: 7020923936833536-4895425479835648
[
l. 4'.2., 3'.
]
Expand Down Expand Up @@ -5906,7 +5906,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
White & Manca, 2070: 6525764484726784-1000123435843584
White & Manca, 2071: 6525764484726784-1000123435843584
[
l. 3'., 2.
]
Expand All @@ -5925,7 +5925,7 @@ exports[`Snapshot 1`] = `
<span
class="reference-popover__citation"
>
Martinez & Robin, 2112: 5946678584541184-5595938733162496
Martinez & Robin, 2113: 5946678584541184-5595938733162496
[
l. 3'., 4'.2.
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Giles & Alvarez, 2086: 5582194326110208-1406653725409280
Giles & Alvarez, 2087: 5582194326110208-1406653725409280
[
l. 1., 3'.
]
Expand All @@ -792,7 +792,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Shaw & Robert, 2045: 6150545542742016-5917511180615680
Shaw & Robert, 2046: 6150545542742016-5917511180615680
[
l. 2., 1.
]
Expand Down Expand Up @@ -6565,7 +6565,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Harrison & Palmieri, 2028: 5188341634957312-4059361584349184
Harrison & Palmieri, 2029: 5188341634957312-4059361584349184
[
l. 1., 2.
]
Expand All @@ -6584,7 +6584,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli
<span
class="reference-popover__citation"
>
Wise & Hudson, 2039: 1529496131862528-4383736143544320
Wise & Hudson, 2040: 1529496131862528-4383736143544320
[
l. 4'.2., 2.
]
Expand Down
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import { scopeString, useAuthentication } from 'auth/Auth'
import SignService from 'signs/application/SignService'
import SignRepository from 'signs/infrastructure/SignRepository'
import AfoRegisterRepository from 'afo-register/infrastructure/AfoRegisterRepository'
import MarkupService from 'markup/application/MarkupService'
import MarkupService, {
CachedMarkupService,
} from 'markup/application/MarkupService'
import AfoRegisterService from 'afo-register/application/AfoRegisterService'
import './index.sass'
import { FindspotService } from 'fragmentarium/application/FindspotService'
Expand Down Expand Up @@ -80,6 +82,10 @@ function InjectedApp(): JSX.Element {
)
const signService = new SignService(signsRepository)
const markupService = new MarkupService(apiClient, bibliographyService)
const cachedMarkupService = new CachedMarkupService(
apiClient,
bibliographyService
)
const afoRegisterService = new AfoRegisterService(afoRegisterRepository)
const findspotService = new FindspotService(findspotRepository)
return (
Expand All @@ -91,6 +97,7 @@ function InjectedApp(): JSX.Element {
bibliographyService={bibliographyService}
textService={textService}
markupService={markupService}
cachedMarkupService={cachedMarkupService}
afoRegisterService={afoRegisterService}
findspotService={findspotService}
/>
Expand Down
21 changes: 19 additions & 2 deletions src/markup/application/MarkupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { MarkupPart } from 'transliteration/domain/markup'
import { stringify } from 'query-string'

export default class MarkupService {
private readonly referenceInjector: ReferenceInjector
protected readonly referenceInjector: ReferenceInjector
constructor(
private readonly apiClient: ApiClient,
protected readonly apiClient: ApiClient,
bibliographyService: BibliographyService
) {
this.referenceInjector = new ReferenceInjector(bibliographyService)
Expand Down Expand Up @@ -42,3 +42,20 @@ export default class MarkupService {
return this.referenceInjector.injectReferencesToMarkup(parts)
}
}

export class CachedMarkupService extends MarkupService {
fromString(text: string): Bluebird<readonly MarkupPart[]> {
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.

return this.apiClient
.fetchJson(
`/cached-markup?${stringify({
text: text,
})}`,
false
)
.then((parts) => {
return Bluebird.all(
parts && Bluebird.all(this.injectReferencesToMarkup(parts))
)
})
}
}
8 changes: 4 additions & 4 deletions src/router/aboutRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React, { ReactNode } from 'react'
import { Redirect, Route, RouteComponentProps } from 'react-router-dom'
import About, { TabId, tabIds } from 'about/ui/about'
import MarkupService from 'markup/application/MarkupService'
import { CachedMarkupService } from 'markup/application/MarkupService'
import { sitemapDefaults } from 'router/sitemap'
import { HeadTagsService } from 'router/head'

export default function AboutRoutes({
sitemap,
markupService,
cachedMarkupService,
}: {
sitemap: boolean
markupService: MarkupService
cachedMarkupService: CachedMarkupService
}): JSX.Element[] {
return [
<Route
Expand All @@ -23,7 +23,7 @@ export default function AboutRoutes({
description="This section provides detailed information about the electronic Babylonian Library (eBL) and the materials and tools available."
>
<About
markupService={markupService}
markupService={cachedMarkupService}
activeTab={props.match.params.id as TabId}
/>
</HeadTagsService>
Expand Down
5 changes: 4 additions & 1 deletion src/router/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import FragmentService from 'fragmentarium/application/FragmentService'
import FragmentSearchService from 'fragmentarium/application/FragmentSearchService'
import BibliographyService from 'bibliography/application/BibliographyService'
import TextService from 'corpus/application/TextService'
import MarkupService from 'markup/application/MarkupService'
import MarkupService, {
CachedMarkupService,
} from 'markup/application/MarkupService'
import SignService from 'signs/application/SignService'
import AfoRegisterService from 'afo-register/application/AfoRegisterService'

Expand All @@ -33,6 +35,7 @@ export interface Services {
textService: TextService
signService: SignService
markupService: MarkupService
cachedMarkupService: CachedMarkupService
afoRegisterService: AfoRegisterService
findspotService: FindspotService
}
Expand Down
Loading
Loading