Skip to content

Commit

Permalink
Use tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
JCZuurmond committed Jun 13, 2024
1 parent f2aa048 commit 8e8e886
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def spec(self) -> WidgetSpec:


class CounterTile(Tile):

@property
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)
Expand All @@ -113,7 +113,7 @@ def spec(self) -> WidgetSpec:


class TableTile(Tile):

@property
def spec(self) -> WidgetSpec:
field_encodings = [RenderFieldEncoding(field_name=field.name) for field in self._fields]
table_encodings = TableEncodingMap(field_encodings)
Expand Down Expand Up @@ -269,15 +269,12 @@ def _get_widget(self, dataset: Dataset) -> Widget:
query = Query(dataset_name=dataset.name, fields=fields, disaggregated=True)
# As far as testing went, a NamedQuery should always have "main_query" as name
named_query = NamedQuery(name="main_query", query=query)
spec: WidgetSpec
tile: Tile
if len(fields) == 1: # Counters are expected to have one field
counter_encodings = CounterFieldEncoding(field_name=fields[0].name, display_name=fields[0].name)
spec = CounterSpec(CounterEncodingMap(value=counter_encodings))
tile = CounterTile(fields)
else:
field_encodings = [RenderFieldEncoding(field_name=field.name) for field in fields]
table_encodings = TableEncodingMap(field_encodings)
spec = TableV2Spec(encodings=table_encodings)
widget = Widget(name=dataset.name, queries=[named_query], spec=spec)
tile = TableTile(fields)
widget = Widget(name=dataset.name, queries=[named_query], spec=tile.spec)
return widget

@staticmethod
Expand Down

0 comments on commit 8e8e886

Please sign in to comment.