diff --git a/src/databricks/labs/lsql/dashboards.py b/src/databricks/labs/lsql/dashboards.py index 8d2d059a..0dc5aafa 100644 --- a/src/databricks/labs/lsql/dashboards.py +++ b/src/databricks/labs/lsql/dashboards.py @@ -1,3 +1,4 @@ +import abc import argparse import dataclasses import json @@ -81,16 +82,39 @@ def replace_from_arguments(self, arguments: list[str]) -> "WidgetMetadata": ) -class CounterTile: - pass +class Tile: + """A dashboard tile.""" + def __init__(self, fields: list[Field]) -> None: + self._fields = fields -class TableTile: - pass + @property + def size(self) -> tuple[int, int]: + """The width and height.""" + return 1, 3 + @property + @abc.abstractmethod + def spec(self) -> WidgetSpec: + """The widget spec""" -class MarkdownTile: - pass + +class CounterTile(Tile): + + def spec(self) -> WidgetSpec: + # Counters are expected to have one field + counter_encodings = CounterFieldEncoding(field_name=self._fields[0].name, display_name=self._fields[0].name) + spec = CounterSpec(CounterEncodingMap(value=counter_encodings)) + return spec + + +class TableTile(Tile): + + def spec(self) -> WidgetSpec: + field_encodings = [RenderFieldEncoding(field_name=field.name) for field in self._fields] + table_encodings = TableEncodingMap(field_encodings) + spec = TableV2Spec(encodings=table_encodings) + return spec class Dashboards: