Skip to content

Fix Toplist widget's stacked display style - remove legend as required field #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-02 14:33:54.593908",
"spec_repo_commit": "3b4747f4"
"regenerated": "2024-10-02 16:22:32.655426",
"spec_repo_commit": "3f12bebc"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-02 14:33:54.609830",
"spec_repo_commit": "3b4747f4"
"regenerated": "2024-10-02 16:22:32.670241",
"spec_repo_commit": "3f12bebc"
}
}
}
1 change: 0 additions & 1 deletion .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18188,7 +18188,6 @@ components:
$ref: '#/components/schemas/ToplistWidgetStackedType'
required:
- type
- legend
type: object
ToplistWidgetStackedType:
default: stacked
Expand Down
3 changes: 1 addition & 2 deletions examples/v1_dashboards_CreateDashboard_1213075383.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ async fn main() {
ToplistWidgetDisplay::ToplistWidgetStacked(
Box::new(
ToplistWidgetStacked::new(
ToplistWidgetLegend::INLINE,
ToplistWidgetStackedType::STACKED,
),
).legend(ToplistWidgetLegend::INLINE),
),
),
)
Expand Down
115 changes: 115 additions & 0 deletions examples/v1_dashboards_CreateDashboard_1413226400.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Create a new dashboard with a toplist widget with stacked type and no legend
// specified
use datadog_api_client::datadog;
use datadog_api_client::datadogV1::api_dashboards::DashboardsAPI;
use datadog_api_client::datadogV1::model::Dashboard;
use datadog_api_client::datadogV1::model::DashboardLayoutType;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricAggregation;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricDataSource;
use datadog_api_client::datadogV1::model::FormulaAndFunctionMetricQueryDefinition;
use datadog_api_client::datadogV1::model::FormulaAndFunctionQueryDefinition;
use datadog_api_client::datadogV1::model::FormulaAndFunctionResponseFormat;
use datadog_api_client::datadogV1::model::GroupType;
use datadog_api_client::datadogV1::model::ToplistWidgetDefinition;
use datadog_api_client::datadogV1::model::ToplistWidgetDefinitionType;
use datadog_api_client::datadogV1::model::ToplistWidgetDisplay;
use datadog_api_client::datadogV1::model::ToplistWidgetRequest;
use datadog_api_client::datadogV1::model::ToplistWidgetScaling;
use datadog_api_client::datadogV1::model::ToplistWidgetStacked;
use datadog_api_client::datadogV1::model::ToplistWidgetStackedType;
use datadog_api_client::datadogV1::model::ToplistWidgetStyle;
use datadog_api_client::datadogV1::model::Widget;
use datadog_api_client::datadogV1::model::WidgetDefinition;
use datadog_api_client::datadogV1::model::WidgetFormula;
use datadog_api_client::datadogV1::model::WidgetGroupSort;
use datadog_api_client::datadogV1::model::WidgetLayout;
use datadog_api_client::datadogV1::model::WidgetLegacyLiveSpan;
use datadog_api_client::datadogV1::model::WidgetSort;
use datadog_api_client::datadogV1::model::WidgetSortBy;
use datadog_api_client::datadogV1::model::WidgetSortOrderBy;
use datadog_api_client::datadogV1::model::WidgetTextAlign;
use datadog_api_client::datadogV1::model::WidgetTime;

