test(sidebar): cover the date preset/custom selection logic (R13 S2c)
The deep-review flagged that the feed sidebar's new date single-select derivation was the one bit of migrated logic without a test, while its sibling primitives (FilterChipGroup/SegmentedToggle/SortControl) all gained one. Lift the pure logic into lib/dateFilter (deriveDateKey + applyDateChip), same split as columnSort, and cover it: dateKey for none/preset/custom/off-preset-value, the preset toggle-off, the preset-not-active-while-custom-open case, and the Custom open/close + maxAgeDays clearing. Sidebar now calls the helpers; the onChange is behaviour-identical (self-E2E'd: preset on/off, Custom editor). 11 new tests (vitest 136 -> 147). gate green. Branch not merged.
This commit is contained in:
@@ -10,6 +10,7 @@ import { copyText } from "../lib/clipboard";
|
||||
import { notify } from "../lib/notifications";
|
||||
import { useDebounced } from "../lib/useDebounced";
|
||||
import { clearedFilters, useActiveFilters } from "../lib/useActiveFilters";
|
||||
import { applyDateChip, deriveDateKey } from "../lib/dateFilter";
|
||||
import TagManager from "./TagManager";
|
||||
import SavedViewsWidget from "./SavedViewsWidget";
|
||||
import SidePanel from "./SidePanel";
|
||||
@@ -152,17 +153,8 @@ export default function Sidebar({
|
||||
case "channel":
|
||||
return <ChannelPicker filters={filters} setFilters={setFilters} />;
|
||||
case "date": {
|
||||
// Single-select across the presets + Custom: a preset is active only when its maxAge matches
|
||||
// and no custom range is open; otherwise Custom owns the selection (or none).
|
||||
const activePresetDays = DATE_PRESETS.find(
|
||||
(p) => filters.maxAgeDays === p.days && !customDates,
|
||||
)?.days;
|
||||
const dateKey =
|
||||
customDates || filters.dateFrom || filters.dateTo
|
||||
? "custom"
|
||||
: activePresetDays != null
|
||||
? String(activePresetDays)
|
||||
: "";
|
||||
// Single-select across the presets + Custom; pure logic lives in lib/dateFilter.
|
||||
const dateKey = deriveDateKey(filters, customDates, DATE_PRESETS);
|
||||
return (
|
||||
<>
|
||||
<FilterChipGroup
|
||||
@@ -176,20 +168,9 @@ export default function Sidebar({
|
||||
{ value: "custom", label: t("sidebar.custom") },
|
||||
]}
|
||||
onChange={(key) => {
|
||||
if (key === "custom") {
|
||||
const next = !customDates;
|
||||
setCustomDates(next);
|
||||
if (next) setFilters({ ...filters, maxAgeDays: undefined });
|
||||
return;
|
||||
}
|
||||
const days = Number(key);
|
||||
const activePreset = filters.maxAgeDays === days && !customDates;
|
||||
setFilters({
|
||||
...filters,
|
||||
maxAgeDays: activePreset ? undefined : days,
|
||||
dateFrom: undefined,
|
||||
dateTo: undefined,
|
||||
});
|
||||
const change = applyDateChip(key, filters, customDates);
|
||||
if (change.customDates !== undefined) setCustomDates(change.customDates);
|
||||
if (change.filters) setFilters(change.filters);
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user