From 8fe44d72f99b1344fd6726f6bdf67982e0e43421 Mon Sep 17 00:00:00 2001 From: Kraiem Taha Yassine Date: Mon, 8 Jul 2024 15:16:33 +0200 Subject: [PATCH] Dev (#2367) * refactor(chalice): upgraded dependencies * refactor(chalice): upgraded dependencies feat(chalice): support heatmaps * feat(chalice): support table-of-browsers showing user-count * feat(chalice): support table-of-devices showing user-count * feat(chalice): support table-of-URLs showing user-count * fix(chalice): fixed Math-operators validation refactor(chalice): search for sessions that have events for heatmaps * refactor(chalice): search for sessions that have at least 1 location event for heatmaps * refactor(chalice): return notes-count * fix(chalice): fixed create heatmap with no replay --- api/chalicelib/core/sessions_notes.py | 14 ++++++++++---- ee/api/chalicelib/core/heatmaps.py | 5 ++++- ee/api/chalicelib/core/sessions_notes.py | 14 ++++++++++---- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/api/chalicelib/core/sessions_notes.py b/api/chalicelib/core/sessions_notes.py index 4bc2138e1..200f6399d 100644 --- a/api/chalicelib/core/sessions_notes.py +++ b/api/chalicelib/core/sessions_notes.py @@ -1,3 +1,4 @@ +import logging from urllib.parse import urljoin from decouple import config @@ -9,6 +10,8 @@ from chalicelib.utils import pg_client, helper from chalicelib.utils import sql_helper as sh from chalicelib.utils.TimeUTC import TimeUTC +logger = logging.getLogger(__name__) + def get_note(tenant_id, project_id, user_id, note_id, share=None): with pg_client.PostgresClient() as cur: @@ -66,19 +69,22 @@ def get_all_notes_by_project_id(tenant_id, project_id, user_id, data: schemas.Se conditions.append("sessions_notes.user_id = %(user_id)s") else: conditions.append("(sessions_notes.user_id = %(user_id)s OR sessions_notes.is_public)") - query = cur.mogrify(f"""SELECT sessions_notes.*, users.name AS user_name + query = cur.mogrify(f"""SELECT COUNT(1) OVER () AS full_count, sessions_notes.*, users.name AS user_name FROM sessions_notes INNER JOIN users USING (user_id) WHERE {" AND ".join(conditions)} ORDER BY created_at {data.order} LIMIT {data.limit} OFFSET {data.limit * (data.page - 1)};""", {"project_id": project_id, "user_id": user_id, "tenant_id": tenant_id, **extra_params}) - + logger.debug(query) cur.execute(query=query) rows = cur.fetchall() - rows = helper.list_to_camel_case(rows) + result = {"count": 0, "notes": helper.list_to_camel_case(rows)} + if len(rows) > 0: + result["count"] = rows[0]["fullCount"] for row in rows: row["createdAt"] = TimeUTC.datetime_to_timestamp(row["createdAt"]) - return rows + row.pop("fullCount") + return result def create(tenant_id, user_id, project_id, session_id, data: schemas.SessionNoteSchema): diff --git a/ee/api/chalicelib/core/heatmaps.py b/ee/api/chalicelib/core/heatmaps.py index 2c213e763..18f2fc12e 100644 --- a/ee/api/chalicelib/core/heatmaps.py +++ b/ee/api/chalicelib/core/heatmaps.py @@ -347,7 +347,8 @@ else: logger.warning("--------------------") raise err - if session: + if len(session) > 0: + session = session[0] if include_mobs: session['domURL'] = sessions_mobs.get_urls(session_id=session["session_id"], project_id=project_id) session['mobsUrl'] = sessions_mobs.get_urls_depercated(session_id=session["session_id"]) @@ -361,6 +362,8 @@ else: session['events'] = events.get_by_session_id(project_id=project_id, session_id=session["session_id"], event_type=schemas.EventType.location) + else: + return None return helper.dict_to_camel_case(session) diff --git a/ee/api/chalicelib/core/sessions_notes.py b/ee/api/chalicelib/core/sessions_notes.py index 97ab14f9c..a3b2c9328 100644 --- a/ee/api/chalicelib/core/sessions_notes.py +++ b/ee/api/chalicelib/core/sessions_notes.py @@ -1,3 +1,4 @@ +import logging from urllib.parse import urljoin from decouple import config @@ -9,6 +10,8 @@ from chalicelib.utils import pg_client, helper from chalicelib.utils import sql_helper as sh from chalicelib.utils.TimeUTC import TimeUTC +logger = logging.getLogger(__name__) + def get_note(tenant_id, project_id, user_id, note_id, share=None): with pg_client.PostgresClient() as cur: @@ -68,19 +71,22 @@ def get_all_notes_by_project_id(tenant_id, project_id, user_id, data: schemas.Se else: conditions.append( "(sessions_notes.user_id = %(user_id)s OR sessions_notes.is_public AND users.tenant_id = %(tenant_id)s)") - query = cur.mogrify(f"""SELECT sessions_notes.*, users.name AS user_name + query = cur.mogrify(f"""SELECT COUNT(1) OVER () AS full_count, sessions_notes.*, users.name AS user_name FROM sessions_notes INNER JOIN users USING (user_id) WHERE {" AND ".join(conditions)} ORDER BY created_at {data.order} LIMIT {data.limit} OFFSET {data.limit * (data.page - 1)};""", {"project_id": project_id, "user_id": user_id, "tenant_id": tenant_id, **extra_params}) - + logger.debug(query) cur.execute(query=query) rows = cur.fetchall() - rows = helper.list_to_camel_case(rows) + result = {"count": 0, "notes": helper.list_to_camel_case(rows)} + if len(rows) > 0: + result["count"] = rows[0]["fullCount"] for row in rows: row["createdAt"] = TimeUTC.datetime_to_timestamp(row["createdAt"]) - return rows + row.pop("fullCount") + return result def create(tenant_id, user_id, project_id, session_id, data: schemas.SessionNoteSchema):