diff --git a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/ClickMapCard/ClickMapCard.tsx b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/ClickMapCard/ClickMapCard.tsx index 0018e319a..b9412de7d 100644 --- a/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/ClickMapCard/ClickMapCard.tsx +++ b/frontend/app/components/Dashboard/Widgets/CustomMetricsWidgets/ClickMapCard/ClickMapCard.tsx @@ -7,7 +7,9 @@ import { setCustomSession } from 'App/duck/sessions' function ClickMapCard({ setCustomSession, visitedEvents }: any) { const { metricStore } = useStore(); - const onMarkerClick = (s: string) => console.log(s) + const onMarkerClick = (s: string, innerText: string) => { + metricStore.changeClickMapSearch(s, innerText) + } React.useEffect(() => { if (metricStore.instance.data.mobsUrl) { diff --git a/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx b/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx index cb459d7ee..01faed546 100644 --- a/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx +++ b/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx @@ -30,7 +30,7 @@ interface Props { function WidgetChart(props: Props) { const { isWidget = false, metric, isTemplate } = props; - const { dashboardStore, metricStore } = useStore(); + const { dashboardStore, metricStore, sessionStore } = useStore(); const _metric: any = metricStore.instance; const period = dashboardStore.period; const drillDownPeriod = dashboardStore.drillDownPeriod; @@ -180,7 +180,6 @@ function WidgetChart(props: Props) { } } if (metricType === CLICKMAP) { - console.log(props.isPreview) if (!props.isPreview) { return (
diff --git a/frontend/app/components/Dashboard/components/WidgetSessions/WidgetSessions.tsx b/frontend/app/components/Dashboard/components/WidgetSessions/WidgetSessions.tsx index d3a092b49..316bb55e9 100644 --- a/frontend/app/components/Dashboard/components/WidgetSessions/WidgetSessions.tsx +++ b/frontend/app/components/Dashboard/components/WidgetSessions/WidgetSessions.tsx @@ -10,6 +10,7 @@ import { debounce } from 'App/utils'; import useIsMounted from 'App/hooks/useIsMounted'; import AnimatedSVG, { ICONS } from 'Shared/AnimatedSVG/AnimatedSVG'; import { numberWithCommas } from 'App/utils'; +import { CLICKMAP } from "App/constants/card"; interface Props { className?: string; @@ -21,9 +22,9 @@ function WidgetSessions(props: Props) { const isMounted = useIsMounted(); const [loading, setLoading] = useState(false); const filteredSessions = getListSessionsBySeries(data, activeSeries); - const { dashboardStore, metricStore } = useStore(); - const filter = useObserver(() => dashboardStore.drillDownFilter); - const widget: any = useObserver(() => metricStore.instance); + const { dashboardStore, metricStore, sessionStore } = useStore(); + const filter = dashboardStore.drillDownFilter; + const widget = metricStore.instance; const startTime = DateTime.fromMillis(filter.startTimestamp).toFormat('LLL dd, yyyy HH:mm'); const endTime = DateTime.fromMillis(filter.endTimestamp).toFormat('LLL dd, yyyy HH:mm'); const [seriesOptions, setSeriesOptions] = useState([{ label: 'All', value: 'all' }]); @@ -50,30 +51,60 @@ function WidgetSessions(props: Props) { setLoading(false); }); }; + const fetchClickmapSessions = (customFilters: Record) => { + sessionStore.getSessions(customFilters) + .then(data => { + setData([{ ...data, seriesId: 1 , seriesName: "Clicks" }]) + }) + } const debounceRequest: any = React.useCallback(debounce(fetchSessions, 1000), []); + const debounceClickMapSearch = React.useCallback(debounce(fetchClickmapSessions, 1000), []) const depsString = JSON.stringify(widget.series); useEffect(() => { - debounceRequest(widget.metricId, { - ...filter, - series: widget.toJsonDrilldown(), - page: metricStore.sessionsPage, - limit: metricStore.sessionsPageSize, - }); - }, [filter.startTimestamp, filter.endTimestamp, filter.filters, depsString, metricStore.sessionsPage]); + if (widget.metricType === CLICKMAP && metricStore.clickMapSearch) { + const clickFilter = { + value: [ + metricStore.clickMapSearch + ], + type: "CLICK", + operator: "onSelector", + isEvent: true, + // @ts-ignore + "filters": [] + } + const timeRange = { + rangeValue: dashboardStore.drillDownPeriod.rangeValue, + startDate: dashboardStore.drillDownPeriod.start, + endDate: dashboardStore.drillDownPeriod.end, + } + const customFilter = { ...filter, ...timeRange, filters: [ ...sessionStore.userFilter.filters, clickFilter]} + debounceClickMapSearch(customFilter) + } else { + debounceRequest(widget.metricId, { + ...filter, + series: widget.toJsonDrilldown(), + page: metricStore.sessionsPage, + limit: metricStore.sessionsPageSize, + }); + } + }, [filter.startTimestamp, filter.endTimestamp, filter.filters, depsString, metricStore.sessionsPage, metricStore.clickMapSearch]); - return useObserver(() => ( + + + return (
-

Sessions

+

{metricStore.clickMapSearch ? 'Clicks' : 'Sessions'}

+ {metricStore.clickMapLabel ? `"${metricStore.clickMapLabel}" ` : null} between {startTime} and{' '} {endTime}{' '}
- {widget.metricType !== 'table' && ( + {widget.metricType !== 'table' && widget.metricType !== CLICKMAP && (
Filter by Series