Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions ddpui/api/public_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,16 @@ def get_public_chart_data(request, token: str, chart_id: int):
extra_config = chart.extra_config.copy() if chart.extra_config else {}

# Parse and resolve dashboard filters if provided
# Uses schema/table match (no warehouse_client) to check filter applicability
resolved_dashboard_filters = None
if filters:
warehouse_client = WarehouseFactory.get_warehouse_client(org_warehouse)
filter_defs = DashboardFilter.objects.filter(id__in=filters.keys(), dashboard=dashboard)
resolved_dashboard_filters = DashboardService.resolve_dashboard_filters_for_chart(
filters,
[f.to_json() for f in filter_defs],
chart.schema_name,
chart.table_name,
warehouse_client,
)

config = ChartConfig(
Expand Down Expand Up @@ -1295,7 +1296,12 @@ def get_public_report_chart_data(request, token: str, chart_id: int):
response={200: dict, 404: PublicErrorResponse},
)
def get_public_report_table_data(
request, token: str, chart_id: int, page: int = 0, limit: int = 100
request,
token: str,
chart_id: int,
page: int = 0,
limit: int = 100,
dashboard_filters: Optional[str] = None,
):
"""Get table chart data for a public report"""
try:
Expand All @@ -1310,7 +1316,27 @@ def get_public_report_table_data(
title=chart_config.get("title"),
extra_config=chart_config.get("extra_config"),
)
chart_payload = charts_service.build_chart_data_payload(config)

# Resolve dashboard filters from the report's frozen config (same pattern as get_public_report_chart_data)
resolved_filters = None
if dashboard_filters:
try:
filter_values = json.loads(dashboard_filters)
except json.JSONDecodeError:
filter_values = None

if filter_values:
frozen_filters = snapshot.frozen_dashboard.get("filters", [])
warehouse_client = WarehouseFactory.get_warehouse_client(org_warehouse)
resolved_filters = DashboardService.resolve_dashboard_filters_for_chart(
filter_values,
frozen_filters,
chart_config["schema_name"],
chart_config["table_name"],
warehouse_client,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

chart_payload = charts_service.build_chart_data_payload(config, resolved_filters)

preview_data = charts_service.get_chart_data_table_preview(
org_warehouse, chart_payload, page, limit
Expand Down Expand Up @@ -1339,7 +1365,9 @@ def get_public_report_table_data(
"/reports/{token}/charts/{chart_id}/total-rows/",
response={200: dict, 404: PublicErrorResponse},
)
def get_public_report_table_total_rows(request, token: str, chart_id: int):
def get_public_report_table_total_rows(
request, token: str, chart_id: int, dashboard_filters: Optional[str] = None
):
"""Get total row count for table chart in a public report"""
try:
snapshot, chart_config, org_warehouse = _get_frozen_chart_for_public_report(
Expand All @@ -1353,7 +1381,27 @@ def get_public_report_table_total_rows(request, token: str, chart_id: int):
title=chart_config.get("title"),
extra_config=chart_config.get("extra_config"),
)
chart_payload = charts_service.build_chart_data_payload(config)

# Resolve dashboard filters from the report's frozen config (same pattern as get_public_report_chart_data)
resolved_filters = None
if dashboard_filters:
try:
filter_values = json.loads(dashboard_filters)
except json.JSONDecodeError:
filter_values = None

if filter_values:
frozen_filters = snapshot.frozen_dashboard.get("filters", [])
warehouse_client = WarehouseFactory.get_warehouse_client(org_warehouse)
resolved_filters = DashboardService.resolve_dashboard_filters_for_chart(
filter_values,
frozen_filters,
chart_config["schema_name"],
chart_config["table_name"],
warehouse_client,
)

chart_payload = charts_service.build_chart_data_payload(config, resolved_filters)

total_rows = charts_service.get_chart_data_total_rows(org_warehouse, chart_payload)

Expand Down
Loading