Add DateRangePicker component with segmented entry and calendar popup
Django CI/CD / test (push) Successful in 2m33s
Django CI/CD / build-and-push (push) Successful in 1m17s

Implements the DateRangePicker design: a DateRangeField that looks like a
single input but splits each date into DD/MM/YYYY part inputs (ordered by
the new common.time.dateformat_hyphenated), and a DateRangeCalendar popup
with a preset column (today, yesterday, last 7/30 days, this/last month,
this year), anchor-style range picking with an outlined/filled/muted range
track, and a Cancel / Clear / Select footer.

Typing fills each part's placeholder from the right (YYYY -> YY19 -> 1987),
auto-advances between parts, and Backspace/Delete reverts the active part.
The committed value lives in hidden ISO {prefix}-min/{prefix}-max inputs --
the same contract as DateRangeFilter, so filter_bar.js needs no changes.

As a tryout, the Purchased filter in PurchaseFilterBar now uses the
DateRangePicker; Refunded keeps the native-date DateRangeFilter, and the
native-path e2e tests were repointed at it.

Includes unit tests for the component family and the filter-bar
integration, plus Playwright e2e tests for segment entry, calendar
picking, presets, and footer actions.

https://claude.ai/code/session_017b75KJAu4kNNpZPu9NAPBM
This commit is contained in:
Claude
2026-06-11 17:49:22 +00:00
committed by Lukáš Kucharczyk
parent 15a97dee9a
commit 0fa860c237
10 changed files with 1552 additions and 11 deletions
+26
View File
@@ -1,17 +1,43 @@
import re
from datetime import date, datetime, timedelta
from typing import NamedTuple
from django.utils import timezone
from common.utils import generate_split_ranges
dateformat: str = "%d/%m/%Y"
dateformat_hyphenated: str = "%d-%m-%Y"
datetimeformat: str = "%d/%m/%Y %H:%M"
timeformat: str = "%H:%M"
durationformat: str = "%2.1H hours"
durationformat_manual: str = "%H hours"
class DatePartSpec(NamedTuple):
"""One date part (day/month/year) of a hyphenated date format."""
name: str
placeholder: str
length: int
_DATE_PART_SPECS: dict[str, DatePartSpec] = {
"%d": DatePartSpec("day", "DD", 2),
"%m": DatePartSpec("month", "MM", 2),
"%Y": DatePartSpec("year", "YYYY", 4),
}
def date_parts(format_string: str = dateformat_hyphenated) -> list[DatePartSpec]:
"""Split a hyphenated strftime date format into its ordered parts.
``"%d-%m-%Y"`` becomes ``[day, month, year]`` specs, each carrying the
placeholder text (``DD``/``MM``/``YYYY``) and digit length shown by the
DateRangeField segments."""
return [_DATE_PART_SPECS[directive] for directive in format_string.split("-")]
def _safe_timedelta(duration: timedelta | int | None):
if duration is None:
return timedelta(0)