From dff39cee656bdeb36a7e48c3d18843fc63a89103 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 25 Jan 2022 12:05:16 +0100 Subject: [PATCH] feat(api): sessions search default sort feat(api): funnels ignore empty values feat(api): sessions search ignore empty values feat(api): saved search return filter feat(api): saved search return empty filter --- api/chalicelib/core/saved_search.py | 2 ++ api/chalicelib/core/sessions.py | 4 ++++ api/chalicelib/core/significance.py | 2 ++ api/routers/core.py | 2 +- api/schemas.py | 2 +- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/chalicelib/core/saved_search.py b/api/chalicelib/core/saved_search.py index 732fc1596..d1e8fe15f 100644 --- a/api/chalicelib/core/saved_search.py +++ b/api/chalicelib/core/saved_search.py @@ -77,6 +77,8 @@ def get_all(project_id, user_id, details=False): for row in rows: row["createdAt"] = TimeUTC.datetime_to_timestamp(row["createdAt"]) if details: + if isinstance(row["filter"], list) and len(row["filter"]) == 0: + row["filter"] = {} row["filter"] = helper.old_search_payload_to_flat(row["filter"]) return rows diff --git a/api/chalicelib/core/sessions.py b/api/chalicelib/core/sessions.py index 8eb58a29d..f5617789d 100644 --- a/api/chalicelib/core/sessions.py +++ b/api/chalicelib/core/sessions.py @@ -297,6 +297,8 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr op = __get_sql_operator(f.operator) \ if filter_type not in [schemas.FilterType.events_count] else f.operator is_any = _isAny_opreator(f.operator) + if not is_any and len(f.value) == 0: + continue is_not = False if __is_negation_operator(f.operator): is_not = True @@ -445,6 +447,8 @@ def search_query_parts(data, error_status, errors_only, favorite_only, issue, pr is_any = _isAny_opreator(event.operator) if not isinstance(event.value, list): event.value = [event.value] + if not is_any and len(event.value) == 0: + continue op = __get_sql_operator(event.operator) is_not = False if __is_negation_operator(event.operator): diff --git a/api/chalicelib/core/significance.py b/api/chalicelib/core/significance.py index f2261ce59..2580a7584 100644 --- a/api/chalicelib/core/significance.py +++ b/api/chalicelib/core/significance.py @@ -130,6 +130,8 @@ def get_stages_and_events(filter_d, project_id) -> List[RealDictRow]: if not isinstance(s["value"], list): s["value"] = [s["value"]] is_any = sessions._isAny_opreator(s["operator"]) + if not is_any and isinstance(s["value"], list) and len(s["value"]) == 0: + continue op = sessions.__get_sql_operator(s["operator"]) event_type = s["type"].upper() if event_type == events.event_type.CLICK.ui_type: diff --git a/api/routers/core.py b/api/routers/core.py index bbeb30bcd..81ed07cca 100644 --- a/api/routers/core.py +++ b/api/routers/core.py @@ -1124,7 +1124,7 @@ def add_saved_search(projectId: int, data: schemas.SavedSearchSchema = Body(...) @app.get('/{projectId}/saved_search', tags=["savedSearch"]) def get_saved_searches(projectId: int, context: schemas.CurrentContext = Depends(OR_context)): - return {"data": saved_search.get_all(project_id=projectId, user_id=context.user_id)} + return {"data": saved_search.get_all(project_id=projectId, user_id=context.user_id, details=True)} @app.get('/{projectId}/saved_search/{search_id}', tags=["savedSearch"]) diff --git a/api/schemas.py b/api/schemas.py index af2034061..0c3493121 100644 --- a/api/schemas.py +++ b/api/schemas.py @@ -536,7 +536,7 @@ class SessionsSearchPayloadSchema(BaseModel): # rangeValue:str=Field(...) startDate: int = Field(None) endDate: int = Field(None) - sort: str = Field(...) + sort: str = Field(default="startTs") order: str = Field(default="DESC") # platform: Optional[PlatformType] = Field(None) events_order: Optional[SearchEventOrder] = Field(default=SearchEventOrder._then)