From 9a014ab2ad598c4122a33f523c6ae0a6046b6a4f Mon Sep 17 00:00:00 2001 From: Drew Harris Date: Sat, 16 Nov 2024 13:55:40 -0600 Subject: [PATCH] feat: custom date picker for analytics overview --- .../dashboard/src/analytics/api/analytics.ts | 7 ++- .../components/charts/QueryCounts.tsx | 32 ++++++-------- .../analytics/pages/AnalyticsOverviewPage.tsx | 43 ++++++++++++------- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/frontends/dashboard/src/analytics/api/analytics.ts b/frontends/dashboard/src/analytics/api/analytics.ts index 6e7e5a8900..3c9bc0dfa7 100644 --- a/frontends/dashboard/src/analytics/api/analytics.ts +++ b/frontends/dashboard/src/analytics/api/analytics.ts @@ -19,6 +19,7 @@ import { UsageGraphResponse, RecommendationEvent, EventData, + DateRangeFilter, } from "shared/types"; import { transformAnalyticsFilter } from "../utils/formatDate"; @@ -257,7 +258,7 @@ export const getNoResultQueries = async ( }; export const getQueryCounts = async ( - gt_date: Date, + dateRange: DateRangeFilter, datasetId: string, ): Promise => { const response = await fetch(`${apiHost}/analytics/search`, { @@ -265,9 +266,7 @@ export const getQueryCounts = async ( method: "POST", body: JSON.stringify({ filter: transformAnalyticsFilter({ - date_range: { - gt: gt_date, - }, + date_range: dateRange, }), type: "count_queries", }), diff --git a/frontends/dashboard/src/analytics/components/charts/QueryCounts.tsx b/frontends/dashboard/src/analytics/components/charts/QueryCounts.tsx index fa2cf82387..745f7909f6 100644 --- a/frontends/dashboard/src/analytics/components/charts/QueryCounts.tsx +++ b/frontends/dashboard/src/analytics/components/charts/QueryCounts.tsx @@ -1,12 +1,12 @@ -import { SearchTypeCount } from "shared/types"; +import { DateRangeFilter, SearchTypeCount } from "shared/types"; import { createSignal, For, Show, useContext } from "solid-js"; import { createQuery } from "@tanstack/solid-query"; import { getQueryCounts } from "../../api/analytics"; import { toTitleCase } from "../../utils/titleCase"; -import { Select } from "shared/ui"; -import { DateRangeOption, dateRanges } from "../FilterBar"; +import { DateRangePicker } from "shared/ui"; import { CTRSummary } from "./CTRSummary"; import { DatasetContext } from "../../../contexts/DatasetContext"; +import { subDays } from "date-fns"; const displaySearchType = (type: SearchTypeCount["search_type"]) => { switch (type) { @@ -27,14 +27,15 @@ const displaySearchType = (type: SearchTypeCount["search_type"]) => { export const QueryCounts = () => { const dataset = useContext(DatasetContext); - const [dateSelection, setDateSelection] = createSignal( - dateRanges[2], - ); + + const [dateRange, setDateRange] = createSignal({ + gt: subDays(new Date(), 7), + }); const queryCountsQuery = createQuery(() => ({ - queryKey: ["queryCounts", { gt_date: dateSelection().date }], + queryKey: ["queryCounts", { filter: dateRange }], queryFn: () => { - return getQueryCounts(dateSelection().date, dataset.datasetId()); + return getQueryCounts(dateRange(), dataset.datasetId()); }, })); @@ -48,14 +49,9 @@ export const QueryCounts = () => {
-