Repository: weaveworks/grafanalib

Issue:
Feature: Support Dashboardlist panel
## What you expected to happen?
We expect to be able to use Dashboardlist panel types with Grafanalib.

## What happened?
Not supported as of this writing.


Discussion:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 2dbfa63..8b6044f 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -10,6 +10,7 @@ Changelog
 * Added support for repetitions to Stat Panels (https://grafana.com/docs/grafana/latest/variables/repeat-panels-or-rows/)
 * Added textMode option to Stat Panels
 * Add Panel object for all panels to inherit from
+* Add Dashboard list panel (https://grafana.com/docs/grafana/latest/panels/visualizations/dashboard-list-panel/)
 
 
 Changes
diff --git a/grafanalib/core.py b/grafanalib/core.py
index 5909e5a..ee3922b 100644
--- a/grafanalib/core.py
+++ b/grafanalib/core.py
@@ -82,6 +82,7 @@ TEXT_TYPE = 'text'
 ALERTLIST_TYPE = 'alertlist'
 BARGAUGE_TYPE = 'bargauge'
 GAUGE_TYPE = 'gauge'
+DASHBOARDLIST_TYPE = 'dashlist'
 HEATMAP_TYPE = 'heatmap'
 STATUSMAP_TYPE = 'flant-statusmap-panel'
 SVG_TYPE = 'marcuscalidus-svg-panel'
@@ -2464,6 +2465,57 @@ class PieChart(Panel):
         )
 
 
+@attr.s
+class DashboardList(Panel):
+    """Generates Dashboard list panel json structure
+    Grafana doc on Dashboard list: https://grafana.com/docs/grafana/latest/panels/visualizations/dashboard-list-panel/
+    :param title: panel title
+    :param description: optional panel description
+    :param editable: defines if panel is editable via web interfaces
+    :param height: defines panel height
+    :param id: panel id
+    :param links: additional web links
+    :param span: defines the number of spans that will be used for panel
+    :param transparent: defines if the panel is transparent
+
+    :param showHeadings: The chosen list selection (Starred, Recently viewed, Search) is shown as a heading
+    :param showSearch: Display dashboards by search query or tags. Requires you to enter at least one value in Query or Tags
+    :param showRecent: Display recently viewed dashboards in alphabetical order
+    :param showStarred: Display starred dashboards in alphabetical order
+    :param maxItems: Sets the maximum number of items to list per section
+    :param searchQuery: Enter the query you want to search by
+    :param searchTags: List of tags you want to search by
+    """
+    showHeadings = attr.ib(default=True)
+    showSearch = attr.ib(default=False)
+    showRecent = attr.ib(default=False)
+    showStarred = attr.ib(default=True)
+    maxItems = attr.ib(default=10, validator=instance_of(int))
+    searchQuery = attr.ib(default='', validator=instance_of(str))
+    searchTags = attr.ib(default=attr.Factory(list), validator=instance_of(list))
+
+    def to_json_data(self):
+        return self.panel_json(
+            {
+                'height': self.height,
+                'fieldConfig': {
+                    'defaults': {
+                        'custom': {},
+                    },
+                    'overrides': []
+                },
+                'headings': self.showHeadings,
+                'search': self.showSearch,
+                'recent': self.showRecent,
+                'starred': self.showStarred,
+                'limit': self.maxItems,
+                'query': self.searchQuery,
+                'tags': self.searchTags,
+                'type': DASHBOARDLIST_TYPE,
+            }
+        )
+
+
 @attr.s
 class Threshold(object):
     """Threshold for a gauge


Test patch:
diff --git a/grafanalib/tests/test_core.py b/grafanalib/tests/test_core.py
index 2d8f571..d85e3da 100644
--- a/grafanalib/tests/test_core.py
+++ b/grafanalib/tests/test_core.py
@@ -121,3 +121,13 @@ def test_single_stat():
     assert data['targets'] == targets
     assert data['datasource'] == data_source
     assert data['title'] == title
+
+
+def test_dashboard_list():
+    title = 'dummy title'
+    dashboard_list = G.DashboardList(title=title)
+    data = dashboard_list.to_json_data()
+    assert data['targets'] == []
+    assert data['datasource'] is None
+    assert data['title'] == title
+    assert data['starred'] is True