Skip to content

Commit 9db72d0

Browse files
authored
feat(dashboards): Surface split decision in widget type field (#74634)
Surface the split decision in the widget type field. This is because we don't return the split decision on subsequent requests when we detect that the `discover_widget_split` field is populated, but the frontend still needs to know which dataset to show on subsequent loads.
1 parent 7d304d1 commit 9db72d0

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

src/sentry/api/serializers/models/dashboard.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import orjson
44

5+
from sentry import features
56
from sentry.api.serializers import Serializer, register, serialize
67
from sentry.constants import ALL_ACCESS_PROJECTS
78
from sentry.models.dashboard import Dashboard
@@ -36,6 +37,21 @@ def get_attrs(self, item_list, user):
3637
return result
3738

3839
def serialize(self, obj, attrs, user, **kwargs):
40+
widget_type = (
41+
DashboardWidgetTypes.get_type_name(obj.widget_type)
42+
or DashboardWidgetTypes.TYPE_NAMES[0]
43+
)
44+
45+
if (
46+
features.has(
47+
"organizations:performance-discover-dataset-selector",
48+
obj.dashboard.organization,
49+
actor=user,
50+
)
51+
and obj.discover_widget_split is not None
52+
):
53+
widget_type = DashboardWidgetTypes.get_type_name(obj.discover_widget_split)
54+
3955
return {
4056
"id": str(obj.id),
4157
"title": obj.title,
@@ -49,8 +65,7 @@ def serialize(self, obj, attrs, user, **kwargs):
4965
"queries": attrs["queries"],
5066
"limit": obj.limit,
5167
# Default to discover type if null
52-
"widgetType": DashboardWidgetTypes.get_type_name(obj.widget_type)
53-
or DashboardWidgetTypes.TYPE_NAMES[0],
68+
"widgetType": widget_type,
5469
"layout": obj.detail.get("layout") if obj.detail else None,
5570
}
5671

tests/sentry/api/endpoints/test_organization_dashboard_details.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,52 @@ def test_response_truncates_with_retention(self):
216216
expected_adjusted_retention_start.replace(second=0)
217217
)
218218

219+
def test_dashboard_widget_type_returns_split_decision(self):
220+
dashboard = Dashboard.objects.create(
221+
title="Dashboard With Split Widgets",
222+
created_by_id=self.user.id,
223+
organization=self.organization,
224+
)
225+
DashboardWidget.objects.create(
226+
dashboard=dashboard,
227+
order=0,
228+
title="error widget",
229+
display_type=DashboardWidgetDisplayTypes.LINE_CHART,
230+
widget_type=DashboardWidgetTypes.DISCOVER,
231+
interval="1d",
232+
detail={"layout": {"x": 0, "y": 0, "w": 1, "h": 1, "minH": 2}},
233+
discover_widget_split=DashboardWidgetTypes.ERROR_EVENTS,
234+
)
235+
DashboardWidget.objects.create(
236+
dashboard=dashboard,
237+
order=1,
238+
title="transaction widget",
239+
display_type=DashboardWidgetDisplayTypes.LINE_CHART,
240+
widget_type=DashboardWidgetTypes.DISCOVER,
241+
interval="1d",
242+
detail={"layout": {"x": 0, "y": 0, "w": 1, "h": 1, "minH": 2}},
243+
discover_widget_split=DashboardWidgetTypes.TRANSACTION_LIKE,
244+
)
245+
DashboardWidget.objects.create(
246+
dashboard=dashboard,
247+
order=2,
248+
title="no split",
249+
display_type=DashboardWidgetDisplayTypes.LINE_CHART,
250+
widget_type=DashboardWidgetTypes.DISCOVER,
251+
interval="1d",
252+
detail={"layout": {"x": 0, "y": 0, "w": 1, "h": 1, "minH": 2}},
253+
)
254+
255+
with self.feature({"organizations:performance-discover-dataset-selector": True}):
256+
response = self.do_request(
257+
"get",
258+
self.url(dashboard.id),
259+
)
260+
assert response.status_code == 200, response.content
261+
assert response.data["widgets"][0]["widgetType"] == "error-events"
262+
assert response.data["widgets"][1]["widgetType"] == "transaction-like"
263+
assert response.data["widgets"][2]["widgetType"] == "discover"
264+
219265

220266
class OrganizationDashboardDetailsDeleteTest(OrganizationDashboardDetailsTestCase):
221267
def test_delete(self):

0 commit comments

Comments
 (0)