fix(alerts&reports): tabs with userfriendly urls (#31350)

Co-authored-by: Erkka Tahvanainen <erkka.tahvanainen@confidently.fi>
This commit is contained in:
Erkka Tahvanainen 2024-12-09 19:21:38 +02:00 committed by GitHub
parent b54a97b5f0
commit 3bfead66c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 6 deletions

View File

@ -207,7 +207,7 @@ class BaseReportState:
if ( if (
dashboard_state := self._report_schedule.extra.get("dashboard") dashboard_state := self._report_schedule.extra.get("dashboard")
) and feature_flag_manager.is_feature_enabled("ALERT_REPORT_TABS"): ) and feature_flag_manager.is_feature_enabled("ALERT_REPORT_TABS"):
return self._get_tab_url(dashboard_state) return self._get_tab_url(dashboard_state, user_friendly=user_friendly)
dashboard = self._report_schedule.dashboard dashboard = self._report_schedule.dashboard
dashboard_id_or_slug = ( dashboard_id_or_slug = (
@ -234,7 +234,7 @@ class BaseReportState:
if anchor := dashboard_state.get("anchor"): if anchor := dashboard_state.get("anchor"):
try: try:
anchor_list: list[str] = json.loads(anchor) anchor_list: list[str] = json.loads(anchor)
return self._get_tabs_urls(anchor_list) return self._get_tabs_urls(anchor_list, user_friendly=user_friendly)
except json.JSONDecodeError: except json.JSONDecodeError:
logger.debug("Anchor value is not a list, Fall back to single tab") logger.debug("Anchor value is not a list, Fall back to single tab")
return [self._get_tab_url(dashboard_state)] return [self._get_tab_url(dashboard_state)]
@ -254,7 +254,9 @@ class BaseReportState:
) )
] ]
def _get_tab_url(self, dashboard_state: DashboardPermalinkState) -> str: def _get_tab_url(
self, dashboard_state: DashboardPermalinkState, user_friendly: bool = False
) -> str:
""" """
Get one tab url Get one tab url
""" """
@ -262,9 +264,15 @@ class BaseReportState:
dashboard_id=str(self._report_schedule.dashboard.uuid), dashboard_id=str(self._report_schedule.dashboard.uuid),
state=dashboard_state, state=dashboard_state,
).run() ).run()
return get_url_path("Superset.dashboard_permalink", key=permalink_key) return get_url_path(
"Superset.dashboard_permalink",
key=permalink_key,
user_friendly=user_friendly,
)
def _get_tabs_urls(self, tab_anchors: list[str]) -> list[str]: def _get_tabs_urls(
self, tab_anchors: list[str], user_friendly: bool = False
) -> list[str]:
""" """
Get multple tabs urls Get multple tabs urls
""" """
@ -275,7 +283,8 @@ class BaseReportState:
"dataMask": None, "dataMask": None,
"activeTabs": None, "activeTabs": None,
"urlParams": None, "urlParams": None,
} },
user_friendly=user_friendly,
) )
for tab_anchor in tab_anchors for tab_anchor in tab_anchors
] ]