refactor(chalice): changed product analytics to return full filters with possible types

This commit is contained in:
Taha Yassine Kraiem 2025-03-26 13:09:04 +01:00 committed by Kraiem Taha Yassine
parent bb17f672fe
commit 856e716507
3 changed files with 9 additions and 7 deletions

View file

@ -259,7 +259,7 @@ def get_for_filters(project_id):
results.append({"id": f"meta_{i}", results.append({"id": f"meta_{i}",
"name": k, "name": k,
"displayName": metas[k], "displayName": metas[k],
"type": "string", "possibleTypes": ["String"],
"autoCaptured": False, "autoCaptured": False,
"icon": None}) "icon": None})
return {"total": len(results), "list": results} return {"total": len(results), "list": results}

View file

@ -12,7 +12,7 @@ def get_events(project_id: int, page: schemas.PaginatedSchema):
with ClickHouseClient() as ch_client: with ClickHouseClient() as ch_client:
r = ch_client.format( r = ch_client.format(
"""SELECT COUNT(1) OVER () AS total, """SELECT COUNT(1) OVER () AS total,
event_name, display_name, description, event_name AS name, display_name, description,
auto_captured auto_captured
FROM product_analytics.all_events FROM product_analytics.all_events
WHERE project_id=%(project_id)s WHERE project_id=%(project_id)s
@ -26,9 +26,9 @@ def get_events(project_id: int, page: schemas.PaginatedSchema):
for i, row in enumerate(rows): for i, row in enumerate(rows):
row["id"] = f"event_{i}" row["id"] = f"event_{i}"
row["icon"] = None row["icon"] = None
row["type"] = "string" row["possibleTypes"] = ["String"]
row.pop("total") row.pop("total")
return {"total": total, "list": rows} return {"total": total, "list": helper.list_to_camel_case(rows)}
def search_events(project_id: int, data: schemas.EventsSearchPayloadSchema): def search_events(project_id: int, data: schemas.EventsSearchPayloadSchema):

View file

@ -7,10 +7,12 @@ def get_all_properties(project_id: int, page: schemas.PaginatedSchema):
with ClickHouseClient() as ch_client: with ClickHouseClient() as ch_client:
r = ch_client.format( r = ch_client.format(
"""SELECT COUNT(1) OVER () AS total, """SELECT COUNT(1) OVER () AS total,
property_name, property_name AS name, display_name,
display_name array_agg(DISTINCT event_properties.value_type) AS possible_types
FROM product_analytics.all_properties FROM product_analytics.all_properties
LEFT JOIN product_analytics.event_properties USING (project_id, property_name)
WHERE all_properties.project_id=%(project_id)s WHERE all_properties.project_id=%(project_id)s
GROUP BY property_name,display_name
ORDER BY display_name ORDER BY display_name
LIMIT %(limit)s OFFSET %(offset)s;""", LIMIT %(limit)s OFFSET %(offset)s;""",
parameters={"project_id": project_id, parameters={"project_id": project_id,