Skip to content

feat(dashboards): granular widget editing + schema discovery + saved-widgets rename#584

Draft
platinummonkey wants to merge 5 commits into
mainfrom
feat/dashboard-widgets-improvements
Draft

feat(dashboards): granular widget editing + schema discovery + saved-widgets rename#584
platinummonkey wants to merge 5 commits into
mainfrom
feat/dashboard-widgets-improvements

Conversation

@platinummonkey

Copy link
Copy Markdown
Collaborator

Summary

Adds pup dashboards widgets <list|get|add|update|remove|types|schema> for editing individual widgets within a dashboard without round-tripping the entire dashboard JSON. Also renames the unrelated top-level saved/reporting widgets command from pup widgets to pup saved-widgets to free the natural dashboards widgets path, and enriches both widgets types and widgets schema with descriptions and full JSON Schemas sourced from the Datadog OpenAPI spec.

Changes

  • src/commands/dashboards.rs — 7 new widget commands (widget_list, widget_get, widget_add, widget_update, widget_remove, widget_types, widget_schema), widget_json_schema (full JSON Schema for all 34 widget types from OpenAPI spec), WIDGET_TYPES as &[(&str, &str)] tuples with descriptions, widget_template (ready-to-edit skeletons), read_widget_input, validate_widget, locate_widget_index helpers, 22 co-located unit tests
  • src/main.rsDashboardWidgetActions enum with List/Get/Add/Update/Remove/Types/Schema subcommands; Commands::SavedWidgets (renamed from Commands::Widgets, repositioned alphabetically after Runbooks); routing wired to new dashboard widget functions
  • src/test_commands.rs — 13 new clap-parsing integration tests covering all dashboards widgets subcommands, mutual-exclusion of --widget-id/--index, read-only classification of list/get/types/schema, and renamed saved-widgets command

Key design decisions

  • fetch → mutate → PUT flow: The Datadog Dashboard API has no per-widget PATCH endpoint. The SDK round-trips unknown fields via additional_properties so untouched widgets are preserved.
  • WidgetDefinition::UnparsedObject validation gate: A successful serde_json::from_slice::<Widget> does not mean valid — the untagged enum silently falls through to UnparsedObject for unknown types. validate_widget rejects these before any PUT.
  • Widget selector: --widget-id (API-assigned integer id) or --index (0-based position). Exactly one required via clap conflicts_with + required_unless_present.
  • pup saved-widgets rename: Frees pup dashboards widgets for embedded widgets. No backward-compat alias (the two concepts are unrelated).
  • JSON Schema sourced from OpenAPI spec: widget_json_schema covers all 34 types with field types, enum values, required arrays, and descriptions from spec/v1/dashboard.yaml.

Testing

  • cargo test passes (22 new dashboards unit tests + 13 new integration tests; 5 pre-existing failures in unrelated modules are unchanged)
  • cargo clippy -- -D warnings clean
  • cargo fmt --check clean

🤖 Generated with Claude Code

platinummonkey and others added 4 commits June 15, 2026 16:49
…scovery

Adds `pup dashboards widgets <list|get|add|update|remove|types|schema>` for
editing individual widgets within a dashboard, replacing the need to
round-trip the entire dashboard JSON.

Widget editing uses a safe fetch → mutate → PUT flow (the Datadog Dashboard
API has no per-widget PATCH endpoint). The SDK losslessly round-trips
unknown fields via `additional_properties`, so untouched widgets are
preserved. Widget input is validated by detecting `WidgetDefinition::UnparsedObject`
— the only validation gate available without importing private SDK internals.

Widget schema discovery emits either a ready-to-edit skeleton JSON (for 8
high-traffic types: timeseries, query_value, query_table, toplist, note,
free_text, heatmap, slo) or a minimal `{"definition":{"type":"<type>"}}`
fallback for the other ~26 known types.

The existing `pup dashboards widgets` saved/reporting widgets (V2 API) are
promoted to a new top-level `pup widgets` command, freeing the natural
`dashboards widgets` path for embedded-widget editing.

Files changed:
- src/commands/dashboards.rs: helpers, 7 widget commands, static type
  registry + templates, 22 new co-located tests
- src/main.rs: DashboardWidgetActions enum, Commands::Widgets top-level
  variant, routing changes
- src/test_commands.rs: 13 new integration tests covering clap parsing,
  mutual-exclusion, and read-only classification

Environment: Datadog workspace

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…dgets`

Rename the Commands::Widgets variant to Commands::SavedWidgets with
#[command(name = "saved-widgets")] so the top-level saved/reporting
widgets command is invoked as `pup saved-widgets` instead of
`pup widgets`. Also repositions the variant alphabetically (after
Runbooks, before Scorecards). Updates routing arm and tests accordingly.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`pup dashboards widgets types` now returns objects with `type` and
`description` fields sourced from the Datadog OpenAPI spec (v1).
`pup dashboards widgets schema <type>` now returns a wrapper object
with `type`, `description`, and `template` fields so callers see
what the widget does alongside the ready-to-edit JSON skeleton.

- WIDGET_TYPES changed from &[&str] to &[(&str, &str)] (type, description)
- widget_types() emits [{type, description}] objects instead of plain strings
- widget_schema() wraps the template in {type, description, template}

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`pup dashboards widgets schema <type>` now outputs a `schema` field
alongside the existing `template`. The schema is a JSON Schema document
derived from the Datadog OpenAPI spec (v1/dashboard.yaml) covering all
34 widget types. Each type documents its required fields, optional
properties, types, enum values, and descriptions for every field
including nested objects (requests, style, view, layout, etc.).

Output shape: {type, description, schema: {type, required, properties:
  {id, layout: {x,y,width,height}, definition: <type-specific schema>}},
  template: <minimal ready-to-edit JSON>}

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@platinummonkey platinummonkey requested a review from a team as a code owner June 15, 2026 21:02
@datadog-official

datadog-official Bot commented Jun 15, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 1 Pipeline job failed

CI | Check, Test &amp; Coverage   View in Datadog   GitHub Actions

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 44cb0e7 | Docs | Datadog PR Page | Give us feedback!

@platinummonkey platinummonkey marked this pull request as draft June 15, 2026 21:03
Run cargo fmt to fix formatting in dashboards.rs and test_commands.rs.

Environment: Datadog workspace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant