Skip to content

Commit 62d3f29

Browse files
committed
Selected time durations have an active state when clicked
1 parent 99b830d commit 62d3f29

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

apps/webapp/app/components/runs/v3/SharedFilters.tsx

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ export function TimeDropdown({
322322
const initialSection: SectionType = from || to ? "dateRange" : "duration";
323323
const [activeSection, setActiveSection] = useState<SectionType>(initialSection);
324324
const [validationError, setValidationError] = useState<string | null>(null);
325+
const [selectedQuickDate, setSelectedQuickDate] = useState<string | null>(null);
325326

326327
// Selection state: preset value or "custom"
327328
const initialCustom = getInitialCustomDuration(period);
@@ -420,6 +421,7 @@ export function TimeDropdown({
420421
onClick={() => {
421422
setActiveSection("duration");
422423
setValidationError(null);
424+
setSelectedQuickDate(null);
423425
}}
424426
className="flex cursor-pointer gap-3 rounded-md pb-3"
425427
>
@@ -437,10 +439,10 @@ export function TimeDropdown({
437439
{/* Custom duration row */}
438440
<div
439441
className={cn(
440-
"col-span-4 flex h-[1.8rem] w-full items-center gap-2 rounded border py-0.5 pl-0 pr-2 transition-colors",
442+
"col-span-4 flex h-[1.8rem] w-full items-center gap-2 rounded border bg-charcoal-750 py-0.5 pl-0 pr-2 transition-colors",
441443
activeSection === "duration" && selectedPeriod === "custom"
442-
? "border-indigo-500 bg-charcoal-750"
443-
: "border-charcoal-650 bg-charcoal-750 hover:border-charcoal-600",
444+
? "border-indigo-500 "
445+
: "border-charcoal-650 hover:border-charcoal-600",
444446
validationError &&
445447
activeSection === "duration" &&
446448
selectedPeriod === "custom" &&
@@ -554,6 +556,7 @@ export function TimeDropdown({
554556
setFromValue(value);
555557
setActiveSection("dateRange");
556558
setValidationError(null);
559+
setSelectedQuickDate(null);
557560
}}
558561
showSeconds
559562
showNowButton
@@ -569,6 +572,7 @@ export function TimeDropdown({
569572
setToValue(value);
570573
setActiveSection("dateRange");
571574
setValidationError(null);
575+
setSelectedQuickDate(null);
572576
}}
573577
showSeconds
574578
showNowButton
@@ -580,46 +584,55 @@ export function TimeDropdown({
580584
<div className="mt-2 grid grid-cols-3 gap-2" onClick={(e) => e.stopPropagation()}>
581585
<QuickDateButton
582586
label="Yesterday"
587+
isActive={selectedQuickDate === "yesterday"}
583588
onClick={() => {
584589
const yesterday = subDays(new Date(), 1);
585590
setFromValue(startOfDay(yesterday));
586591
setToValue(endOfDay(yesterday));
587592
setActiveSection("dateRange");
588593
setValidationError(null);
594+
setSelectedQuickDate("yesterday");
589595
}}
590596
/>
591597
<QuickDateButton
592598
label="Today"
599+
isActive={selectedQuickDate === "today"}
593600
onClick={() => {
594601
const today = new Date();
595602
setFromValue(startOfDay(today));
596603
setToValue(today);
597604
setActiveSection("dateRange");
598605
setValidationError(null);
606+
setSelectedQuickDate("today");
599607
}}
600608
/>
601609
<QuickDateButton
602610
label="This week"
611+
isActive={selectedQuickDate === "thisWeek"}
603612
onClick={() => {
604613
const now = new Date();
605614
setFromValue(startOfWeek(now, { weekStartsOn: 1 }));
606615
setToValue(now);
607616
setActiveSection("dateRange");
608617
setValidationError(null);
618+
setSelectedQuickDate("thisWeek");
609619
}}
610620
/>
611621
<QuickDateButton
612622
label="Last week"
623+
isActive={selectedQuickDate === "lastWeek"}
613624
onClick={() => {
614625
const lastWeek = subWeeks(new Date(), 1);
615626
setFromValue(startOfWeek(lastWeek, { weekStartsOn: 1 }));
616627
setToValue(endOfWeek(lastWeek, { weekStartsOn: 1 }));
617628
setActiveSection("dateRange");
618629
setValidationError(null);
630+
setSelectedQuickDate("lastWeek");
619631
}}
620632
/>
621633
<QuickDateButton
622634
label="Last weekend"
635+
isActive={selectedQuickDate === "lastWeekend"}
623636
onClick={() => {
624637
const now = new Date();
625638
let saturday: Date;
@@ -635,36 +648,43 @@ export function TimeDropdown({
635648
setToValue(sunday);
636649
setActiveSection("dateRange");
637650
setValidationError(null);
651+
setSelectedQuickDate("lastWeekend");
638652
}}
639653
/>
640654
<QuickDateButton
641655
label="This month"
656+
isActive={selectedQuickDate === "thisMonth"}
642657
onClick={() => {
643658
const now = new Date();
644659
setFromValue(startOfMonth(now));
645660
setToValue(now);
646661
setActiveSection("dateRange");
647662
setValidationError(null);
663+
setSelectedQuickDate("thisMonth");
648664
}}
649665
/>
650666
<QuickDateButton
651667
label="Last month"
668+
isActive={selectedQuickDate === "lastMonth"}
652669
onClick={() => {
653670
const lastMonth = subMonths(new Date(), 1);
654671
setFromValue(startOfMonth(lastMonth));
655672
setToValue(endOfMonth(lastMonth));
656673
setActiveSection("dateRange");
657674
setValidationError(null);
675+
setSelectedQuickDate("lastMonth");
658676
}}
659677
/>
660678
<QuickDateButton
661679
label="Year to date"
680+
isActive={selectedQuickDate === "yearToDate"}
662681
onClick={() => {
663682
const now = new Date();
664683
setFromValue(startOfYear(now));
665684
setToValue(now);
666685
setActiveSection("dateRange");
667686
setValidationError(null);
687+
setSelectedQuickDate("yearToDate");
668688
}}
669689
/>
670690
</div>
@@ -737,9 +757,23 @@ export function dateFromString(value: string | undefined | null): Date | undefin
737757
return new Date(value);
738758
}
739759

740-
function QuickDateButton({ label, onClick }: { label: string; onClick: () => void }) {
760+
function QuickDateButton({
761+
label,
762+
onClick,
763+
isActive,
764+
}: {
765+
label: string;
766+
onClick: () => void;
767+
isActive?: boolean;
768+
}) {
741769
return (
742-
<Button type="button" variant="secondary/small" onClick={onClick} fullWidth>
770+
<Button
771+
type="button"
772+
variant="secondary/small"
773+
onClick={onClick}
774+
fullWidth
775+
className={isActive ? "border-indigo-500 group-hover/button:border-indigo-500" : undefined}
776+
>
743777
{label}
744778
</Button>
745779
);

0 commit comments

Comments
 (0)