:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(metrics): hide panel descriptions on imported dashboards (#119537)
Frank Hamand21a9c5fe10f5
diff --git a/products/dashboards/backend/dashboard_creation.py b/products/dashboards/backend/dashboard_creation.pyindex aab3efbb855b..5597e3b27a34 100644--- a/products/dashboards/backend/dashboard_creation.py+++ b/products/dashboards/backend/dashboard_creation.py@@ -51,6 +51,7 @@ class NewInsightTile:description: strquery: dict[str, Any]layout: TileLayout+ show_description: bool | None = None@frozen@@ -154,7 +155,11 @@ def create_dashboard_with_tiles(*, team_id: int, user_id: int, dashboard: NewDasif not was_created:raise ValueError("A dashboard was already created with this idempotency key.")created_tile = DashboardTile.objects.create(- dashboard=created, team_id=team_id, insight_id=insight_id, layouts=_layouts(tile.layout)+ dashboard=created,+ team_id=team_id,+ insight_id=insight_id,+ layouts=_layouts(tile.layout),+ show_description=tile.show_description,)insight_count += 1else:diff --git a/products/dashboards/backend/test/test_dashboard_creation.py b/products/dashboards/backend/test/test_dashboard_creation.pyindex 7c219408608e..b90c0f62d6f0 100644--- a/products/dashboards/backend/test/test_dashboard_creation.py+++ b/products/dashboards/backend/test/test_dashboard_creation.py@@ -16,6 +16,7 @@ from products.dashboards.backend.facade.dashboard_creation import (create_dashboard_with_tiles,)from products.dashboards.backend.models.dashboard import Dashboard+from products.dashboards.backend.models.dashboard_tile import DashboardTiledef _dashboard(key: str = "import-1") -> NewDashboard:@@ -66,3 +67,20 @@ class TestCreateDashboardWithTiles(APIBaseTest):assert (created.insight_count, created.text_tile_count) == (1, 1)assert list(Dashboard.objects.filter(team=self.team).values_list("id", flat=True)) == [created.id]++ @parameterized.expand([("default", None), ("hidden", False)])+ def test_sets_whether_an_insight_tile_shows_its_description(self, _name: str, show: bool | None) -> None:+ tile = NewInsightTile(+ name="Requests",+ description="Requests per second",+ query={"kind": "MetricsQuery", "language": "promql", "promql": "up", "clauses": []},+ layout=TileLayout(x=0, y=0, w=6, h=3),+ show_description=show,+ )+ created = create_dashboard_with_tiles(+ team_id=self.team.id,+ user_id=self.user.id,+ dashboard=NewDashboard(name="Imported", description="", idempotency_key="import-2", tiles=(tile,)),+ )++ assert DashboardTile.objects.get(id=created.tile_ids[0]).show_description is showdiff --git a/products/metrics/backend/dashboard_import/importer.py b/products/metrics/backend/dashboard_import/importer.pyindex ea9b09bb214b..b65c0e1b7256 100644--- a/products/metrics/backend/dashboard_import/importer.py+++ b/products/metrics/backend/dashboard_import/importer.py@@ -921,7 +921,14 @@ def _new_tile(tile: TileDraft) -> NewInsightTile | NewTextTile:layout = TileLayout(x=tile.layout.x, y=tile.layout.y, w=tile.layout.w, h=tile.layout.h)if tile.kind == "text":return NewTextTile(body=tile.text or "", layout=layout)- return NewInsightTile(name=tile.name, description=tile.description, query=tile.query or {}, layout=layout)+ # Grafana shows a panel description only in a tooltip, and the tile's (i) popover still shows a hidden one.+ return NewInsightTile(+ name=tile.name,+ description=tile.description,+ query=tile.query or {},+ layout=layout,+ show_description=False if tile.description else None,+ )def _delete_inputs(paths: list[str]) -> None:diff --git a/products/metrics/backend/tests/test_dashboard_import_api.py b/products/metrics/backend/tests/test_dashboard_import_api.pyindex e557ac980cd2..f26bb21abcdb 100644--- a/products/metrics/backend/tests/test_dashboard_import_api.py+++ b/products/metrics/backend/tests/test_dashboard_import_api.py@@ -150,6 +150,18 @@ class TestDashboardImportAPI(APIBaseTest):assert tiles[1].layouts == {"sm": {"x": 0, "y": 1, "w": 6, "h": 3}}self.workflow.assert_not_called()+ def test_hides_the_description_of_imported_panels_that_have_one(self) -> None:+ grafana = json.loads(_grafana("sum(rate(orders_total[5m]))", "sum(orders_total)"))+ grafana["panels"][1]["description"] = "Orders per second."++ body = self._start(source="grafana", grafana_json=json.dumps(grafana))++ tiles = DashboardTile.objects.filter(dashboard_id=body["dashboard_id"], insight__isnull=False)+ assert {(tile.insight.name if tile.insight else None, tile.show_description) for tile in tiles} == {+ ("Panel 2", False),+ ("Panel 3", None),+ }+def test_starts_a_read_only_agent_for_panels_it_cannot_match(self) -> None:body = self._start(source="grafana",