Give every year of a repeating period its own row

A repeating period was a single row that the planner expanded into one
window per year at read time, so no year had anywhere to differ from the
others. Editing one year rewrote them all, and removing a year in the
middle had to split the wish in two. Neither survives contact with the
thing this app is for: Easter moves, and the cheapest week is not the
same week every year.

Each year is now its own row, linked by a series id. Editing one year
touches one row; editing the series re-projects the rest from it.
Removing a year is one delete. The weekday snap is worked out once, when
the rows are made, and stored, so a row now says what it means rather
than being re-derived on every read. Recurrence stops being a stored
field and becomes what it always was in practice — an instruction at
create and update time; whether a period repeats is whether it belongs
to a series.

Migration 004 rebuilds the table and expands the existing rows, keeping
each original row as its first year so the days already planned against
it still point somewhere. A Feb 29 anchor recurring into a common year
used to raise out of the allocator; it clamps now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ei7gCZzdd751uZtPzb1Pep
This commit is contained in:
2026-09-19 15:53:25 +02:00
parent c6593062e3
commit 6d92b87bf3
43 changed files with 2735 additions and 638 deletions
@@ -94,8 +94,10 @@ describe('PeriodPopover', () => {
windowEndMonth: 7,
windowEndDay: 26,
firstYear: 2028,
// One year of a repeating wish: the series link is what makes it
// "repeat" now, and what makes the this-year/every-year choice real.
seriesId: 'series-1',
lastYear: null,
recurrence: 'yearly',
parentMode: 'either',
})
@@ -141,7 +143,7 @@ describe('PeriodPopover', () => {
windowEndMonth: 7,
windowEndDay: 26,
firstYear: 2026,
recurrence: 'yearly',
seriesId: 'series-1',
})
render(
<PeriodPopover
@@ -197,8 +199,11 @@ describe('PeriodPopover', () => {
})
it('re-checking "until age 4" hides the last-year input and clears it on save', async () => {
// The end year is series-wide, so the flow starts by widening the scope
// — the control is disabled until then (see the scope tests above).
mockOnSave.mockResolvedValue(undefined)
render(<PeriodPopover {...defaultProps} wish={makeLeaveWish({ ...wish, lastYear: 2030 })} />)
fireEvent.click(screen.getByTestId('period-scope-series'))
fireEvent.click(screen.getByTestId('period-until-age4'))
expect(screen.queryByTestId('period-last-year-input')).not.toBeInTheDocument()
fireEvent.click(screen.getByTestId('period-save-button'))
@@ -208,12 +213,69 @@ describe('PeriodPopover', () => {
it('editing the last-year input updates the value sent on save', async () => {
mockOnSave.mockResolvedValue(undefined)
render(<PeriodPopover {...defaultProps} wish={makeLeaveWish({ ...wish, lastYear: 2030 })} />)
fireEvent.click(screen.getByTestId('period-scope-series'))
fireEvent.change(screen.getByTestId('period-last-year-input'), { target: { value: '2032' } })
expect(screen.getByTestId('period-last-year-input')).toHaveValue(2032)
fireEvent.click(screen.getByTestId('period-save-button'))
await waitFor(() => expect(mockOnSave).toHaveBeenCalledWith(expect.objectContaining({ lastYear: 2032 })))
})
// Per-year vs whole-series editing. Only a real choice once the
// occurrence belongs to a series — that is what materialising the years
// into their own rows bought (Easter moves, so one year has to be able to
// move without the rest).
describe('this year vs every year', () => {
it('offers the choice for an occurrence of a repeating wish', () => {
render(<PeriodPopover {...defaultProps} wish={wish} />)
expect(screen.getByTestId('period-scope-fieldset')).toBeInTheDocument()
expect(screen.getByTestId('period-scope-occurrence')).toBeChecked()
expect(screen.getByTestId('period-scope-series')).not.toBeChecked()
})
it('does not offer it for a one-off period, where there is nothing to choose between', () => {
render(<PeriodPopover {...defaultProps} wish={makeLeaveWish({ ...wish, seriesId: null })} />)
expect(screen.queryByTestId('period-scope-fieldset')).not.toBeInTheDocument()
})
it('hides it again when the user turns repeating off', () => {
render(<PeriodPopover {...defaultProps} wish={wish} />)
fireEvent.click(screen.getByTestId('period-repeat-never'))
expect(screen.queryByTestId('period-scope-fieldset')).not.toBeInTheDocument()
})
it('saves this year only by default', async () => {
mockOnSave.mockResolvedValue(undefined)
render(<PeriodPopover {...defaultProps} wish={wish} />)
fireEvent.click(screen.getByTestId('period-save-button'))
await waitFor(() =>
expect(mockOnSave).toHaveBeenCalledWith(expect.objectContaining({ scope: 'occurrence' })),
)
})
it('saves every year once "Alla år" is picked', async () => {
mockOnSave.mockResolvedValue(undefined)
render(<PeriodPopover {...defaultProps} wish={wish} />)
fireEvent.click(screen.getByTestId('period-scope-series'))
fireEvent.click(screen.getByTestId('period-save-button'))
await waitFor(() =>
expect(mockOnSave).toHaveBeenCalledWith(expect.objectContaining({ scope: 'series' })),
)
})
it('locks the series end year until the edit is series-wide', () => {
// `lastYear` belongs to the whole series, so the backend rejects a
// change to it under the this-year-only scope. Say so in the UI
// rather than let the user hit a 422.
render(<PeriodPopover {...defaultProps} wish={makeLeaveWish({ ...wish, lastYear: 2030 })} />)
expect(screen.getByTestId('period-last-year-input')).toBeDisabled()
expect(screen.getByTestId('period-last-year-locked-hint')).toBeInTheDocument()
fireEvent.click(screen.getByTestId('period-scope-series'))
expect(screen.getByTestId('period-last-year-input')).toBeEnabled()
expect(screen.queryByTestId('period-last-year-locked-hint')).not.toBeInTheDocument()
})
})
it('toggles to "Never" repeat and hides the yearly options', () => {
render(<PeriodPopover {...defaultProps} wish={wish} />)
fireEvent.click(screen.getByTestId('period-repeat-never'))
@@ -236,6 +298,9 @@ describe('PeriodPopover', () => {
parentMode: 'either',
parentPersonalDataUuid: null,
recurrence: 'yearly',
// Defaults to the narrow scope: an edit must not silently rewrite
// the other years of the series.
scope: 'occurrence',
lastYear: null,
wantsDubbeldag: false,
})