diff --git a/src/corpus/application/TextService.test.ts b/src/corpus/application/TextService.test.ts index f1c00a78f..613e130b7 100644 --- a/src/corpus/application/TextService.test.ts +++ b/src/corpus/application/TextService.test.ts @@ -20,7 +20,6 @@ import { fragment, fragmentDto, lines } from 'test-support/test-fragment' import BibliographyService from 'bibliography/application/BibliographyService' import { ExtantLines } from 'corpus/domain/extant-lines' import { ChapterDisplay } from 'corpus/domain/chapter' -import textLineFixture, { textLineDto } from 'test-support/lines/text-line' import { chapterDisplayDtoFactory } from 'test-support/chapter-fixtures' import { bibliographyEntryFactory, @@ -202,40 +201,6 @@ const manuscriptsDto = { const textsDto = [textDto] -const matchingLine = { - ...chapterDto.lines[0], - translation: [ - { - language: 'de', - extent: null, - parts: [ - { - text: 'Test text', - type: 'StringPart', - }, - ], - content: [], - }, - ], -} - -const chapterInfoDto = { - id: { - textId: { - genre: 'L', - category: 1, - index: 2, - }, - stage: 'Old Babyblonian', - name: 'My Chapter', - }, - siglums: { '1': 'NinSchb' }, - matchingLines: [matchingLine], - matchingColophonLines: { - '1': [textLineDto], - }, -} - const extantLines: ExtantLines = { NinNA1a: { o: [ @@ -457,40 +422,7 @@ const testData: TestData[] = [ [`${chapterUrl}/manuscripts`, false], Bluebird.resolve(chapterDto.manuscripts) ), - new TestData( - 'searchTransliteration', - ['kur', 0], - apiClient.fetchJson, - { - chapterInfos: [ - { - ...chapterInfoDto, - matchingLines: [ - { - ...chapter.lines[0], - translation: [ - new TranslationLine({ - language: 'de', - extent: null, - parts: [ - { - text: 'Test text', - type: 'StringPart', - }, - ], - content: [], - }), - ], - }, - ], - matchingColophonLines: { '1': [textLineFixture] }, - }, - ], - totalCount: 1, - }, - ['/textsearch?paginationIndex=0&transliteration=kur', false], - Bluebird.resolve({ chapterInfos: [chapterInfoDto], totalCount: 1 }) - ), + new TestData( 'updateAlignment', [chapterId, chapter.alignment], diff --git a/src/corpus/application/TextService.ts b/src/corpus/application/TextService.ts index 892a3ee13..96adbc82e 100644 --- a/src/corpus/application/TextService.ts +++ b/src/corpus/application/TextService.ts @@ -40,8 +40,6 @@ import { fromDto, fromLineDetailsDto, fromManuscriptDto, - fromMatchingColophonLinesDto, - fromMatchingLineDto, fromSiglumAndTransliterationDto, LineVariantDisplayDto, toAlignmentDto, @@ -54,7 +52,6 @@ import TranslationLine from 'transliteration/domain/translation-line' import { NoteLine, NoteLineDto } from 'transliteration/domain/note-line' import { fromTransliterationLineDto } from 'transliteration/application/dtos' import { ParallelLine } from 'transliteration/domain/parallel-line' -import ChapterInfosPagination from 'corpus/domain/ChapterInfosPagination' import { CorpusQuery } from 'query/CorpusQuery' import { CorpusQueryResult } from 'query/QueryResult' import { ChapterSlugs, TextSlugs } from 'router/sitemap' @@ -369,30 +366,6 @@ export default class TextService { .then((dtos) => dtos.map(fromDto)) } - searchTransliteration( - transliteration: string, - paginationIndex: number - ): Bluebird { - return this.apiClient - .fetchJson( - `/textsearch?${stringify({ - transliteration: transliteration, - paginationIndex: paginationIndex, - })}`, - false - ) - .then((result) => { - const chapterInfos = result.chapterInfos.map((dto) => ({ - ...dto, - matchingLines: dto.matchingLines.map(fromMatchingLineDto), - matchingColophonLines: fromMatchingColophonLinesDto( - dto.matchingColophonLines - ), - })) - return { chapterInfos: chapterInfos, totalCount: result.totalCount } - }) - } - searchLemma( lemmaId: string, genre: string | null | undefined = null diff --git a/src/corpus/ui/ChapterLink.tsx b/src/corpus/ui/ChapterLink.tsx deleted file mode 100644 index 631957ae6..000000000 --- a/src/corpus/ui/ChapterLink.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React, { PropsWithChildren } from 'react' -import { Link } from 'react-router-dom' -import { ChapterId } from 'transliteration/domain/chapter-id' -import { stageToAbbreviation } from 'common/period' - -export default function ChapterLink({ - id: { textId, stage, name }, - children, -}: PropsWithChildren<{ - id: ChapterId -}>): JSX.Element { - return ( - - {children} - - ) -} diff --git a/src/fragmentarium/ui/search/ChapterInfoResults.tsx b/src/fragmentarium/ui/search/ChapterInfoResults.tsx deleted file mode 100644 index 51c4d2627..000000000 --- a/src/fragmentarium/ui/search/ChapterInfoResults.tsx +++ /dev/null @@ -1,283 +0,0 @@ -import React, { useState } from 'react' -import { Col, Row } from 'react-bootstrap' -import _ from 'lodash' -import withData from 'http/withData' -import TextService from 'corpus/application/TextService' -import ChapterInfo, { ChapterInfoLine } from 'corpus/domain/ChapterInfo' -import ChapterLink from 'corpus/ui/ChapterLink' -import { ChapterId, chapterIdToString } from 'transliteration/domain/chapter-id' -import Pagination from 'fragmentarium/ui/search/Pagination' -import ChapterInfosPagination from 'corpus/domain/ChapterInfosPagination' -import Bluebird from 'bluebird' -import { Token } from 'transliteration/domain/token' -import { - createColumns, - lineAccFromColumns, -} from 'transliteration/domain/columns' -import lineNumberToString from 'transliteration/domain/lineNumberToString' -import { genreFromAbbr } from 'corpus/ui/Corpus' -import { Markdown } from 'common/Markdown' -import Markup from 'transliteration/ui/markup' -import { TextLine } from 'transliteration/domain/text-line' -import { - createLemmaMap, - LemmaMap, - LineLemmasContext, -} from 'transliteration/ui/LineLemmasContext' -import { ManuscriptLine } from 'corpus/domain/line' -import TranslationLine from 'transliteration/domain/translation-line' - -function DisplayTokens({ - tokens, -}: { - tokens: readonly Token[] - maxColumns?: number -}): JSX.Element { - const columns = createColumns(tokens) - const lineAccumulator = lineAccFromColumns({ columns, highlightLemmas: [] }) - const [lemmaMap, lemmaSetter] = useState( - createLemmaMap(lineAccumulator.lemmas) - ) - return ( - - {lineAccumulator.flatResult} - - ) -} - -function MatchingLine({ - line, - siglums, - id, -}: { - line: ChapterInfoLine - siglums: Record - id: ChapterId -}): JSX.Element { - const ReconstructionToken = ({ - lineNumber, - reconstructionTokens, - }: { - lineNumber: string - reconstructionTokens: readonly Token[] - }) => ( - - {lineNumber}. - - - ) - - const Translation = ({ - translation, - }: { - translation: readonly TranslationLine[] - }) => ( - <> - {translation.map((translation, index) => ( - - - - - - ))} - - ) - - const Manuscripts = ({ - manuscripts, - }: { - manuscripts: readonly ManuscriptLine[] - }) => ( - <> - {manuscripts.map((manuscript, index) => ( - - - - {siglums[String(manuscript.manuscriptId)]}{' '} - {manuscript.labels.join(' ')} {manuscript.number}.{' '} - - - - - ))} - - ) - return ( - <> - {line.variants.map((variant, index) => ( - - - - - - - - - - ))} -
- - ) -} - -function ColophonLine({ - colophonLine, - colophonLineIndex, - siglums, -}: { - colophonLine: readonly TextLine[] - colophonLineIndex: string - siglums: Record -}): JSX.Element { - return ( - <> - {colophonLine.map((line, index) => ( - - {siglums[colophonLineIndex]} {lineNumberToString(line.lineNumber)}{' '} - - {' '} - - - - ))} - - ) -} - -function ChapterInfoResults({ - chapterInfo, -}: { - chapterInfo: ChapterInfo - key: number -}): JSX.Element { - return ( - <> -
- -
- - - {chapterInfo.textName && ( - <> -  >  - - - )} - {' > '} - {chapterIdToString(chapterInfo.id)} - -
-
- {chapterInfo.matchingLines.map((line, index) => ( - - ))} - - {Object.entries(chapterInfo.matchingColophonLines).map( - (colophon, index) => ( - - ) - )} - - - ) -} - -function TransliterationSearchPagination({ - chapterInfosPagination, - searchPagination, - paginationIndex, -}: { - chapterInfosPagination: ChapterInfosPagination - searchPagination: ( - paginationIndex: number - ) => Bluebird - paginationIndex: number -}): JSX.Element { - const Component = ({ - PaginationControlsComponent, - PaginationElementComponent, - }: { - PaginationControlsComponent: JSX.Element - PaginationElementComponent: JSX.Element - }): JSX.Element => ( - <> - - - {PaginationControlsComponent} - - - - {PaginationElementComponent} - - - ) - return ( - - paginationURLParam={'paginationIndexCorpus'} - paginationElements={chapterInfosPagination.chapterInfos} - totalCount={chapterInfosPagination.totalCount} - searchPagination={searchPagination} - paginationIndex={paginationIndex} - renderPagination={( - PaginationControlsComponent, - PaginationElementComponent - ) => ( - - )} - renderPaginationElement={(data, key) => ( - - )} - /> - ) -} - -export default withData< - { - transliteration: string - textService: TextService - paginationIndex: number - }, - { textService: TextService }, - ChapterInfosPagination ->( - ({ transliteration, data, textService, paginationIndex }) => - transliteration && data.chapterInfos.length > 0 ? ( - - textService - .searchTransliteration(transliteration, paginationIndex) - .then((result) => result.chapterInfos) - } - paginationIndex={paginationIndex} - /> - ) : null, - (props) => - props.textService.searchTransliteration(props.transliteration ?? '', 0), - { - watch: (props) => [props.transliteration], - filter: (props) => !_.isEmpty(props.transliteration), - defaultData: () => ({ chapterInfos: [], totalCount: 0 }), - } -) diff --git a/src/fragmentarium/ui/search/CorpusSearch.test.tsx b/src/fragmentarium/ui/search/CorpusSearch.test.tsx deleted file mode 100644 index b9336a851..000000000 --- a/src/fragmentarium/ui/search/CorpusSearch.test.tsx +++ /dev/null @@ -1,175 +0,0 @@ -import React from 'react' -import { Router } from 'react-router-dom' -import { render, screen, waitFor } from '@testing-library/react' -import Promise from 'bluebird' -import Bluebird from 'bluebird' -import SessionContext from 'auth/SessionContext' -import MemorySession, { Session } from 'auth/Session' -import TextService from 'corpus/application/TextService' -import { fromMatchingLineDto } from 'corpus/application/dtos' -import WordService from 'dictionary/application/WordService' -import textLineFixture from 'test-support/lines/text-line' -import { stageToAbbreviation } from 'common/period' -import { DictionaryContext } from 'dictionary/ui/dictionary-context' -import CorpusTransliterationSearch from 'fragmentarium/ui/search/ChapterInfoResults' -import { waitForSpinnerToBeRemoved } from 'test-support/waitForSpinnerToBeRemoved' -import userEvent from '@testing-library/user-event' -import { createMemoryHistory, MemoryHistory } from 'history' -import ChapterInfo from 'corpus/domain/ChapterInfo' - -jest.mock('fragmentarium/application/FragmentSearchService') -jest.mock('corpus/application/TextService') -jest.mock('dictionary/application/WordService') - -let history: MemoryHistory - -const wordService = new (WordService as jest.Mock)() -const session: Session = new MemorySession(['read:fragments']) -let container: HTMLElement - -const corpusResult: ChapterInfo = { - id: { - textId: { - genre: 'L', - category: 1, - index: 2, - }, - stage: 'Old Babylonian', - name: 'My Chapter', - }, - siglums: { '1': 'NinSchb' }, - textName: 'Text Name Test', - matchingLines: [ - fromMatchingLineDto({ - number: '1', - isBeginningOfSection: false, - isSecondLineOfParallelism: false, - translation: [ - { - language: 'de', - extent: null, - parts: [ - { - text: 'Test text', - type: 'StringPart', - }, - ], - content: [], - }, - ], - variants: [ - { - reconstruction: '%n ra', - manuscripts: [ - { - manuscriptId: 1, - labels: ['o', 'iii'], - number: 'a+1', - atf: 'ra', - omittedWords: [], - }, - ], - }, - ], - }), - ], - matchingColophonLines: { - '1': [textLineFixture], - }, -} -const textService = new (TextService as jest.Mock>)() - -async function renderCorpusSearch(transliteration = 'test') { - history = createMemoryHistory() - jest.spyOn(history, 'push') - const container = render( - - - - - - - - ).container - await waitForSpinnerToBeRemoved(screen) - return container -} - -describe('Corpus results', () => { - beforeEach(async () => { - textService.searchTransliteration.mockReturnValue( - Promise.resolve({ chapterInfos: [corpusResult], totalCount: 1 }) - ) - container = await renderCorpusSearch() - }) - - it('Match Snapshot', () => { - expect(container).toMatchSnapshot() - }) - - it('Name links to chapter', async () => { - expect(await screen.findByText('1.')).toHaveAttribute( - 'href', - `/corpus/${corpusResult.id.textId.genre}/${ - corpusResult.id.textId.category - }/${corpusResult.id.textId.index}/${stageToAbbreviation( - corpusResult.id.stage - )}/${corpusResult.id.name}` - ) - }) -}) - -const transliteration = 'LI₂₃ ši₂-ṣa-pel₃-ṭa₃' -const TOTAL_COUNT = 2 -describe('test scrolling through pagination', () => { - beforeEach(async () => { - textService.searchTransliteration - .mockReturnValueOnce( - Bluebird.resolve({ - chapterInfos: [corpusResult], - totalCount: TOTAL_COUNT, - }) - ) - .mockReturnValueOnce( - Bluebird.resolve({ - chapterInfos: [ - { - ...corpusResult, - textName: ' Test Text Name 1', - }, - ], - totalCount: TOTAL_COUNT, - }) - ) - await renderCorpusSearch(transliteration) - }) - it('Inital Render', async () => { - await waitFor(() => - expect(textService.searchTransliteration).toBeCalledWith( - transliteration, - 0 - ) - ) - await screen.findByText(/Text Name Test/) - }) - it('Next Page', async () => { - userEvent.click(screen.getByText('2')) - await waitFor(() => - expect(history.push).toHaveBeenCalledWith({ - search: 'paginationIndexCorpus=1', - }) - ) - await waitFor(() => - expect(textService.searchTransliteration).toBeCalledWith( - transliteration, - 1 - ) - ) - await screen.findByText(/Test Text Name 1/) - expect(screen.queryByText(/Text Name Test/)).not.toBeInTheDocument() - }) -}) diff --git a/src/fragmentarium/ui/search/Pagination.tsx b/src/fragmentarium/ui/search/Pagination.tsx deleted file mode 100644 index f9db58bf8..000000000 --- a/src/fragmentarium/ui/search/Pagination.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import _ from 'lodash' -import React, { useEffect, useMemo, useState } from 'react' -import PaginationItems from 'fragmentarium/ui/search/PaginationItems' -import Bluebird from 'bluebird' -import withData from 'http/withData' - -type renderPaginationElement = ( - data: PaginationElement, - key: number -) => React.ReactElement<{ data: PaginationElement; key: number }> - -interface Props { - paginationElements: readonly PaginationElement[] - totalCount: number - searchPagination: ( - paginationIndex: number - ) => Bluebird - paginationIndex: number - renderPagination: ( - PaginationControlsComponent: JSX.Element, - PaginationElementComponent: JSX.Element - ) => React.ReactElement<{ - PaginationControlsComponent: JSX.Element - PaginationElementComponent: JSX.Element - }> - renderPaginationElement: renderPaginationElement - paginationURLParam: string -} - -export default function Pagination({ - paginationURLParam, - paginationElements, - totalCount, - searchPagination, - paginationIndex, - renderPagination, - renderPaginationElement, -}: Props): JSX.Element { - const [activePage, setActivePage] = useState(paginationIndex) - const [savedPaginationElements, setSavedPaginationElements] = useState([ - { - paginationElements: paginationElements, - paginationIndex: paginationIndex, - }, - ]) - - const lastPage = - totalCount > 0 ? Math.ceil(totalCount / paginationElements.length) - 1 : 0 - - const findPaginationElements = ( - index: number - ): readonly PaginationElement[] | null => { - const found = _.find(savedPaginationElements, { - paginationIndex: index, - }) - return found ? found.paginationElements : null - } - - const fetchAndSavePaginationElements = ( - paginationIndex: number - ): Bluebird => - searchPagination(paginationIndex).then((paginationElements) => { - setSavedPaginationElements((stored) => [ - ...stored, - { - paginationElements: paginationElements, - paginationIndex: paginationIndex, - }, - ]) - return paginationElements - }) - useEffect(() => { - const succeeding = activePage + 1 - if (!findPaginationElements(succeeding) && succeeding <= lastPage) { - fetchAndSavePaginationElements(succeeding) - } - }, [ - activePage, - findPaginationElements, - fetchAndSavePaginationElements, - lastPage, - ]) - - const DisplayActivePage = withData< - { - paginationElements: readonly PaginationElement[] | null - searchPagination: ( - paginationIndex: number - ) => Bluebird - activePage: number - render: renderPaginationElement - }, - { - searchPagination: ( - paginationIndex: number - ) => Bluebird - }, - readonly PaginationElement[] - >( - ({ data, render }) => ( - <> - {data.map((paginationElement, index) => - render(paginationElement, index) - )} - - ), - (props) => props.searchPagination(props.activePage), - { - filter: (props) => _.isNil(props.paginationElements), - defaultData: (props) => props.paginationElements, - } - ) - - const displayActivePageMemo = useMemo( - () => ( - - ), - [activePage] - ) - - return ( - <> - {renderPagination( - , - displayActivePageMemo - )} - - ) -} diff --git a/src/fragmentarium/ui/search/__snapshots__/CorpusSearch.test.tsx.snap b/src/fragmentarium/ui/search/__snapshots__/CorpusSearch.test.tsx.snap deleted file mode 100644 index b8339bd3b..000000000 --- a/src/fragmentarium/ui/search/__snapshots__/CorpusSearch.test.tsx.snap +++ /dev/null @@ -1,405 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Corpus results Match Snapshot 1`] = ` -
-
-
-
    -
  • - - 1 - - (current) - - -
  • -
-
-
-
-
-
-
-
- - - Literature - -  >  - - Text Name Test - - > - Old Babylonian My Chapter - -
-
-
- - - 1 - . - - -
-
-
-
-
- - Test text - -
-
-
-
-
- -
- NinSchb - - o iii - - a+1 - . - -
-
-
-
- -
- NinSchb - - 1 - - - - - - - - - - - érin - - - - - - - - - - - - - - - [ - - - - - ( - - - - - - - ŠÁ - - - - - - - - - - - - - - - - - - šà - - - - - - - / - - - - - GÌRI - - - - - - - - - - ) - - - - - - - - - - - - - - - - kur - - - - - - - - - - - - - - - - - - - - saḫ - - - - - - - - - - - - - - - - - SAḪ - - - - - - - - - - - - - - … - - - - ] - - - -
-
-
-
-
-`;