Browse Source

feat(dashboar-widget-description) Added description field to Widget model (#49992)

Linked issue:  https://github.com/getsentry/sentry/issues/49869

Added a new description field to the DashboardWidget model.

Co-authored-by: Abdullah Khan <abdullahkhan@PG9Y57YDXQ.local>
Abdkhan14 1 year ago
parent
commit
5905bcea80

+ 1 - 1
migrations_lockfile.txt

@@ -6,5 +6,5 @@ To resolve this, rebase against latest master and regenerate your migration. Thi
 will then be regenerated, and you should be able to merge without conflicts.
 
 nodestore: 0002_nodestore_no_dictfield
-sentry: 0470_denormalize_user_is_active
+sentry: 0471_dashboard_widget_description
 social_auth: 0001_initial

+ 1 - 0
src/sentry/api/serializers/models/dashboard.py

@@ -36,6 +36,7 @@ class DashboardWidgetSerializer(Serializer):
         return {
             "id": str(obj.id),
             "title": obj.title,
+            "description": obj.description,
             "displayType": DashboardWidgetDisplayTypes.get_type_name(obj.display_type),
             # Default value until a backfill can be done.
             "interval": str(obj.interval or "5m"),

+ 3 - 0
src/sentry/api/serializers/rest_framework/dashboard.py

@@ -234,6 +234,7 @@ class DashboardWidgetSerializer(CamelSnakeSerializer):
     # Is a string because output serializers also make it a string.
     id = serializers.CharField(required=False)
     title = serializers.CharField(required=False, max_length=255)
+    description = serializers.CharField(required=False, max_length=255, allow_null=True)
     display_type = serializers.ChoiceField(
         choices=DashboardWidgetDisplayTypes.as_text_choices(), required=False
     )
@@ -433,6 +434,7 @@ class DashboardDetailsSerializer(CamelSnakeSerializer):
             dashboard=dashboard,
             display_type=widget_data["display_type"],
             title=widget_data["title"],
+            description=widget_data.get("description", None),
             interval=widget_data.get("interval", "5m"),
             widget_type=widget_data.get("widget_type", DashboardWidgetTypes.DISCOVER),
             order=order,
@@ -459,6 +461,7 @@ class DashboardDetailsSerializer(CamelSnakeSerializer):
     def update_widget(self, widget, data, order):
         prev_layout = widget.detail.get("layout") if widget.detail else None
         widget.title = data.get("title", widget.title)
+        widget.description = data.get("description", widget.description)
         widget.display_type = data.get("display_type", widget.display_type)
         widget.interval = data.get("interval", widget.interval)
         widget.widget_type = data.get("widget_type", widget.widget_type)

+ 31 - 0
src/sentry/migrations/0471_dashboard_widget_description.py

@@ -0,0 +1,31 @@
+# Generated by Django 2.2.28 on 2023-05-31 13:55
+
+from django.db import migrations, models
+
+from sentry.new_migrations.migrations import CheckedMigration
+
+
+class Migration(CheckedMigration):
+    # This flag is used to mark that a migration shouldn't be automatically run in production. For
+    # the most part, this should only be used for operations where it's safe to run the migration
+    # after your code has deployed. So this should not be used for most operations that alter the
+    # schema of a table.
+    # Here are some things that make sense to mark as dangerous:
+    # - Large data migrations. Typically we want these to be run manually by ops so that they can
+    #   be monitored and not block the deploy for a long period of time while they run.
+    # - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
+    #   have ops run this and not block the deploy. Note that while adding an index is a schema
+    #   change, it's completely safe to run the operation after the code has deployed.
+    is_dangerous = False
+
+    dependencies = [
+        ("sentry", "0470_denormalize_user_is_active"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="dashboardwidget",
+            name="description",
+            field=models.CharField(max_length=255, null=True),
+        ),
+    ]

+ 1 - 0
src/sentry/models/dashboard_widget.py

@@ -117,6 +117,7 @@ class DashboardWidget(Model):
     dashboard = FlexibleForeignKey("sentry.Dashboard")
     order = BoundedPositiveIntegerField()
     title = models.CharField(max_length=255)
+    description = models.CharField(max_length=255, null=True)
     interval = models.CharField(max_length=10, null=True)
     display_type = BoundedPositiveIntegerField(choices=DashboardWidgetDisplayTypes.as_choices())
     date_added = models.DateTimeField(default=timezone.now)

+ 1 - 0
tests/sentry/api/endpoints/test_organization_dashboard_widget_details.py

@@ -34,6 +34,7 @@ class OrganizationDashboardWidgetDetailsTestCase(OrganizationDashboardWidgetTest
                     "orderby": "count()",
                 },
             ],
+            "description": "Valid widget description",
         }
         response = self.do_request(
             "post",