#[tokio::main]
async fn main() {
let body =
Dashboard::new(
DashboardLayoutType::FREE,
"Example-Dashboard".to_string(),
vec![
Widget::new(
WidgetDefinition::ToplistWidgetDefinition(
Box::new(
ToplistWidgetDefinition::new(
vec![
ToplistWidgetRequest::new()
.formulas(vec![WidgetFormula::new("query1".to_string())])
.queries(
vec![
FormulaAndFunctionQueryDefinition
::FormulaAndFunctionMetricQueryDefinition(
Box::new(
FormulaAndFunctionMetricQueryDefinition::new(
FormulaAndFunctionMetricDataSource::METRICS,
"query1".to_string(),
"avg:system.cpu.user{*} by {service}".to_string(),
).aggregator(FormulaAndFunctionMetricAggregation::AVG),
),
)
],
)
.response_format(FormulaAndFunctionResponseFormat::SCALAR)
.sort(
WidgetSortBy::new()
.count(10)
.order_by(
vec![
WidgetSortOrderBy::WidgetGroupSort(
Box::new(
WidgetGroupSort::new(
"service".to_string(),
WidgetSort::ASCENDING,
GroupType::GROUP,
),
),
)
],
),
)
],
ToplistWidgetDefinitionType::TOPLIST,
)
.style(
ToplistWidgetStyle::new()
.display(
ToplistWidgetDisplay::ToplistWidgetStacked(
Box::new(
ToplistWidgetStacked::new(ToplistWidgetStackedType::STACKED),
),
),
)
.palette("dog_classic".to_string())
.scaling(ToplistWidgetScaling::RELATIVE),
)
.time(WidgetTime::WidgetLegacyLiveSpan(Box::new(WidgetLegacyLiveSpan::new())))
.title("".to_string())
.title_align(WidgetTextAlign::LEFT)
.title_size("16".to_string()),
),
),
).layout(WidgetLayout::new(15, 47, 0, 0))
],
)
.description(Some("".to_string()))
.is_read_only(false)
.notify_list(Some(vec![]))
.template_variables(Some(vec![]));
let configuration = datadog::Configuration::new();
let api = DashboardsAPI::with_config(configuration);
let resp = api.create_dashboard(body).await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
3 changes: 1 addition & 2 deletions examples/v1_dashboards_CreateDashboard_2563642929.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ async fn main() {
ToplistWidgetDisplay::ToplistWidgetStacked(
Box::new(
ToplistWidgetStacked::new(
ToplistWidgetLegend::INLINE,
ToplistWidgetStackedType::STACKED,
),
).legend(ToplistWidgetLegend::INLINE),
),
),
)
Expand Down
18 changes: 11 additions & 7 deletions src/datadogV1/model/model_toplist_widget_stacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::fmt::{self, Formatter};
pub struct ToplistWidgetStacked {
/// Top list widget stacked legend behavior.
#[serde(rename = "legend")]
pub legend: crate::datadogV1::model::ToplistWidgetLegend,
pub legend: Option<crate::datadogV1::model::ToplistWidgetLegend>,
/// Top list widget stacked display type.
#[serde(rename = "type")]
pub type_: crate::datadogV1::model::ToplistWidgetStackedType,
Expand All @@ -25,18 +25,20 @@ pub struct ToplistWidgetStacked {
}

impl ToplistWidgetStacked {
pub fn new(
legend: crate::datadogV1::model::ToplistWidgetLegend,
type_: crate::datadogV1::model::ToplistWidgetStackedType,
) -> ToplistWidgetStacked {
pub fn new(type_: crate::datadogV1::model::ToplistWidgetStackedType) -> ToplistWidgetStacked {
ToplistWidgetStacked {
legend,
legend: None,
type_,
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}

pub fn legend(mut self, value: crate::datadogV1::model::ToplistWidgetLegend) -> Self {
self.legend = Some(value);
self
}

pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
Expand Down Expand Up @@ -74,6 +76,9 @@ impl<'de> Deserialize<'de> for ToplistWidgetStacked {
while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
"legend" => {
if v.is_null() {
continue;
}
legend = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _legend) = legend {
match _legend {
Expand Down Expand Up @@ -102,7 +107,6 @@ impl<'de> Deserialize<'de> for ToplistWidgetStacked {
}
}
}
let legend = legend.ok_or_else(|| M::Error::missing_field("legend"))?;
let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;

let content = ToplistWidgetStacked {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-09-30T17:24:52.299Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"http_interactions": [
{
"request": {
"body": {
"string": "{\"description\":\"\",\"is_read_only\":false,\"layout_type\":\"free\",\"notify_list\":[],\"template_variables\":[],\"title\":\"Test-Create_a_new_dashboard_with_a_toplist_widget_with_stacked_type_and_no_legend_specified-1727717092\",\"widgets\":[{\"definition\":{\"requests\":[{\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{*} by {service}\"}],\"response_format\":\"scalar\",\"sort\":{\"count\":10,\"order_by\":[{\"name\":\"service\",\"order\":\"asc\",\"type\":\"group\"}]}}],\"style\":{\"display\":{\"type\":\"stacked\"},\"palette\":\"dog_classic\",\"scaling\":\"relative\"},\"time\":{},\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"toplist\"},\"layout\":{\"height\":15,\"width\":47,\"x\":0,\"y\":0}}]}",
"encoding": null
},
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json"
]
},
"method": "post",
"uri": "https://api.datadoghq.com/api/v1/dashboard"
},
"response": {
"body": {
"string": "{\"id\":\"2az-xeg-xar\",\"title\":\"Test-Create_a_new_dashboard_with_a_toplist_widget_with_stacked_type_and_no_legend_specified-1727717092\",\"description\":\"\",\"author_handle\":\"frog@datadoghq.com\",\"author_name\":null,\"layout_type\":\"free\",\"url\":\"/dashboard/2az-xeg-xar/test-createanewdashboardwithatoplistwidgetwithstackedtypeandnolegendspecified-17\",\"is_read_only\":false,\"template_variables\":[],\"widgets\":[{\"definition\":{\"requests\":[{\"formulas\":[{\"formula\":\"query1\"}],\"queries\":[{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:system.cpu.user{*} by {service}\"}],\"response_format\":\"scalar\",\"sort\":{\"count\":10,\"order_by\":[{\"name\":\"service\",\"order\":\"asc\",\"type\":\"group\"}]}}],\"style\":{\"display\":{\"type\":\"stacked\"},\"palette\":\"dog_classic\",\"scaling\":\"relative\"},\"time\":{},\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"toplist\"},\"layout\":{\"height\":15,\"width\":47,\"x\":0,\"y\":0},\"id\":688132644515996}],\"notify_list\":[],\"created_at\":\"2024-09-30T17:24:52.542207+00:00\",\"modified_at\":\"2024-09-30T17:24:52.542207+00:00\",\"experience_type\":\"default\",\"restricted_roles\":[]}\n",
"encoding": null
},
"headers": {
"Content-Type": [
"application/json"
]
},
"status": {
"code": 200,
"message": "OK"
}
},
"recorded_at": "Mon, 30 Sep 2024 17:24:52 GMT"
},
{
"request": {
"body": "",
"headers": {
"Accept": [
"application/json"
]
},
"method": "delete",
"uri": "https://api.datadoghq.com/api/v1/dashboard/2az-xeg-xar"
},
"response": {
"body": {
"string": "{\"deleted_dashboard_id\":\"2az-xeg-xar\"}\n",
"encoding": null
},
"headers": {
"Content-Type": [
"application/json"
]
},
"status": {
"code": 200,
"message": "OK"
}
},
"recorded_at": "Mon, 30 Sep 2024 17:24:52 GMT"
}
],
"recorded_with": "VCR 6.0.0"
}
13 changes: 13 additions & 0 deletions tests/scenarios/features/v1/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ Feature: Dashboards
And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "group"
And the response "widgets[0].definition.requests[0].sort.order_by[0].name" is equal to "service"

@skip-typescript @team:DataDog/dashboards-backend
Scenario: Create a new dashboard with a toplist widget with stacked type and no legend specified
Given new "CreateDashboard" request
And body with value {"title":"{{ unique }}","description":"","widgets":[{"layout":{"x":0,"y":0,"width":47,"height":15},"definition":{"title":"","title_size":"16","title_align":"left","time":{},"style":{"display": {"type": "stacked"},"scaling": "relative","palette": "dog_classic"},"type":"toplist","requests":[{"queries":[{"data_source":"metrics","name":"query1","query":"avg:system.cpu.user{*} by {service}","aggregator":"avg"}],"formulas":[{"formula":"query1"}],"sort":{"count":10,"order_by":[{"type":"group","name":"service","order":"asc"}]},"response_format":"scalar"}]}}],"template_variables":[],"layout_type":"free","is_read_only":false,"notify_list":[]}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.type" is equal to "toplist"
And the response "widgets[0].definition.requests[0].sort.order_by[0].order" is equal to "asc"
And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "group"
And the response "widgets[0].definition.requests[0].sort.order_by[0].name" is equal to "service"
And the response "widgets[0].definition.style.display.type" is equal to "stacked"
And the response "widgets[0].definition.style.display" does not have field "legend"

@team:DataDog/dashboards-backend
Scenario: Create a new dashboard with alert_graph widget
Given there is a valid "monitor" in the system
Expand Down
Loading