From 607e6a7be1b4b576e14d1980b6391bc1e18b3ea2 Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Thu, 17 Mar 2022 20:56:43 -0700 Subject: [PATCH] Update events chart when filter selected. Closes #494 --- components/metrics/EventsChart.js | 9 ++++++--- components/metrics/EventsTable.js | 11 +++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/components/metrics/EventsChart.js b/components/metrics/EventsChart.js index b44aa22d..c5d6a898 100644 --- a/components/metrics/EventsChart.js +++ b/components/metrics/EventsChart.js @@ -12,7 +12,9 @@ import { EVENT_COLORS, TOKEN_HEADER } from 'lib/constants'; export default function EventsChart({ websiteId, className, token }) { const [{ startDate, endDate, unit, modified }] = useDateRange(websiteId); const [timezone] = useTimezone(); - const { query } = usePageQuery(); + const { + query: { url, eventType }, + } = usePageQuery(); const shareToken = useShareToken(); const { data, loading } = useFetch( @@ -23,12 +25,13 @@ export default function EventsChart({ websiteId, className, token }) { end_at: +endDate, unit, tz: timezone, - url: query.url, + url, + event_type: eventType, token, }, headers: { [TOKEN_HEADER]: shareToken?.token }, }, - [modified], + [modified, eventType], ); const datasets = useMemo(() => { diff --git a/components/metrics/EventsTable.js b/components/metrics/EventsTable.js index e497a25e..b3427775 100644 --- a/components/metrics/EventsTable.js +++ b/components/metrics/EventsTable.js @@ -4,16 +4,18 @@ import MetricsTable from './MetricsTable'; import Tag from 'components/common/Tag'; import DropDown from 'components/common/DropDown'; import { eventTypeFilter } from 'lib/filters'; +import usePageQuery from 'hooks/usePageQuery'; import styles from './EventsTable.module.css'; const EVENT_FILTER_DEFAULT = { - value: 'EVENT_FILTER_DEFAULT', + value: 'all', label: , }; export default function EventsTable({ websiteId, ...props }) { const [eventType, setEventType] = useState(EVENT_FILTER_DEFAULT.value); const [eventTypes, setEventTypes] = useState([]); + const { resolve, router } = usePageQuery(); const dropDownOptions = [EVENT_FILTER_DEFAULT, ...eventTypes.map(t => ({ value: t, label: t }))]; @@ -22,11 +24,16 @@ export default function EventsTable({ websiteId, ...props }) { props.onDataLoad?.(data); } + function handleChange(value) { + router.replace(resolve({ eventType: value === 'all' ? undefined : value })); + setEventType(value); + } + return ( <> {eventTypes?.length > 1 && (
- +
)}