Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(ui): persist dateRange filter state of dashboard (#3298)

marliessophie7c90bbed0caa
diff --git a/web/src/hooks/useDashboardDateRange.tsx b/web/src/hooks/useDashboardDateRange.tsx
index 386172d415..f0f1d167f1 100644
--- a/web/src/hooks/useDashboardDateRange.tsx
+++ b/web/src/hooks/useDashboardDateRange.tsx
@@ -19,6 +19,12 @@ export interface UseDashboardDateRangeOutput {
) => void;
}
+function isDashboardDateRangeAggregationOption(
+ dateRange?: string | null,
+): dateRange is DashboardDateRangeAggregationOption {
+ return !!dateRange && dateRange in dashboardDateRangeAggregationSettings;
+}
+
export function useDashboardDateRange(): UseDashboardDateRangeOutput {
const [queryParams, setQueryParams] = useQueryParams({
dateRange: withDefault(StringParam, "Select a date range"),
@@ -26,7 +32,10 @@ export function useDashboardDateRange(): UseDashboardDateRangeOutput {
to: StringParam,
});
- const initialRangeOption: DashboardDateRangeAggregationOption = "24 hours";
+ const initialRangeOption: DashboardDateRangeAggregationOption =
+ isDashboardDateRangeAggregationOption(queryParams.dateRange)
+ ? queryParams.dateRange
+ : "24 hours";
const initialRange: DashboardDateRange | undefined =
queryParams.dateRange !== "Select a date range" &&
diff --git a/web/src/pages/project/[projectId]/index.tsx b/web/src/pages/project/[projectId]/index.tsx
index 65152c5416..4eac6dc879 100644
--- a/web/src/pages/project/[projectId]/index.tsx
+++ b/web/src/pages/project/[projectId]/index.tsx
@@ -139,7 +139,7 @@ export default function Dashboard() {
<div className="md:container">
<Header title="Dashboard" actionButtons={<SetupTracingButton />} />
<div className="my-3 flex flex-wrap items-center justify-between gap-2">
- <div className=" flex flex-col gap-2 lg:flex-row">
+ <div className="flex flex-col gap-2 lg:flex-row">
<DatePickerWithRange
dateRange={dateRange}
setDateRangeAndOption={useDebounce(setDateRangeAndOption)}
@@ -201,7 +201,7 @@ export default function Dashboard() {
/>
{!disableExpensiveDashboardComponents && (
<ModelUsageChart
- className="col-span-1 min-h-24 xl:col-span-3"
+ className="col-span-1 min-h-24 xl:col-span-3"
projectId={projectId}
globalFilterState={mergedFilterState}
agg={agg}