diff --git a/README.md b/README.md index 127fa1bb..0a079f14 100644 --- a/README.md +++ b/README.md @@ -330,8 +330,8 @@ its settings only: `widgets.chart` answers one widget's data (paged with `page`, `widgets.charts` answers every widget's first page in one call, each entry carrying its own `status` and either `chart` or `error`. A chart's shape depends on its `chart_type`, so `WidgetChart` names only the shared fields. `dashboards.widgetTypes` lists the chart types -a dashboard can hold, the `chart_model` values each accepts and whether the plan includes -it. +a dashboard can hold, the `chart_model` values each accepts, whether the plan includes +it, and `config_schema`, the JSON Schema of the type's `config` when the server publishes one. ```ts const dashboards = client.v2.workspaces.dashboards; diff --git a/scripts/__fixtures__/types-bundle-exports.snapshot.txt b/scripts/__fixtures__/types-bundle-exports.snapshot.txt index ebfcf7d8..07153af2 100644 --- a/scripts/__fixtures__/types-bundle-exports.snapshot.txt +++ b/scripts/__fixtures__/types-bundle-exports.snapshot.txt @@ -864,7 +864,7 @@ root WidgetField WidgetField 031f7fd7faa535e1 root WidgetLastUsedFilter WidgetLastUsedFilter 2a17869a66311d52 root WidgetOrderBy WidgetOrderBy 84e9b98d55c55510 root WidgetShapeParams WidgetShapeParams bde434605ccec0a2 -root WidgetType WidgetType be7711d06b85c633 +root WidgetType WidgetType d28766e7ef8889ec root WidgetYAxisMetric WidgetYAxisMetric 5838f1f9900b8726 root WikiPageExpand WikiPageExpand b41bd04e55582fc9 root WikiPageField WikiPageField bd8a2930ea927502 @@ -1809,7 +1809,7 @@ v2models WidgetChartSchemaEntry WidgetChartSchemaEntry 1d893d2793a353a5 v2models WidgetChartType WidgetChartType 986ca7ab4e136daf v2models WidgetDateGrouping WidgetDateGrouping b01881c8ca4e6793 v2models WidgetLastUsedFilter WidgetLastUsedFilter 2a17869a66311d52 -v2models WidgetType WidgetType be7711d06b85c633 +v2models WidgetType WidgetType d28766e7ef8889ec v2models WidgetYAxisMetric WidgetYAxisMetric 5838f1f9900b8726 v2models Workflow Workflow af044ee329fcfaea v2models WorkflowState WorkflowState dcdeb244246c7a20 diff --git a/src/models/v2/Widget.ts b/src/models/v2/Widget.ts index 915b093d..fcb030ed 100644 --- a/src/models/v2/Widget.ts +++ b/src/models/v2/Widget.ts @@ -149,6 +149,11 @@ export interface WidgetType { chart_models: WidgetChartModel[]; /** `false` when the plan doesn't include it: writing or charting a widget of this type answers 402. */ available: boolean; + /** + * JSON Schema of the type's `config`. `null` when the server publishes none for the type; + * absent on an older server that doesn't send the key. + */ + config_schema?: Record | null; } /** One entity in a chart's `schema` map — at least `id` and `name`, plus per-entity extras (`color`, `group`, …). */ diff --git a/tests/unit/v2/dashboards.test.ts b/tests/unit/v2/dashboards.test.ts index f89cb793..d2c23453 100644 --- a/tests/unit/v2/dashboards.test.ts +++ b/tests/unit/v2/dashboards.test.ts @@ -86,13 +86,25 @@ describe("Dashboards (v2)", () => { available: true, }, { chart_type: "WORK_ITEMS_TABLE", name: "Work Items Table", chart_models: ["BASIC"], available: false }, + { + 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" } } } }, + }, ], }); const types = await makeDashboards().widgetTypes(SLUG); - expect(types.map((type) => type.chart_type)).toEqual(["BAR_CHART", "WORK_ITEMS_TABLE"]); + expect(types.map((type) => type.chart_type)).toEqual(["BAR_CHART", "WORK_ITEMS_TABLE", "CYCLE_PROGRESS_BAR"]); expect(types[1].available).toBe(false); + expect(types[0].config_schema).toBeUndefined(); + expect(types[2].config_schema).toEqual({ + type: "object", + properties: { cycle_ids: { type: "array", items: { type: "string" } } }, + }); }); it("answers navigable rows that reach their widgets, from a fetched workspace too", async () => {