diff --git a/README.md b/README.md index ebf0dcd..f921104 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,7 @@ widget = dashboard.widgets.create( chart = dashboard.widgets.chart(widget.id) # chart.data, chart.chart_schema, paging fields chart = dashboard.widgets.chart(widget.id, page=2) everything = dashboard.widgets.charts() # every widget's first page in one call -dashboards.widget_types("acme") # chart types, their models, plan availability +dashboards.widget_types("acme") # chart types, their models, plan availability, config_schema dashboards.copy("acme", dashboard.id) # copies settings, filters and widgets ``` diff --git a/plane/models/v2/dashboards.py b/plane/models/v2/dashboards.py index 78be8d3..07492b3 100644 --- a/plane/models/v2/dashboards.py +++ b/plane/models/v2/dashboards.py @@ -153,7 +153,9 @@ class CopyDashboard(BaseModel): class WidgetType(BaseModel): """One row of `Dashboards.widget_types`. A type with `available=False` isn't on the - workspace's plan and answers 402 on create and on `chart`.""" + workspace's plan and answers 402 on create and on `chart`. `config_schema` is the JSON Schema + of the type's `config`; `None` when the server publishes none for the type, or is older and + doesn't send the key.""" model_config = ConfigDict(extra="allow") @@ -161,6 +163,7 @@ class WidgetType(BaseModel): name: str | None = None chart_models: list[str] | None = None available: bool | None = None + config_schema: dict[str, Any] | None = None class WidgetTypeList(BaseModel): diff --git a/tests/v2/test_dashboards_resource.py b/tests/v2/test_dashboards_resource.py index 675a291..a75656a 100644 --- a/tests/v2/test_dashboards_resource.py +++ b/tests/v2/test_dashboards_resource.py @@ -175,6 +175,17 @@ def test_widget_types_unwraps_the_envelope(dashboards: Dashboards) -> None: "name": "Number", "chart_models": ["BASIC"], "available": False, + "config_schema": None, + }, + { + "chart_type": "CYCLE_PROGRESS_BAR", + "name": "Cycle Progress Bar", + "chart_models": ["BASIC"], + "available": True, + "config_schema": { + "type": "object", + "properties": {"cycle_ids": {"type": "array", "items": {"type": "string"}}}, + }, }, ] }, @@ -185,8 +196,14 @@ def test_widget_types_unwraps_the_envelope(dashboards: Dashboards) -> None: assert [(row.chart_type, row.available) for row in types] == [ ("BAR_CHART", True), ("NUMBER", False), + ("CYCLE_PROGRESS_BAR", True), ] assert types[0].chart_models == ["BASIC", "STACKED", "GROUPED"] + # A key left out (an older server) and a null both read as None. + assert types[0].config_schema is None + assert types[1].config_schema is None + assert types[2].config_schema is not None + assert list(types[2].config_schema["properties"]) == ["cycle_ids"] # -- Widgets ------------------------------------------------------------------------