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

Date fixes #448

Merged
merged 108 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
956b29e
Implement Mesopotamian date, editing component & date converter (WiP)
khoidt Jul 19, 2023
4b3111e
Improve
khoidt Jul 19, 2023
c150438
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jul 19, 2023
bec1458
Extend (WiP)
khoidt Jul 31, 2023
84c3d60
Fix and update tests
khoidt Aug 1, 2023
d5d212a
Fix tsc
khoidt Aug 1, 2023
36b15ad
Improve & update tests
khoidt Aug 1, 2023
357fdda
Fix tsc
khoidt Aug 1, 2023
0492249
Refactor
khoidt Aug 1, 2023
92dd7c9
Adjust and unify
khoidt Aug 2, 2023
5c1f265
Update & fix
khoidt Aug 5, 2023
1b9279f
Implement date display in fragmentarium search
khoidt Aug 5, 2023
8546d86
Date paleography
khoidt Aug 7, 2023
81e1ccb
Fix tests
khoidt Aug 7, 2023
5b42cba
Make `date` optional in `CroppedAnnotation`
khoidt Aug 7, 2023
3123ba0
Update style
khoidt Aug 7, 2023
e505fd6
Refactor & update
khoidt Aug 7, 2023
e41636e
Add tests & update
khoidt Aug 7, 2023
c3d21d5
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 10, 2023
bb435be
Implement date delete & fix display issue
khoidt Aug 14, 2023
fc1a5d7
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 16, 2023
525ed06
Implement dates in text
khoidt Aug 24, 2023
ad96479
Add tests
khoidt Aug 25, 2023
b0bfd7c
Add more tests
khoidt Aug 25, 2023
22166ea
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 28, 2023
fbfedb7
Adjust date display
khoidt Aug 28, 2023
bf526e1
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Aug 29, 2023
41a0257
Implement eponyms (WiP)
khoidt Sep 4, 2023
5b6675c
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 4, 2023
4df82dc
Add phases and improve selection
khoidt Sep 4, 2023
7460ee8
Extend eponym
khoidt Sep 5, 2023
088c5d3
Improve & add tests
khoidt Sep 5, 2023
111df01
Add & update tests
khoidt Sep 6, 2023
03fc524
Add test for date with eponym string
khoidt Sep 6, 2023
ba52efd
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 7, 2023
ae397c3
Implement date converter
khoidt Sep 21, 2023
b325ede
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 22, 2023
4768f48
Refactor
khoidt Sep 22, 2023
c3fa9fb
Refactor more
khoidt Sep 22, 2023
2f4d3e9
Refactor more
khoidt Sep 22, 2023
1a875b6
Add tests
khoidt Sep 22, 2023
bb5cdcf
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 23, 2023
da5a92a
Patch approximate dates conversion
khoidt Sep 23, 2023
5ae999f
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Sep 25, 2023
725fee6
Restructure
khoidt Sep 25, 2023
14ecf92
Add basic form
khoidt Sep 25, 2023
06860d4
Reorder about tabs
khoidt Sep 25, 2023
d6e6818
Add routes & breadcrumbs to About section
khoidt Sep 26, 2023
3be1327
Add routes to About
khoidt Oct 1, 2023
4d5ced6
Implement form functionality, design & refactor
khoidt Oct 2, 2023
cac6554
Add copy json button & refactor style
khoidt Oct 3, 2023
596a84a
Implement broken date display
khoidt Oct 3, 2023
1c28754
Add options & text display for modern date fields
khoidt Oct 4, 2023
6bec43b
Update description
khoidt Oct 5, 2023
674f3be
Fix cjdn calculator
khoidt Oct 5, 2023
20f9ce2
Julian and Gregorian dates correction (WiP)
khoidt Oct 9, 2023
6bf7be2
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Oct 9, 2023
306a4d3
Implement Gregorian dates
khoidt Oct 10, 2023
9c95b43
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Oct 11, 2023
866c826
Implement Gregorian string output, correct, update & refactor
khoidt Oct 12, 2023
29d7879
Uddate converter & tests (WiP)
khoidt Oct 16, 2023
2560722
Update Gregrian date converter & restrict day fields
khoidt Oct 17, 2023
e509ac7
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Dec 12, 2023
6cd9dbd
Update snap
khoidt Dec 12, 2023
d04d68b
Refactor & improve style
khoidt Dec 12, 2023
7b983b8
Improve & refactor
khoidt Dec 13, 2023
06d046f
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Dec 13, 2023
3dec050
Improve & refactor
khoidt Dec 18, 2023
45c41ea
Improve & refactor
khoidt Dec 18, 2023
1f4bf60
Improve & refactor
khoidt Dec 18, 2023
4fe8bae
Refactor
khoidt Dec 18, 2023
5efd8cb
Improve & refactor
khoidt Dec 20, 2023
f1b442d
Improve & refactor
khoidt Dec 26, 2023
ff9da56
Improve & add tests
khoidt Jan 2, 2024
f6de167
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jan 2, 2024
43d7c1e
Update snapshots
khoidt Jan 2, 2024
4bc979d
Add tests, refactor & extend options fields (WiP)
khoidt Jan 2, 2024
d7274c6
Implement advanced field options & limits (WiP)
khoidt Jan 4, 2024
e6b5089
Refactor
khoidt Jan 4, 2024
9c2ad93
Work on options and restrictions (WiP)
khoidt Jan 5, 2024
86fb42f
Fix regnal years calculation & tests
khoidt Jan 8, 2024
79b1bbc
Implement ruler selection and Brinkman names
khoidt Jan 8, 2024
bac49d4
Implement tools page & Mes. date guards, improve
khoidt Jan 15, 2024
863c0cb
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jan 15, 2024
01df76d
Add tests
khoidt Jan 16, 2024
139dcb9
Update tests
khoidt Jan 16, 2024
32e3d43
Clean up
khoidt Jan 16, 2024
e89f1f5
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jan 16, 2024
f420231
Fix markup
khoidt Jan 16, 2024
eedbcde
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jan 17, 2024
be23064
Add broken & uncertain in king & eponym (WiP), refactor
khoidt Jan 25, 2024
0cb26ed
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Jan 25, 2024
28e393c
Update piping & display for king & eponym `broken` & `uncertain`
khoidt Jan 31, 2024
837ad53
Implement `isNotInBrinkman`, add data, test, update & refactor
khoidt Feb 7, 2024
802ac9e
Hide empty year-month-date
khoidt Feb 8, 2024
b99251b
Refactor
khoidt Feb 8, 2024
c1559bf
Implement date switch & default PJC
khoidt Feb 8, 2024
1eb95d5
Update & improve
khoidt Feb 9, 2024
6b9eb5a
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Feb 9, 2024
97d4294
Improve & refactor
khoidt Feb 9, 2024
8a1fcfa
Add tests
khoidt Feb 9, 2024
4c19a46
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Feb 12, 2024
5dea98e
Implement validation & date display in editor
khoidt Feb 12, 2024
87d33b4
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Feb 13, 2024
27dde9c
Update tests
khoidt Feb 13, 2024
6c06c04
Refactor
khoidt Feb 22, 2024
845675a
Merge remote-tracking branch 'origin/master' into add-date-to-fragment
khoidt Feb 22, 2024
29d3eab
Update date calculations & tests
khoidt Feb 22, 2024
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
64 changes: 56 additions & 8 deletions src/chronology/application/DateSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from 'chronology/ui/DateEditor/DateSelectionInput'
import useDateSelectionState, {
DateEditorStateProps,
DateSelectionState,
} from 'chronology/application/DateSelectionState'

