From d6b16a77478fc3ddf6dd9487d54aaa9edfeb8dc4 Mon Sep 17 00:00:00 2001
From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com>
Date: Fri, 6 Sep 2024 14:26:32 -0500
Subject: [PATCH] Semantic search UI tweaks (#13591)
* Semantic search UI tweaks
* clean up
---
.../filter/CalendarFilterButton.tsx | 25 +++++-----
web/src/components/ui/calendar-range.tsx | 23 +++++-----
web/src/views/search/SearchView.tsx | 46 +++++++++++++++----
3 files changed, 60 insertions(+), 34 deletions(-)
diff --git a/web/src/components/filter/CalendarFilterButton.tsx b/web/src/components/filter/CalendarFilterButton.tsx
index 9b630b893..cfa69faf6 100644
--- a/web/src/components/filter/CalendarFilterButton.tsx
+++ b/web/src/components/filter/CalendarFilterButton.tsx
@@ -12,6 +12,7 @@ import { isMobile } from "react-device-detect";
import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";
import { DateRangePicker } from "../ui/calendar-range";
import { DateRange } from "react-day-picker";
+import { useState } from "react";
type CalendarFilterButtonProps = {
reviewSummary?: ReviewSummary;
@@ -91,6 +92,8 @@ export function CalendarRangeFilterButton({
defaultText,
updateSelectedRange,
}: CalendarRangeFilterButtonProps) {
+ const [open, setOpen] = useState(false);
+
const selectedDate = useFormattedRange(
range?.from == undefined ? 0 : range.from.getTime() / 1000 + 1,
range?.to == undefined ? 0 : range.to.getTime() / 1000 - 1,
@@ -119,24 +122,18 @@ export function CalendarRangeFilterButton({
initialDateFrom={range?.from}
initialDateTo={range?.to}
showCompare={false}
- onUpdate={(range) => updateSelectedRange(range.range)}
+ onUpdate={(range) => {
+ updateSelectedRange(range.range);
+ setOpen(false);
+ }}
+ onReset={() => updateSelectedRange(undefined)}
/>
-
-
-
-
>
);
if (isMobile) {
return (
-
+
{trigger}
{content}
@@ -144,9 +141,9 @@ export function CalendarRangeFilterButton({
}
return (
-
+
{trigger}
- {content}
+ {content}
);
}
diff --git a/web/src/components/ui/calendar-range.tsx b/web/src/components/ui/calendar-range.tsx
index f940e772e..5629c5ce9 100644
--- a/web/src/components/ui/calendar-range.tsx
+++ b/web/src/components/ui/calendar-range.tsx
@@ -1,7 +1,4 @@
-/* eslint-disable max-lines */
-"use client";
-
-import { type FC, useState, useEffect, useRef } from "react";
+import { useState, useEffect, useRef } from "react";
import { Button } from "./button";
import { Calendar } from "./calendar";
import { Label } from "./label";
@@ -19,6 +16,7 @@ import { LuCheck } from "react-icons/lu";
export interface DateRangePickerProps {
/** Click handler for applying the updates from DateRangePicker. */
onUpdate?: (values: { range: DateRange; rangeCompare?: DateRange }) => void;
+ onReset?: () => void;
/** Initial value for start date */
initialDateFrom?: Date | string;
/** Initial value for end date */
@@ -73,14 +71,15 @@ const PRESETS: Preset[] = [
];
/** The DateRangePicker component allows a user to select a range of dates */
-export const DateRangePicker: FC = ({
+export function DateRangePicker({
initialDateFrom = new Date(new Date().setHours(0, 0, 0, 0)),
initialDateTo,
initialCompareFrom,
initialCompareTo,
onUpdate,
+ onReset,
showCompare = true,
-}): JSX.Element => {
+}: DateRangePickerProps) {
const [isOpen, setIsOpen] = useState(false);
const [range, setRange] = useState({
@@ -283,7 +282,7 @@ export const DateRangePicker: FC = ({
isSelected: boolean;
}): JSX.Element => (