Skip to content

Commit

Permalink
Add broken & uncertain in king & eponym (WiP), refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
khoidt committed Jan 25, 2024
1 parent eedbcde commit be23064
Show file tree
Hide file tree
Showing 29 changed files with 238 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/chronology/application/DateConverterFormChange.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DateConverter from 'chronology/domain/DateConverter'
import { CalendarProps } from 'chronology/domain/DateConverterBase'
import { FormChangeProps } from 'chronology/ui/DateConverterForm'
import { FormChangeProps } from 'chronology/ui/DateConverter/DateConverterForm'

export function handleDateConverterFormChange({
event,
Expand Down
2 changes: 1 addition & 1 deletion src/chronology/application/DateSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DateDisplay from 'chronology/ui/DateDisplay'
import {
DateOptionsInput,
DateInputGroups,
} from 'chronology/ui/DateSelectionInput'
} from 'chronology/ui/DateEditor/DateSelectionInput'
import useDateSelectionState, {
DateEditorStateProps,
} from 'chronology/application/DateSelectionState'
Expand Down
2 changes: 1 addition & 1 deletion src/chronology/application/DateSelectionInputConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DateOptionsProps } from 'chronology/ui/DateSelectionInput'
import { DateOptionsProps } from 'chronology/ui/DateEditor/DateSelectionInput'