type Props = {
Expand All @@ -30,6 +31,28 @@ interface DateEditorProps extends DateEditorStateProps {
isDisplayed: boolean
}

function getSelectedDateAndValidation(
state: DateSelectionState,
savedDate?: MesopotamianDate
): { selectedDate?: MesopotamianDate; isSelectedDateValid: boolean } {
let isSelectedDateValid: boolean
let selectedDate: MesopotamianDate | undefined
try {
selectedDate = state.getDate()
const dateString = selectedDate.toString()
const isDatesNotSame =
savedDate === undefined || dateString !== savedDate.toString()
const isDateEmpty = dateString.replaceAll('SE', '') !== ''
const isAssyrianDateNotEmpty =
!state.isAssyrianDate || dateString !== '∅.∅.1'
isSelectedDateValid =
isDateEmpty && isAssyrianDateNotEmpty && isDatesNotSame
} catch {
isSelectedDateValid = false
}
return { selectedDate, isSelectedDateValid }
}

export function DateEditor({
date,
setDate,
Expand All @@ -55,27 +78,50 @@ export function DateEditor({
const dateOptionsInput = DateOptionsInput({ ...state })
const dateInputGroups = DateInputGroups({ ...state })

const saveButton = (
const deleteButton = (
<Button
className="m-1"
variant="danger"
disabled={false}
onClick={() => state.saveDate(state.getDate(), index)}
onClick={() => state.saveDate(undefined, index)}
>
Save
Delete
</Button>
)

const deleteButton = (
const { selectedDate, isSelectedDateValid } = getSelectedDateAndValidation(
state,
date
)

const saveButton = (
<Button
className="m-1"
variant="danger"
disabled={false}
onClick={() => state.saveDate(undefined, index)}
disabled={!isSelectedDateValid}
onClick={() => state.saveDate(state.getDate(), index)}
>
Delete
Save
</Button>
)

const savedDateDisplay = date ? (
<>
<b>Saved date</b>
<DateDisplay date={date} />
</>
) : (
''
)
const selectedDateDisplay =
selectedDate && isSelectedDateValid ? (
<>
<b>Selected date</b>
<DateDisplay date={selectedDate} />
</>
) : (
''
)

const popover = (
<Popover
style={{ maxWidth: '600px' }}
Expand All @@ -85,6 +131,8 @@ export function DateEditor({
<Popover.Content>
{dateOptionsInput}
{dateInputGroups}
{savedDateDisplay}
{selectedDateDisplay}
{date && deleteButton}
{saveButton}
<Spinner loading={isSaving}>Saving...</Spinner>
Expand Down
5 changes: 4 additions & 1 deletion src/chronology/ui/DateEditor/DateSelection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ describe('DateSelection', () => {
act(() => {
fireEvent.click(editButton)
})
const yearInput = screen.getByPlaceholderText('Year')
await act(async () => {
fireEvent.change(yearInput, { target: { value: '189' } })
})
const saveButton = screen.getByText('Save')

fireEvent.click(saveButton)
const loadingSpinner = screen.getByText('Saving...')
expect(loadingSpinner).toBeInTheDocument()
Expand Down
12 changes: 12 additions & 0 deletions src/chronology/ui/DateEditor/DatesInTextSelection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ describe('DatesInTextSelection', () => {
await act(async () => {
fireEvent.click(addButton)
})
const dayInput = screen.getByPlaceholderText('Day')
const monthInput = screen.getByPlaceholderText('Month')
await act(async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

fireEvent.change(dayInput, { target: { value: '18' } })
fireEvent.change(monthInput, { target: { value: '10' } })
})
const saveButton = screen.getByText('Save')
await act(async () => {
fireEvent.click(saveButton)
Expand All @@ -62,6 +68,12 @@ describe('DatesInTextSelection', () => {
await act(async () => {
fireEvent.click(editButton)
})
const dayInput = screen.getByPlaceholderText('Day')
const monthInput = screen.getByPlaceholderText('Month')
await act(async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

fireEvent.change(dayInput, { target: { value: '18' } })
fireEvent.change(monthInput, { target: { value: '10' } })
})
const saveButton = screen.getByText('Save')
await act(async () => {
fireEvent.click(saveButton)
Expand Down
Loading