From 8c4f3b1155a7c2bdc97621f8a9f21ed5445f6150 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 31 Jan 2023 18:12:28 +0100 Subject: [PATCH 1/3] feat(chalice): fixed table of urls query --- api/chalicelib/core/sessions.py | 12 +++++++----- ee/api/chalicelib/core/sessions.py | 6 ++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index 0921556af..fa1aa6aca 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -204,9 +204,9 @@ def search_sessions(data: schemas.SessionsSearchPayloadSchema, project_id, user_ ORDER BY s.session_id desc) AS filtred_sessions ORDER BY {sort} {data.order}, issue_score DESC) AS full_sessions;""", full_args) - # print("--------------------") - # print(main_query) - # print("--------------------") + print("--------------------") + print(main_query) + print("--------------------") try: cur.execute(main_query) except Exception as err: @@ -301,6 +301,7 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d extra_col = "" extra_where = "" pre_query = "" + distinct_on="s.session_id" if metric_of == schemas.MetricOfTable.user_country: main_col = "user_country" elif metric_of == schemas.MetricOfTable.user_device: @@ -320,13 +321,14 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d elif metric_of == schemas.MetricOfTable.visited_url: main_col = "path" extra_col = ", path" + distinct_on+=",path" main_query = cur.mogrify(f"""{pre_query} SELECT COUNT(*) AS count, COALESCE(JSONB_AGG(users_sessions) FILTER ( WHERE rn <= 200 ), '[]'::JSONB) AS values FROM (SELECT {main_col} AS name, - count(full_sessions) AS session_count, + count(DISTINCT session_id) AS session_count, ROW_NUMBER() OVER (ORDER BY count(full_sessions) DESC) AS rn FROM (SELECT * - FROM (SELECT DISTINCT ON(s.session_id) s.session_id, s.user_uuid, + FROM (SELECT DISTINCT ON({distinct_on}) s.session_id, s.user_uuid, s.user_id, s.user_os, s.user_browser, s.user_device, s.user_device_type, s.user_country, s.issue_types{extra_col} diff --git a/ee/api/chalicelib/core/sessions.py b/ee/api/chalicelib/core/sessions.py index bc3e0ebab..bc7613278 100644 --- a/ee/api/chalicelib/core/sessions.py +++ b/ee/api/chalicelib/core/sessions.py @@ -304,6 +304,7 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d extra_col = "" extra_where = "" pre_query = "" + distinct_on="s.session_id" if metric_of == schemas.MetricOfTable.user_country: main_col = "user_country" elif metric_of == schemas.MetricOfTable.user_device: @@ -323,13 +324,14 @@ def search2_series(data: schemas.SessionsSearchPayloadSchema, project_id: int, d elif metric_of == schemas.MetricOfTable.visited_url: main_col = "path" extra_col = ", path" + distinct_on+=",path" main_query = cur.mogrify(f"""{pre_query} SELECT COUNT(*) AS count, COALESCE(JSONB_AGG(users_sessions) FILTER ( WHERE rn <= 200 ), '[]'::JSONB) AS values FROM (SELECT {main_col} AS name, - count(full_sessions) AS session_count, + count(DISTINCT session_id) AS session_count, ROW_NUMBER() OVER (ORDER BY count(full_sessions) DESC) AS rn FROM (SELECT * - FROM (SELECT DISTINCT ON(s.session_id) s.session_id, s.user_uuid, + FROM (SELECT DISTINCT ON({distinct_on}) s.session_id, s.user_uuid, s.user_id, s.user_os, s.user_browser, s.user_device, s.user_device_type, s.user_country, s.issue_types{extra_col} From 68c5700aa1dbfa1e454a3e62308a631a6ff94447 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 31 Jan 2023 17:01:05 +0100 Subject: [PATCH 2/3] fix(ui) - reset drilldown filter --- .../components/WidgetChart/WidgetChart.tsx | 6 ++++++ frontend/app/mstore/dashboardStore.ts | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx b/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx index d4ed53324..0663268a1 100644 --- a/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx +++ b/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx @@ -47,6 +47,12 @@ function WidgetChart(props: Props) { const isTableWidget = metric.metricType === 'table' && metric.viewType === 'table'; const isPieChart = metric.metricType === 'table' && metric.viewType === 'pieChart'; + useEffect(() => { + return () => { + dashboardStore.resetDrillDownFilter(); + } + }, []) + const onChartClick = (event: any) => { if (event) { if (isTableWidget || isPieChart) { // get the filter of clicked row diff --git a/frontend/app/mstore/dashboardStore.ts b/frontend/app/mstore/dashboardStore.ts index 530948466..bd8681c2f 100644 --- a/frontend/app/mstore/dashboardStore.ts +++ b/frontend/app/mstore/dashboardStore.ts @@ -52,10 +52,7 @@ export default class DashboardStore { constructor() { makeAutoObservable(this); - this.drillDownPeriod = Period({ rangeName: LAST_7_DAYS }); - const timeStamps = this.drillDownPeriod.toTimestamps(); - this.drillDownFilter.updateKey('startTimestamp', timeStamps.startTimestamp); - this.drillDownFilter.updateKey('endTimestamp', timeStamps.endTimestamp); + this.resetDrillDownFilter(); } get sortedDashboards() { @@ -65,6 +62,14 @@ export default class DashboardStore { ); } + resetDrillDownFilter() { + this.drillDownFilter = new Filter(); + this.drillDownPeriod = Period({ rangeName: LAST_7_DAYS }); + const timeStamps = this.drillDownPeriod.toTimestamps(); + this.drillDownFilter.updateKey('startTimestamp', timeStamps.startTimestamp); + this.drillDownFilter.updateKey('endTimestamp', timeStamps.endTimestamp); + } + get filteredList() { const filterRE = this.filter.query ? getRE(this.filter.query, 'i') : null; return this.dashboards From df4ea3788a8579cd55f98f9f7eece0f28daa11d6 Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Tue, 31 Jan 2023 17:57:29 +0100 Subject: [PATCH 3/3] fix(ui) - fix card table pagination reset on filter change --- .../Dashboard/components/WidgetChart/WidgetChart.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx b/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx index 0663268a1..cf44102d4 100644 --- a/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx +++ b/frontend/app/components/Dashboard/components/WidgetChart/WidgetChart.tsx @@ -87,7 +87,7 @@ function WidgetChart(props: Props) { } const debounceRequest: any = React.useCallback(debounce(fetchMetricChartData, 500), []); - useEffect(() => { + const loadPage = () => { if (prevMetricRef.current && prevMetricRef.current.name !== metric.name) { prevMetricRef.current = metric; return @@ -96,7 +96,12 @@ function WidgetChart(props: Props) { const timestmaps = drillDownPeriod.toTimestamps(); const payload = isWidget ? { ...params } : { ...metricParams, ...timestmaps, ...metric.toJson() }; debounceRequest(metric, payload, isWidget, !isWidget ? drillDownPeriod : period); - }, [drillDownPeriod, period, depsString, _metric.page, metric.metricType, metric.metricOf, metric.viewType, metric.metricValue]); + } + useEffect(() => { + _metric.updateKey('page', 1) + loadPage(); + }, [drillDownPeriod, period, depsString, metric.metricType, metric.metricOf, metric.viewType, metric.metricValue]); + useEffect(loadPage, [_metric.page]); const renderChart = () => {