interface Config {
id: string
Expand Down
66 changes: 53 additions & 13 deletions src/chronology/application/DateSelectionState.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { MesopotamianDate } from 'chronology/domain/Date'
import { Ur3Calendar } from 'chronology/domain/DateBase'
import { King } from 'chronology/ui/BrinkmanKings'
import { KingDateField } from 'chronology/domain/DateBase'
import usePromiseEffect from 'common/usePromiseEffect'
import { Eponym } from 'chronology/ui/Eponyms'
import { Eponym } from 'chronology/ui/DateEditor/Eponyms'
import { useState } from 'react'
import Bluebird from 'bluebird'
import { Fragment } from 'fragmentarium/domain/fragment'
Expand Down Expand Up @@ -59,12 +59,25 @@ interface DateConditionParams {
setIsCalenderFieldDisplayed: React.Dispatch<React.SetStateAction<boolean>>
}

interface AdditionalDateStateParams extends DateConditionParams {
king: King | undefined
eponym: Eponym | undefined
ur3Calendar: Ur3Calendar | undefined
setKing: React.Dispatch<React.SetStateAction<King | undefined>>
interface KingAndEponymDateParams {
king?: KingDateField | undefined
eponym?: Eponym | undefined
setKing: React.Dispatch<React.SetStateAction<KingDateField | undefined>>
setEponym: React.Dispatch<React.SetStateAction<Eponym | undefined>>
kingBroken?: boolean
kingUncertain?: boolean
eponymBroken?: boolean
eponymUncertain?: boolean
setKingBroken: React.Dispatch<React.SetStateAction<boolean>>
setKingUncertain: React.Dispatch<React.SetStateAction<boolean>>
setEponymBroken: React.Dispatch<React.SetStateAction<boolean>>
setEponymUncertain: React.Dispatch<React.SetStateAction<boolean>>
}

interface AdditionalDateStateParams
extends DateConditionParams,
KingAndEponymDateParams {
ur3Calendar: Ur3Calendar | undefined
setUr3Calendar: React.Dispatch<React.SetStateAction<Ur3Calendar | undefined>>
}

Expand Down Expand Up @@ -158,21 +171,48 @@ function useDateConditionParams(date?: MesopotamianDate): DateConditionParams {
}
}

function useKingAndEponymDateParams(
date?: MesopotamianDate
): KingAndEponymDateParams {
const [king, setKing] = useState<KingDateField | undefined>(date?.king)
const [eponym, setEponym] = useState<Eponym | undefined>(date?.eponym)
const [kingBroken, setKingBroken] = useState(date?.king?.isBroken ?? false)
const [kingUncertain, setKingUncertain] = useState(
date?.king?.isUncertain ?? false
)
const [eponymBroken, setEponymBroken] = useState(
date?.king?.isBroken ?? false
)
const [eponymUncertain, setEponymUncertain] = useState(
date?.king?.isUncertain ?? false
)
return {
king,
setKing,
eponym,
setEponym,
kingBroken,
setKingBroken,
kingUncertain,
setKingUncertain,
eponymBroken,
setEponymBroken,
eponymUncertain,
setEponymUncertain,
}
}

function useAdditionalDateParams(
date?: MesopotamianDate
): AdditionalDateStateParams {
const [king, setKing] = useState<King | undefined>(date?.king)
const [eponym, setEponym] = useState<Eponym | undefined>(date?.eponym)
const [ur3Calendar, setUr3Calendar] = useState<Ur3Calendar | undefined>(
date?.ur3Calendar ?? undefined
)

return {
...useDateConditionParams(date),
king,
eponym,
...useKingAndEponymDateParams(date),
ur3Calendar,
setKing,
setEponym,
setUr3Calendar,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/chronology/domain/Date.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Eponym } from 'chronology/ui/Eponyms'
import { Eponym } from 'chronology/ui/DateEditor/Eponyms'
import { MesopotamianDate } from 'chronology/domain/Date'
import { Ur3Calendar } from 'chronology/domain/DateBase'

Expand Down
22 changes: 16 additions & 6 deletions src/chronology/domain/DateBase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { King } from 'chronology/ui/BrinkmanKings'
import { Eponym } from 'chronology/ui/Eponyms'
import { King } from 'chronology/ui/BrinkmanKings/BrinkmanKings'
import { Eponym } from 'chronology/ui/DateEditor/Eponyms'
import DateConverter from 'chronology/domain/DateConverter'
import data from 'chronology/domain/dateConverterData.json'
import _ from 'lodash'
Expand All @@ -19,6 +19,16 @@ export interface MonthField extends DateField {
isIntercalary?: boolean
}

export interface KingDateField extends King {
isBroken?: boolean
isUncertain?: boolean
}

export interface EponymDateField extends Eponym {
isBroken?: boolean
isUncertain?: boolean
}

export enum Ur3Calendar {
ADAB = 'Adab',
GIRSU = 'Girsu',
Expand All @@ -33,8 +43,8 @@ export class MesopotamianDateBase {
year: DateField
month: MonthField
day: DateField
king?: King
eponym?: Eponym
king?: KingDateField
eponym?: EponymDateField
isSeleucidEra?: boolean
isAssyrianDate?: boolean
ur3Calendar?: Ur3Calendar
Expand All @@ -43,8 +53,8 @@ export class MesopotamianDateBase {
year: DateField,
month: MonthField,
day: DateField,
king?: King,
eponym?: Eponym,
king?: KingDateField,
eponym?: EponymDateField,
isSeleucidEra?: boolean,
isAssyrianDate?: boolean,
ur3Calendar?: Ur3Calendar
Expand Down
7 changes: 5 additions & 2 deletions src/chronology/domain/DateConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import DateConverterBase, {
monthNames,
} from 'chronology/domain/DateConverterBase'
import DateConverterChecks from 'chronology/domain/DateConverterChecks'
import { King, findKingsByOrderGlobal } from 'chronology/ui/BrinkmanKings'
import {
King,
findKingByOrderGlobal,
} from 'chronology/ui/BrinkmanKings/BrinkmanKings'

export default class DateConverter extends DateConverterBase {
checks: DateConverterChecks = new DateConverterChecks()
Expand Down Expand Up @@ -46,7 +49,7 @@ export default class DateConverter extends DateConverterBase {
ruler = ruler ?? this.calendar?.ruler
if (ruler) {
const orderGlobal = data.rulerToBrinkmanKings[ruler]
return findKingsByOrderGlobal(orderGlobal)
return findKingByOrderGlobal(orderGlobal)
}
return null
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BrinkmanKingsTable from 'chronology/ui/BrinkmanKings'
import BrinkmanKingsTable from 'chronology/ui/BrinkmanKings/BrinkmanKings'

test('Snapshot', () => {
expect(BrinkmanKingsTable()).toMatchSnapshot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import React, { Fragment } from 'react'

import Table from 'react-bootstrap/Table'
import _ from 'lodash'
import 'chronology/ui/BrinkmanKings.sass'
import 'chronology/ui/BrinkmanKings/BrinkmanKings.sass'
import BrinkmanKings from 'chronology/domain/BrinkmanKings.json'
import { Popover } from 'react-bootstrap'
import HelpTrigger from 'common/HelpTrigger'
import Select, { ValueType } from 'react-select'
import { KingDateField } from 'chronology/domain/DateBase'

export interface King {
orderGlobal: number
Expand All @@ -22,11 +23,11 @@ export interface King {

const dynasties: string[] = _.uniq(_.map(BrinkmanKings, 'dynastyName'))

function getKingsByDynasty(dynastyName: string): King[] {
function getKingsByDynasty(dynastyName: string): King[] | KingDateField[] {
return _.filter(BrinkmanKings, ['dynastyName', dynastyName])
}

export function findKingsByOrderGlobal(orderGlobal: number): King | null {
export function findKingByOrderGlobal(orderGlobal: number): King | null {
const king = _.find(BrinkmanKings, ['orderGlobal', orderGlobal])
return king ?? null
}
Expand Down Expand Up @@ -104,7 +105,7 @@ export function KingField({
setKing,
setIsCalenderFieldDisplayed,
}: {
king?: King
king?: King | KingDateField
setKing: React.Dispatch<React.SetStateAction<King | undefined>>
setIsCalenderFieldDisplayed?: React.Dispatch<React.SetStateAction<boolean>>
}): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Markdown } from 'common/Markdown'
import BrinkmanKingsTable from 'chronology/ui/BrinkmanKings'
import BrinkmanKingsTable from 'chronology/ui/BrinkmanKings/BrinkmanKings'

export default function AboutListOfKings(): JSX.Element {
return (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { render, fireEvent, screen } from '@testing-library/react'
import MarkupService from 'markup/application/MarkupService'
import DateConverterForm, {
AboutDateConverter,
} from 'chronology/ui/DateConverterForm'
} from 'chronology/ui/DateConverter/DateConverterForm'
import { markupDtoSerialized } from 'test-support/markup-fixtures'
import { MemoryRouter } from 'react-router-dom'
import Bluebird from 'bluebird'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Markup from 'markup/ui/markup'
import {
DateConverterFormControls,
DateConverterFormSection,
} from 'chronology/ui/DateConverterFormParts'
} from 'chronology/ui/DateConverter/DateConverterFormParts'
import { CalendarProps } from 'chronology/domain/DateConverterBase'
import { handleDateConverterFormChange } from 'chronology/application/DateConverterFormChange'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import DateConverter from 'chronology/domain/DateConverter'
import HelpTrigger from 'common/HelpTrigger'
import { Field } from 'chronology/application/DateConverterFormFieldData'
import { CalendarProps } from 'chronology/domain/DateConverterBase'
import getOptions from 'chronology/ui/DateConverterFormOptions'
import getOptions from 'chronology/ui/DateConverter/DateConverterFormOptions'

const selectFields = [
'weekDay',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormGroup, FormCheck, Button, Row, Col } from 'react-bootstrap'
import DateConverter from 'chronology/domain/DateConverter'
import { Field } from 'chronology/application/DateConverterFormFieldData'
import { CalendarProps } from 'chronology/domain/DateConverterBase'
import { DateConverterFormField } from 'chronology/ui/DateConverterFormField'
import { DateConverterFormField } from 'chronology/ui/DateConverter/DateConverterFormField'

const scenarioLabels = {
setToGregorianDate: 'Modern date',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { render, fireEvent, screen, act } from '@testing-library/react'
import DateSelection from '../application/DateSelection'
import DateSelection from '../../application/DateSelection'
import { fragment as mockFragment } from 'test-support/test-fragment'
import SessionContext from 'auth/SessionContext'
import { Promise } from 'bluebird'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './DateSelectionInput'
import { mesopotamianDateFactory } from 'test-support/date-fixtures'
import { Ur3Calendar } from 'chronology/domain/DateBase'
import { EponymField } from 'chronology/ui/Eponyms'
import { EponymField } from 'chronology/ui/DateEditor/Eponyms'

describe('Date options input', () => {
it('Renders and handels the date type radios', () => {
Expand All @@ -29,6 +29,10 @@ describe('Date options input', () => {
setUr3Calendar={jest.fn()}
setIsAssyrianDate={setIsAssyrianDate}
setEponym={jest.fn()}
setKingBroken={jest.fn()}
setKingUncertain={jest.fn()}
setEponymBroken={jest.fn()}
setEponymUncertain={jest.fn()}
/>
)
const seleucidRadioElem = screen.getByLabelText('Seleucid')
Expand Down Expand Up @@ -83,6 +87,10 @@ describe('Ur3 Calendar Field', () => {
setIsCalenderFieldDisplayed: jest.fn(),
setIsAssyrianDate: jest.fn(),
setEponym: jest.fn(),
setKingBroken: jest.fn(),
setKingUncertain: jest.fn(),
setEponymBroken: jest.fn(),
setEponymUncertain: jest.fn(),
})
)
const selectElem = screen.getByLabelText('select-calendar')
Expand Down Expand Up @@ -193,6 +201,10 @@ describe('Date options input with Eponyms', () => {
setUr3Calendar={jest.fn()}
setIsAssyrianDate={jest.fn()}
setEponym={jest.fn()}
setKingBroken={jest.fn()}
setKingUncertain={jest.fn()}
setEponymBroken={jest.fn()}
setEponymUncertain={jest.fn()}
/>
)
const eponymSelectElem = screen.getByLabelText('select-eponym')
Expand Down
Loading

0 comments on commit be23064

Please sign in to comment.