Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Vas9ka committed Feb 22, 2024
1 parent bb29585 commit db1d0ba
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/fragmentarium/application/FragmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface FragmentRepository {
): Bluebird<Fragment>
findInCorpus(number: string): Bluebird<ReadonlyArray<ManuscriptAttestation>>
fetchGenres(): Bluebird<string[][]>
fetchArchaeologies(): Bluebird<string[][]>
fetchProvenances(): Bluebird<string[][]>
fetchPeriods(): Bluebird<string[]>
updateGenres(number: string, genres: Genres): Bluebird<Fragment>
updateScript(number: string, script: Script): Bluebird<Fragment>
Expand Down Expand Up @@ -177,8 +177,8 @@ export class FragmentService {
fetchGenres(): Bluebird<string[][]> {
return this.fragmentRepository.fetchGenres()
}
fetchArchaeologies(): Bluebird<string[][]> {
return this.fragmentRepository.fetchArchaeologies()
fetchProvenances(): Bluebird<string[][]> {
return this.fragmentRepository.fetchProvenances()
}

fetchPeriods(): Bluebird<string[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/infrastructure/FragmentRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ApiFragmentRepository
fetchGenres(): Promise<string[][]> {
return this.apiClient.fetchJson('/genres', false)
}
fetchArchaeologies(): Promise<string[][]> {
fetchProvenances(): Promise<string[][]> {
return this.apiClient.fetchJson('/provenances', false)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.archaeology-selector
.provenance-selector
&__menu
z-index: 99 !important
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import withData from 'http/withData'
import Select from 'react-select'
import FragmentService from 'fragmentarium/application/FragmentService'
import './ArchaeologySearchForm.sass'
import './ProvenanceSearchForm.sass'

export default withData<
{
Expand All @@ -13,26 +13,26 @@ export default withData<
ReadonlyArray<ReadonlyArray<string>>
>(
({ data, value, onChange }) => {
const options = data.map((archaeology) => ({
value: archaeology[0],
label: archaeology[0],
const options = data.map((site) => ({
value: site.join(' '),
label: site.join(' '),
}))
const defaultOption = value ? { value: value, label: value } : null

return (
<Select
aria-label="select-archaeology"
aria-label="select-provenance"
placeholder="Provenance"
options={options}
value={defaultOption}
onChange={(selection) => {
onChange(selection?.value || null)
}}
isSearchable={true}
classNamePrefix={'archaeology-selector'}
classNamePrefix={'provenance-selector'}
isClearable
/>
)
},
(props) => props.fragmentService.fetchArchaeologies()
(props) => props.fragmentService.fetchProvenances()
)
8 changes: 3 additions & 5 deletions src/fragmentarium/ui/SearchForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ beforeEach(async () => {
Promise.resolve(Object.keys(Periods))
)
fragmentService.fetchGenres.mockReturnValue(Promise.resolve(genres))
fragmentService.fetchArchaeologies.mockReturnValue(
Promise.resolve(provenances)
)
fragmentService.fetchProvenances.mockReturnValue(Promise.resolve(provenances))
wordService.searchLemma.mockReturnValue(Promise.resolve([word]))
wordService.findAll.mockReturnValue(Promise.resolve([]))
session.isAllowedToReadFragments.mockReturnValue(true)
Expand Down Expand Up @@ -228,11 +226,11 @@ describe('Script period selection form', () => {

describe('Provenance selection form', () => {
beforeEach(() => {
userEvent.type(screen.getByLabelText('select-archaeology'), 'Assur')
userEvent.type(screen.getByLabelText('select-provenance'), 'Assur')
})
it('displays user input', async () => {
await waitFor(() =>
expect(screen.getByLabelText('select-archaeology')).toHaveValue('Assur')
expect(screen.getByLabelText('select-provenance')).toHaveValue('Assur')
)
})

Expand Down
8 changes: 4 additions & 4 deletions src/fragmentarium/ui/SearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
import GenreSearchForm from './GenreSearchForm'
import BibliographyService from 'bibliography/application/BibliographyService'
import { ResearchProjects } from 'research-projects/researchProject'
import ArchaeologySearchForm from './ArchaeologySearchForm'
import ProvenanceSearchForm from './ProvenanceSearchForm'

interface State {
number: string | null
Expand Down Expand Up @@ -85,7 +85,7 @@ class SearchForm extends Component<Props, State> {
scriptPeriod: fragmentQuery.scriptPeriod || '',
scriptPeriodModifier: fragmentQuery.scriptPeriodModifier || '',
genre: fragmentQuery.genre || '',
site: fragmentQuery.archaeology || '',
site: fragmentQuery.provenance || '',
isValid: isValidNumber(fragmentQuery.number),
}

Expand Down Expand Up @@ -141,7 +141,7 @@ class SearchForm extends Component<Props, State> {
: '',
scriptPeriod: state.scriptPeriod,
genre: state.genre,
site: state.site,
site: state.site ? state.site.split(' ')[0] : '',
project: this.props.project,
},
(value) => !value
Expand Down Expand Up @@ -244,7 +244,7 @@ class SearchForm extends Component<Props, State> {
<HelpTrigger overlay={ProvenanceSearchHelp()} />
</Col>
<Col>
<ArchaeologySearchForm
<ProvenanceSearchForm
fragmentService={this.props.fragmentService}
onChange={this.onChange('site')}
value={this.state.site}
Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/front-page/Fragmentarium.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ beforeEach(() => {
wordService.findAll.mockReturnValue(Promise.resolve([]))
fragmentService.fetchPeriods.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchGenres.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchArchaeologies.mockRejectedValueOnce(Promise.resolve([]))
fragmentService.fetchProvenances.mockRejectedValueOnce(Promise.resolve([]))
})

describe('Statistics', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/fragmentarium/ui/search/FragmentariumSearch.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ beforeEach(async () => {
session = new MemorySession(['read:fragments'])
fragmentService.fetchPeriods.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchGenres.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchArchaeologies.mockReturnValueOnce(Promise.resolve([]))
fragmentService.fetchProvenances.mockReturnValueOnce(Promise.resolve([]))
})

describe('Search', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/query/FragmentQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type FragmentQuery = Partial<{
scriptPeriod: PeriodString
scriptPeriodModifier: PeriodModifierString
genre: string
archaeology: string
provenance: string
project: keyof typeof ResearchProjects | null
latest: boolean
}>

0 comments on commit db1d0ba

Please sign in to comment.