Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

fix(date-selector): calendar panel padding, separators, simpler mobile (#1151)

Goldflag30d98e11beed
diff --git a/client/messages/cs.json b/client/messages/cs.json
index 2cc500c9e..58afacd29 100644
--- a/client/messages/cs.json
+++ b/client/messages/cs.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Poslední 1 hodina",
"4/DApn": "Posledních 6 hodin",
"XB8fV9": "Posledních 24 hodin",
- "NvVBfV": "V reálném čase",
- "csFahs": "Relativní",
- "Coy6SH": "Kalendář",
"Nd8jYf": "Hledat rozsahy",
"cgqpQ6": "Žádný odpovídající rozsah",
"dM+p3/": "Od",
diff --git a/client/messages/de.json b/client/messages/de.json
index 1ebaddd3a..111f0288c 100644
--- a/client/messages/de.json
+++ b/client/messages/de.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Letzte Stunde",
"4/DApn": "Letzte 6 Stunden",
"XB8fV9": "Letzte 24 Stunden",
- "NvVBfV": "Echtzeit",
- "csFahs": "Relativ",
- "Coy6SH": "Kalender",
"Nd8jYf": "Zeiträume suchen",
"cgqpQ6": "Kein passender Zeitraum",
"dM+p3/": "Von",
diff --git a/client/messages/en.json b/client/messages/en.json
index 3e8b2fc3c..bb042f87b 100644
--- a/client/messages/en.json
+++ b/client/messages/en.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Last 1 Hour",
"4/DApn": "Last 6 Hours",
"XB8fV9": "Last 24 Hours",
- "NvVBfV": "Realtime",
- "csFahs": "Relative",
- "Coy6SH": "Calendar",
"Nd8jYf": "Search ranges",
"cgqpQ6": "No matching range",
"dM+p3/": "From",
diff --git a/client/messages/es.json b/client/messages/es.json
index 5308d2e2e..057d4221e 100644
--- a/client/messages/es.json
+++ b/client/messages/es.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Última 1 hora",
"4/DApn": "Últimas 6 horas",
"XB8fV9": "Últimas 24 horas",
- "NvVBfV": "Tiempo real",
- "csFahs": "Relativo",
- "Coy6SH": "Calendario",
"Nd8jYf": "Buscar periodos",
"cgqpQ6": "Ningún periodo coincide",
"dM+p3/": "Desde",
diff --git a/client/messages/fr.json b/client/messages/fr.json
index 971d47d77..d8f50c6bf 100644
--- a/client/messages/fr.json
+++ b/client/messages/fr.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Dernière heure",
"4/DApn": "6 dernières heures",
"XB8fV9": "24 dernières heures",
- "NvVBfV": "Temps réel",
- "csFahs": "Relatif",
- "Coy6SH": "Calendrier",
"Nd8jYf": "Rechercher une période",
"cgqpQ6": "Aucune période correspondante",
"dM+p3/": "Du",
diff --git a/client/messages/it.json b/client/messages/it.json
index d1babfd2d..613757fd1 100644
--- a/client/messages/it.json
+++ b/client/messages/it.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Ultima 1 Ora",
"4/DApn": "Ultime 6 Ore",
"XB8fV9": "Ultime 24 Ore",
- "NvVBfV": "Tempo reale",
- "csFahs": "Relativo",
- "Coy6SH": "Calendario",
"Nd8jYf": "Cerca intervalli",
"cgqpQ6": "Nessun intervallo corrispondente",
"dM+p3/": "Da",
diff --git a/client/messages/ja.json b/client/messages/ja.json
index c230478c7..9c0dd4040 100644
--- a/client/messages/ja.json
+++ b/client/messages/ja.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "過去1時間",
"4/DApn": "過去6時間",
"XB8fV9": "過去24時間",
- "NvVBfV": "リアルタイム",
- "csFahs": "相対",
- "Coy6SH": "カレンダー",
"Nd8jYf": "期間を検索",
"cgqpQ6": "一致する期間がありません",
"dM+p3/": "開始",
diff --git a/client/messages/ko.json b/client/messages/ko.json
index fa333a21d..7b5043e57 100644
--- a/client/messages/ko.json
+++ b/client/messages/ko.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "최근 1시간",
"4/DApn": "최근 6시간",
"XB8fV9": "최근 24시간",
- "NvVBfV": "실시간",
- "csFahs": "상대",
- "Coy6SH": "달력",
"Nd8jYf": "기간 검색",
"cgqpQ6": "일치하는 기간 없음",
"dM+p3/": "시작",
diff --git a/client/messages/pl.json b/client/messages/pl.json
index 0b547d2b8..7b68d881a 100644
--- a/client/messages/pl.json
+++ b/client/messages/pl.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Ostatnia godzina",
"4/DApn": "Ostatnie 6 godzin",
"XB8fV9": "Ostatnie 24 godziny",
- "NvVBfV": "Czas rzeczywisty",
- "csFahs": "Względne",
- "Coy6SH": "Kalendarz",
"Nd8jYf": "Szukaj zakresów",
"cgqpQ6": "Brak pasującego zakresu",
"dM+p3/": "Od",
diff --git a/client/messages/pt.json b/client/messages/pt.json
index 1b3d885e9..bfeca3685 100644
--- a/client/messages/pt.json
+++ b/client/messages/pt.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Última 1 Hora",
"4/DApn": "Últimas 6 Horas",
"XB8fV9": "Últimas 24 Horas",
- "NvVBfV": "Tempo Real",
- "csFahs": "Relativo",
- "Coy6SH": "Calendário",
"Nd8jYf": "Pesquisar períodos",
"cgqpQ6": "Nenhum período correspondente",
"dM+p3/": "De",
diff --git a/client/messages/uk.json b/client/messages/uk.json
index d8c0ea6ea..c23eadb7d 100644
--- a/client/messages/uk.json
+++ b/client/messages/uk.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "Остання 1 година",
"4/DApn": "Останні 6 годин",
"XB8fV9": "Останні 24 години",
- "NvVBfV": "У реальному часі",
- "csFahs": "Відносні",
- "Coy6SH": "Календар",
"Nd8jYf": "Пошук періодів",
"cgqpQ6": "Немає відповідного періоду",
"dM+p3/": "Від",
diff --git a/client/messages/zh.json b/client/messages/zh.json
index 2b2c7efa5..eaa9128e9 100644
--- a/client/messages/zh.json
+++ b/client/messages/zh.json
@@ -1396,9 +1396,6 @@
"tOwHZm": "过去 1 小时",
"4/DApn": "过去 6 小时",
"XB8fV9": "过去 24 小时",
- "NvVBfV": "实时",
- "csFahs": "相对",
- "Coy6SH": "日历",
"Nd8jYf": "搜索时间范围",
"cgqpQ6": "没有匹配的时间范围",
"dM+p3/": "从",
diff --git a/client/src/components/DateSelector/DateSelector.test.tsx b/client/src/components/DateSelector/DateSelector.test.tsx
index d6b6b073f..835fbd318 100644
--- a/client/src/components/DateSelector/DateSelector.test.tsx
+++ b/client/src/components/DateSelector/DateSelector.test.tsx
@@ -103,10 +103,10 @@ describe("DateSelector", () => {
render(<DateSelector time={{ mode: "range", startDate: "2024-03-08", endDate: "2024-03-14" }} setTime={setTime} />);
fireEvent.click(screen.getByRole("button", { name: /Mar 8/ }));
- expect(screen.getByText("Realtime")).toBeTruthy();
+ expect(screen.getByPlaceholderText("Search ranges")).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
- expect(screen.queryByText("Realtime")).toBeNull();
+ expect(screen.queryByPlaceholderText("Search ranges")).toBeNull();
});
it("hides the realtime presets when a caller disables them", () => {
@@ -119,6 +119,7 @@ describe("DateSelector", () => {
);
fireEvent.click(screen.getByRole("button", { name: /Mar 8/ }));
- expect(screen.queryByText("Realtime")).toBeNull();
+ expect(screen.queryByText("Last 30 Minutes")).toBeNull();
+ expect(screen.getByText("Today")).toBeTruthy();
});
});
diff --git a/client/src/components/DateSelector/RangePanel.test.tsx b/client/src/components/DateSelector/RangePanel.test.tsx
index 5cc6ced9e..48454409f 100644
--- a/client/src/components/DateSelector/RangePanel.test.tsx
+++ b/client/src/components/DateSelector/RangePanel.test.tsx
@@ -63,12 +63,11 @@ afterEach(() => {
});
describe("RangePanel presets", () => {
- it("groups the presets under headings instead of one flat list", () => {
- renderPanel(DATE_RANGE);
+ it("rules the preset groups apart instead of running them into one flat list", () => {
+ const { container } = renderPanel(DATE_RANGE);
- expect(screen.getByText("Realtime")).toBeTruthy();
- expect(screen.getByText("Relative")).toBeTruthy();
- expect(screen.getByText("Calendar")).toBeTruthy();
+ // realtime | relative | calendar
+ expect(container.querySelectorAll('[data-slot="command-separator"]').length).toBe(2);
});
it("offers Last Week and Last Month, which had labels but no menu item before", () => {
@@ -98,11 +97,11 @@ describe("RangePanel presets", () => {
});
it("hides the realtime group when a caller disables past-minutes windows", () => {
- renderPanel(DATE_RANGE, { pastMinutesEnabled: false });
+ const { container } = renderPanel(DATE_RANGE, { pastMinutesEnabled: false });
- expect(screen.queryByText("Realtime")).toBeNull();
expect(screen.queryByText("Last 30 Minutes")).toBeNull();
expect(screen.getByText("Today")).toBeTruthy();
+ expect(container.querySelectorAll('[data-slot="command-separator"]').length).toBe(1);
});
});
diff --git a/client/src/components/DateSelector/RangePanel.tsx b/client/src/components/DateSelector/RangePanel.tsx
index 9f412f857..9aa49ce4b 100644
--- a/client/src/components/DateSelector/RangePanel.tsx
+++ b/client/src/components/DateSelector/RangePanel.tsx
@@ -2,7 +2,15 @@
import { Button } from "@/components/ui/button";
import { Calendar } from "@/components/ui/calendar";
-import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
+import {
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+ CommandList,
+ CommandSeparator,
+} from "@/components/ui/command";
import useMediaQuery from "@/components/ui/hooks/useMediaQuery";
import { Input } from "@/components/ui/input";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
@@ -13,9 +21,9 @@ import { cn } from "@/lib/utils";
import { DateTime } from "luxon";
import { Check, Globe } from "lucide-react";
import { useExtracted } from "next-intl";
-import { useState } from "react";
+import { Fragment, useState } from "react";
import { DateRange } from "react-day-picker";
-import { PRESET_GROUPS, usePresetGroupLabels, usePresetLabels } from "./presets";
+import { PRESET_GROUPS, usePresetLabels } from "./presets";
import {
describeBounds,
rangeFieldsForTime,
@@ -55,7 +63,6 @@ export function RangePanel({
}) {
const t = useExtracted();
const presetLabels = usePresetLabels();
- const groupLabels = usePresetGroupLabels();
const isWide = useMediaQuery("(min-width: 768px)");
const [timezoneOpen, setTimezoneOpen] = useState(false);
@@ -136,29 +143,45 @@ export function RangePanel({
<div className="w-full border-b border-neutral-150 md:w-[190px] md:shrink-0 md:border-b-0 md:border-r dark:border-neutral-800">
<Command defaultValue={draft.time.wellKnown ? presetLabels[draft.time.wellKnown] : undefined}>
<CommandInput placeholder={t("Search ranges")} />
- <CommandList className="max-h-[180px] md:max-h-[440px]">
+ {/* Capped so the rail ends level with the calendar column beside it
+ (two months + the bound rows + the pane's padding, less this
+ list's own 36px search row). Left to its natural height the
+ seventeen presets stretched the panel and left a block of dead
+ space under the calendar. */}
+ <CommandList className="max-h-[180px] md:max-h-[384px]">
<CommandEmpty>{t("No matching range")}</CommandEmpty>
- {groups.map(group => (
- <CommandGroup key={group.id} heading={groupLabels[group.id]}>
- {group.presets.map(preset => (
- <CommandItem
- key={preset}
- value={presetLabels[preset]}
- onSelect={() => applyPreset(preset)}
- className={cn(draft.time.wellKnown === preset && "font-medium")}
- >
- {presetLabels[preset]}
- {draft.time.wellKnown === preset && <Check className="ml-auto h-3.5 w-3.5" />}
- </CommandItem>
- ))}
- </CommandGroup>
+ {/* Separators rather than headings: the groups are obvious from
+ their contents, and cmdk drops the rules automatically while a
+ search is filtering across them. */}
+ {groups.map((group, index) => (
+ <Fragment key={group.id}>
+ {index > 0 && <CommandSeparator />}
+ <CommandGroup>
+ {group.presets.map(preset => (
+ <CommandItem
+ key={preset}
+ value={presetLabels[preset]}
+ onSelect={() => applyPreset(preset)}
+ className={cn(draft.time.wellKnown === preset && "font-medium")}
+ >
+ {presetLabels[preset]}
+ {draft.time.wellKnown === preset && <Check className="ml-auto h-3.5 w-3.5" />}
+ </CommandItem>
+ ))}
+ </CommandGroup>
+ </Fragment>
))}
</CommandList>
</Command>
</div>
- <div className="p-3">
+ <div className="flex flex-col p-3">
<Calendar
+ // `useMediaQuery` resolves in an effect, so `months` flips from 2 to
+ // 1 after mount. `defaultMonth` is only read on mount, which left a
+ // phone opening one month to the left of the selection — remount so
+ // it is read again once the breakpoint is known.
+ key={months}
mode="range"
selected={selected}
onDayClick={(date, modifiers) => {
@@ -174,10 +197,11 @@ export function RangePanel({
startMonth={lastMonth.minus({ years: 6 }).toJSDate()}
endMonth={lastMonth.toJSDate()}
disabled={{ after: maxDate }}
- className="p-0"
+ // the calendar is `w-fit`; centre it when it is alone in a full-width column
+ className="mx-auto p-0 md:mx-0"
/>
- <div className="mt-3 flex flex-col gap-2 border-t border-neutral-150 pt-3 dark:border-neutral-800">
+ <div className="mt-3 hidden flex-col gap-2 border-t border-neutral-150 pt-3 md:flex dark:border-neutral-800">
<BoundRow
label={t("From")}
date={draft.fields.startDate}
diff --git a/client/src/components/DateSelector/presets.ts b/client/src/components/DateSelector/presets.ts
index acad26aac..5c4d937b8 100644
--- a/client/src/components/DateSelector/presets.ts
+++ b/client/src/components/DateSelector/presets.ts
@@ -2,10 +2,11 @@ import { useExtracted } from "next-intl";
import type { DashboardDefaultTimeRange } from "@/lib/defaultTimeRange";
/**
- * The preset list, grouped.
+ * The preset list, grouped. The groups are drawn as separators rather than
+ * named headings — their contents say what they are, and it keeps the rail as
+ * quiet as the dropdown it replaces.
*
- * It replaces seventeen items in one flat column with no headings and no way to
- * search them. Two of those seventeen were unreachable: `last-week` and
+ * Two of the seventeen presets were previously unreachable: `last-week` and
* `last-month` had labels but no menu item, so they could only be arrived at
* from a stored default or a URL param.
*
@@ -49,13 +50,3 @@ export function usePresetLabels(): Record<DashboardDefaultTimeRange, string> {
"all-time": t("All Time"),
};
}
-
-export function usePresetGroupLabels(): Record<PresetGroupId, string> {
- const t = useExtracted();
-
- return {
- realtime: t("Realtime"),
- relative: t("Relative"),
- calendar: t("Calendar"),
- };
-}
diff --git a/client/src/components/ui/popover.tsx b/client/src/components/ui/popover.tsx
index 7fbbfcb2d..737eada84 100644
--- a/client/src/components/ui/popover.tsx
+++ b/client/src/components/ui/popover.tsx
@@ -18,6 +18,10 @@ const PopoverContent = React.forwardRef<
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
ref={ref}
+ // `ui/calendar.tsx` keys its `bg-transparent` override off this slot.
+ // Without it a calendar inside a popover paints its own lighter panel,
+ // which reads as an inset rectangle with broken padding.
+ data-slot="popover-content"
align={align}
sideOffset={sideOffset}
className={cn(