mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-27 20:38:32 +02:00
add new date search filter (#3065)
* add new complicated filters * clarity updates * update date range filter
This commit is contained in:
@@ -24,6 +24,11 @@ import { FilterDropdown } from "./FilterDropdown";
|
|||||||
import { listSourceMetadata } from "@/lib/sources";
|
import { listSourceMetadata } from "@/lib/sources";
|
||||||
import { SourceIcon } from "@/components/SourceIcon";
|
import { SourceIcon } from "@/components/SourceIcon";
|
||||||
import { TagFilter } from "./TagFilter";
|
import { TagFilter } from "./TagFilter";
|
||||||
|
import { Calendar } from "@/components/ui/calendar";
|
||||||
|
import { Popover, PopoverTrigger } from "@/components/ui/popover";
|
||||||
|
import { PopoverContent } from "@radix-ui/react-popover";
|
||||||
|
import { CalendarIcon } from "lucide-react";
|
||||||
|
import { buildDateString, getTimeAgoString } from "@/lib/dateUtils";
|
||||||
|
|
||||||
const SectionTitle = ({ children }: { children: string }) => (
|
const SectionTitle = ({ children }: { children: string }) => (
|
||||||
<div className="font-bold text-xs mt-2 flex">{children}</div>
|
<div className="font-bold text-xs mt-2 flex">{children}</div>
|
||||||
@@ -106,10 +111,39 @@ export function SourceSelector({
|
|||||||
<FiFilter className="my-auto ml-2" size="16" />
|
<FiFilter className="my-auto ml-2" size="16" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<SectionTitle>Time Range</SectionTitle>
|
<Popover>
|
||||||
<div className="mt-2">
|
<PopoverTrigger asChild>
|
||||||
<DateRangeSelector value={timeRange} onValueChange={setTimeRange} />
|
<div className="cursor-pointer">
|
||||||
</div>
|
<SectionTitle>Time Range</SectionTitle>
|
||||||
|
<p className="text-sm text-default mt-2">
|
||||||
|
{getTimeAgoString(timeRange?.from!) || "Select a time range"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent
|
||||||
|
className="bg-background border-border border rounded-md z-[200] p-0"
|
||||||
|
align="start"
|
||||||
|
>
|
||||||
|
<Calendar
|
||||||
|
mode="range"
|
||||||
|
selected={
|
||||||
|
timeRange
|
||||||
|
? { from: new Date(timeRange.from), to: new Date(timeRange.to) }
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
onSelect={(daterange) => {
|
||||||
|
const initialDate = daterange?.from || new Date();
|
||||||
|
const endDate = daterange?.to || new Date();
|
||||||
|
setTimeRange({
|
||||||
|
from: initialDate,
|
||||||
|
to: endDate,
|
||||||
|
selectValue: timeRange?.selectValue || "",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
className="rounded-md "
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
{availableTags.length > 0 && (
|
{availableTags.length > 0 && (
|
||||||
<>
|
<>
|
||||||
@@ -424,14 +458,57 @@ export function HorizontalSourceSelector({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-nowrap space-x-2">
|
<div className="flex flex-nowrap space-x-2">
|
||||||
<div className="max-w-24">
|
<Popover>
|
||||||
<DateRangeSelector
|
<PopoverTrigger asChild>
|
||||||
isHorizontal
|
<div
|
||||||
value={timeRange}
|
className={`
|
||||||
onValueChange={setTimeRange}
|
border
|
||||||
className="bg-background-search-filter"
|
max-w-36
|
||||||
/>
|
border-border
|
||||||
</div>
|
rounded-lg
|
||||||
|
bg-background
|
||||||
|
max-h-96
|
||||||
|
overflow-y-scroll
|
||||||
|
overscroll-contain
|
||||||
|
px-3
|
||||||
|
text-sm
|
||||||
|
py-1.5
|
||||||
|
select-none
|
||||||
|
cursor-pointer
|
||||||
|
w-fit
|
||||||
|
gap-x-1
|
||||||
|
hover:bg-hover
|
||||||
|
bg-hover-light
|
||||||
|
flex
|
||||||
|
items-center
|
||||||
|
bg-background-search-filter
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
<CalendarIcon className="h-4 w-4" />
|
||||||
|
|
||||||
|
{timeRange?.from ? getTimeAgoString(timeRange.from) : "Since"}
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent
|
||||||
|
className="bg-background border-border border rounded-md z-[200] p-0"
|
||||||
|
align="start"
|
||||||
|
>
|
||||||
|
<Calendar
|
||||||
|
mode="single"
|
||||||
|
selected={timeRange ? new Date(timeRange.from) : undefined}
|
||||||
|
onSelect={(date) => {
|
||||||
|
const selectedDate = date || new Date();
|
||||||
|
const today = new Date();
|
||||||
|
setTimeRange({
|
||||||
|
from: selectedDate > today ? today : selectedDate,
|
||||||
|
to: today,
|
||||||
|
selectValue: timeRange?.selectValue || "",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
className="rounded-md "
|
||||||
|
/>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
{existingSources.length > 0 && (
|
{existingSources.length > 0 && (
|
||||||
<FilterDropdown
|
<FilterDropdown
|
||||||
|
@@ -41,7 +41,7 @@ function Calendar({
|
|||||||
buttonVariants({ variant: "ghost" }),
|
buttonVariants({ variant: "ghost" }),
|
||||||
"h-9 w-9 p-0 font-normal aria-selected:opacity-100"
|
"h-9 w-9 p-0 font-normal aria-selected:opacity-100"
|
||||||
),
|
),
|
||||||
day_range_end: "day-range-end",
|
day_range_end: "day-range-end !text-neutral-200",
|
||||||
day_selected:
|
day_selected:
|
||||||
"bg-neutral-900 text-neutral-50 hover:bg-neutral-900 hover:text-neutral-50 focus:bg-neutral-900 focus:text-neutral-50 dark:bg-neutral-50 dark:text-neutral-900 dark:hover:bg-neutral-50 dark:hover:text-neutral-900 dark:focus:bg-neutral-50 dark:focus:text-neutral-900",
|
"bg-neutral-900 text-neutral-50 hover:bg-neutral-900 hover:text-neutral-50 focus:bg-neutral-900 focus:text-neutral-50 dark:bg-neutral-50 dark:text-neutral-900 dark:hover:bg-neutral-50 dark:hover:text-neutral-900 dark:focus:bg-neutral-50 dark:focus:text-neutral-900",
|
||||||
day_today:
|
day_today:
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
import { DateRangePickerValue } from "@/app/ee/admin/performance/DateRangeSelector";
|
||||||
|
|
||||||
export function getXDaysAgo(daysAgo: number) {
|
export function getXDaysAgo(daysAgo: number) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const daysAgoDate = new Date(today);
|
const daysAgoDate = new Date(today);
|
||||||
@@ -46,3 +48,25 @@ export const timestampToReadableDate = (timestamp: string) => {
|
|||||||
date.toLocaleTimeString(undefined, timeOptions)
|
date.toLocaleTimeString(undefined, timeOptions)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const buildDateString = (date: Date | null) => {
|
||||||
|
return date
|
||||||
|
? `${Math.round(
|
||||||
|
(new Date().getTime() - date.getTime()) / (1000 * 60 * 60 * 24)
|
||||||
|
)} days ago`
|
||||||
|
: "Select a time range";
|
||||||
|
};
|
||||||
|
export const getTimeAgoString = (date: Date | null) => {
|
||||||
|
if (!date) return null;
|
||||||
|
|
||||||
|
const diffMs = new Date().getTime() - date.getTime();
|
||||||
|
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
||||||
|
const diffWeeks = Math.floor(diffDays / 7);
|
||||||
|
const diffMonths = Math.floor(diffDays / 30);
|
||||||
|
|
||||||
|
if (buildDateString(date).includes("Today")) return "Today";
|
||||||
|
if (diffDays === 1) return "Yesterday";
|
||||||
|
if (diffDays < 7) return `${diffDays}d ago`;
|
||||||
|
if (diffDays < 30) return `${diffWeeks}w ago`;
|
||||||
|
return `${diffMonths}mo ago`;
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user