From 163d3dfd877d70408db3d09fc5cd78f22d3c4d8d Mon Sep 17 00:00:00 2001 From: "ci.datadog-api-spec" Date: Mon, 16 Sep 2024 14:08:40 +0000 Subject: [PATCH] Regenerate client from commit 966987f5 of spec repo --- .apigentools-info | 8 +- .generator/schemas/v1/openapi.yaml | 175 +++++++++++++++ ...v1_dashboards_CreateDashboard_794302680.rs | 200 ++++++++++++++++++ src/datadogV1/model/mod.rs | 18 ++ .../model/model_table_widget_request.rs | 23 ++ .../model_table_widget_text_format_match.rs | 114 ++++++++++ ...del_table_widget_text_format_match_type.rs | 63 ++++++ .../model_table_widget_text_format_palette.rs | 78 +++++++ .../model_table_widget_text_format_replace.rs | 45 ++++ ...el_table_widget_text_format_replace_all.rs | 115 ++++++++++ ...ble_widget_text_format_replace_all_type.rs | 48 +++++ ...le_widget_text_format_replace_substring.rs | 126 +++++++++++ ...dget_text_format_replace_substring_type.rs | 48 +++++ .../model_table_widget_text_format_rule.rs | 182 ++++++++++++++++ ...ry-table-widget-and-text-formatting.frozen | 1 + ...uery-table-widget-and-text-formatting.json | 67 ++++++ .../scenarios/features/v1/dashboards.feature | 16 ++ .../query_table_widget_text_formatting.json | 147 +++++++++++++ 18 files changed, 1470 insertions(+), 4 deletions(-) create mode 100644 examples/v1_dashboards_CreateDashboard_794302680.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_match.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_match_type.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_palette.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_replace.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_replace_all.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_replace_all_type.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_replace_substring.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_replace_substring_type.rs create mode 100644 src/datadogV1/model/model_table_widget_text_format_rule.rs create mode 100644 tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.frozen create mode 100644 tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.json create mode 100644 tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json diff --git a/.apigentools-info b/.apigentools-info index 8d0dd380e..f7a9889aa 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-13 20:35:27.418968", - "spec_repo_commit": "6093038f" + "regenerated": "2024-09-16 14:02:52.161932", + "spec_repo_commit": "966987f5" }, "v2": { "apigentools_version": "1.6.6", - "regenerated": "2024-09-13 20:35:27.437228", - "spec_repo_commit": "6093038f" + "regenerated": "2024-09-16 14:02:52.179359", + "spec_repo_commit": "966987f5" } } } \ No newline at end of file diff --git a/.generator/schemas/v1/openapi.yaml b/.generator/schemas/v1/openapi.yaml index 2a6fbf20f..e45da8ea4 100644 --- a/.generator/schemas/v1/openapi.yaml +++ b/.generator/schemas/v1/openapi.yaml @@ -16752,6 +16752,181 @@ components: $ref: '#/components/schemas/LogQueryDefinition' sort: $ref: '#/components/schemas/WidgetSortBy' + text_formats: + description: List of text formats for columns produced by tags. + items: + $ref: '#/components/schemas/TableWidgetTextFormat' + type: array + type: object + TableWidgetTextFormat: + description: Text format rules for a tag-based column within a table widget. + example: + - match: + type: is + value: fruit + replace: + type: all + with: vegetable + - match: + type: is + value: cake + palette: white_on_green + items: + $ref: '#/components/schemas/TableWidgetTextFormatRule' + minItems: 1 + type: array + TableWidgetTextFormatMatch: + description: Match rule for the table widget text format. + example: + type: is + value: fruit + properties: + type: + $ref: '#/components/schemas/TableWidgetTextFormatMatchType' + value: + description: Table Widget Match String. + example: Match Value + type: string + required: + - type + - value + type: object + TableWidgetTextFormatMatchType: + description: Match or compare option. + enum: + - is + - is_not + - contains + - does_not_contain + - starts_with + - ends_with + example: is + type: string + x-enum-varnames: + - IS + - IS_NOT + - CONTAINS + - DOES_NOT_CONTAIN + - STARTS_WITH + - ENDS_WITH + TableWidgetTextFormatPalette: + default: white_on_green + description: Color-on-color palette to highlight replaced text. + enum: + - white_on_red + - white_on_yellow + - white_on_green + - black_on_light_red + - black_on_light_yellow + - black_on_light_green + - red_on_white + - yellow_on_white + - green_on_white + - custom_bg + - custom_text + type: string + x-enum-varnames: + - WHITE_ON_RED + - WHITE_ON_YELLOW + - WHITE_ON_GREEN + - BLACK_ON_LIGHT_RED + - BLACK_ON_LIGHT_YELLOW + - BLACK_ON_LIGHT_GREEN + - RED_ON_WHITE + - YELLOW_ON_WHITE + - GREEN_ON_WHITE + - CUSTOM_BG + - CUSTOM_TEXT + TableWidgetTextFormatReplace: + description: Replace rule for the table widget text format. + example: + type: all + with: vegetable + oneOf: + - $ref: '#/components/schemas/TableWidgetTextFormatReplaceAll' + - $ref: '#/components/schemas/TableWidgetTextFormatReplaceSubstring' + TableWidgetTextFormatReplaceAll: + description: Match All definition. + example: + type: all + with: vegetable + properties: + type: + $ref: '#/components/schemas/TableWidgetTextFormatReplaceAllType' + with: + description: Replace All type. + example: all + type: string + required: + - type + - with + type: object + TableWidgetTextFormatReplaceAllType: + description: Table widget text format replace all type. + enum: + - all + example: all + type: string + x-enum-varnames: + - ALL + TableWidgetTextFormatReplaceSubstring: + description: Match Sub-string definition. + example: + substring: fruit + type: substring + with: vegetable + properties: + substring: + description: Text that will be replaced. + example: string to replace + type: string + type: + $ref: '#/components/schemas/TableWidgetTextFormatReplaceSubstringType' + with: + description: Text that will replace original sub-string. + example: replacement + type: string + required: + - type + - with + - substring + type: object + TableWidgetTextFormatReplaceSubstringType: + description: Table widget text format replace sub-string type. + enum: + - substring + example: substring + type: string + x-enum-varnames: + - SUBSTRING + TableWidgetTextFormatRule: + description: Text format rules. + example: + match: + type: is + value: apple + replace: + type: all + with: vegetable + properties: + custom_bg_color: + description: Hex representation of the custom background color. Used with + custom background palette option. + example: '#632ca6' + type: string + custom_fg_color: + description: Hex representation of the custom text color. Used with custom + text palette option. + example: '#632ca6' + type: string + match: + $ref: '#/components/schemas/TableWidgetTextFormatMatch' + palette: + $ref: '#/components/schemas/TableWidgetTextFormatPalette' + replace: + $ref: '#/components/schemas/TableWidgetTextFormatReplace' + required: + - match type: object TagToHosts: description: In this object, the key is the tag, the value is a list of host diff --git a/examples/v1_dashboards_CreateDashboard_794302680.rs b/examples/v1_dashboards_CreateDashboard_794302680.rs new file mode 100644 index 000000000..2bfcfa59d --- /dev/null +++ b/examples/v1_dashboards_CreateDashboard_794302680.rs @@ -0,0 +1,200 @@ +// Create a new dashboard with query_table widget and text formatting +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::TableWidgetDefinition; +use datadog_api_client::datadogV1::model::TableWidgetDefinitionType; +use datadog_api_client::datadogV1::model::TableWidgetHasSearchBar; +use datadog_api_client::datadogV1::model::TableWidgetRequest; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatMatch; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatMatchType; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatPalette; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatReplace; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatReplaceAll; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatReplaceAllType; +use datadog_api_client::datadogV1::model::TableWidgetTextFormatRule; +use datadog_api_client::datadogV1::model::Widget; +use datadog_api_client::datadogV1::model::WidgetDefinition; +use datadog_api_client::datadogV1::model::WidgetLayout; +use datadog_api_client::datadogV1::model::WidgetTextAlign; + +#[tokio::main] +async fn main() { + let body = + Dashboard::new( + DashboardLayoutType::FREE, + "Example-Dashboard".to_string(), + vec![ + Widget::new( + WidgetDefinition::TableWidgetDefinition( + Box::new( + TableWidgetDefinition::new( + vec![ + TableWidgetRequest::new() + .formulas(vec![]) + .queries( + vec![ + FormulaAndFunctionQueryDefinition + ::FormulaAndFunctionMetricQueryDefinition( + Box::new( + FormulaAndFunctionMetricQueryDefinition::new( + FormulaAndFunctionMetricDataSource::METRICS, + "query1".to_string(), + "avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}".to_string(), + ).aggregator(FormulaAndFunctionMetricAggregation::AVG), + ), + ), + FormulaAndFunctionQueryDefinition + ::FormulaAndFunctionMetricQueryDefinition( + Box::new( + FormulaAndFunctionMetricQueryDefinition::new( + FormulaAndFunctionMetricDataSource::METRICS, + "query2".to_string(), + "avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}".to_string(), + ).aggregator(FormulaAndFunctionMetricAggregation::AVG), + ), + ) + ], + ) + .response_format(FormulaAndFunctionResponseFormat::SCALAR) + .text_formats( + vec![ + vec![ + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::IS, + "fruit".to_string(), + ), + ) + .palette(TableWidgetTextFormatPalette::WHITE_ON_RED) + .replace( + TableWidgetTextFormatReplace + ::TableWidgetTextFormatReplaceAll( + Box::new( + TableWidgetTextFormatReplaceAll::new( + TableWidgetTextFormatReplaceAllType::ALL, + "vegetable".to_string(), + ), + ), + ), + ), + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::IS, + "animal".to_string(), + ), + ) + .custom_bg_color("#632ca6".to_string()) + .palette(TableWidgetTextFormatPalette::CUSTOM_BG), + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::IS, + "robot".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::RED_ON_WHITE), + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::IS, + "ai".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::YELLOW_ON_WHITE) + ], + vec![ + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::IS_NOT, + "xyz".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::WHITE_ON_YELLOW) + ], + vec![ + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::CONTAINS, + "test".to_string(), + ), + ) + .palette(TableWidgetTextFormatPalette::WHITE_ON_GREEN) + .replace( + TableWidgetTextFormatReplace + ::TableWidgetTextFormatReplaceAll( + Box::new( + TableWidgetTextFormatReplaceAll::new( + TableWidgetTextFormatReplaceAllType::ALL, + "vegetable".to_string(), + ), + ), + ), + ) + ], + vec![ + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::DOES_NOT_CONTAIN, + "blah".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::BLACK_ON_LIGHT_RED) + ], + vec![ + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::STARTS_WITH, + "abc".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::BLACK_ON_LIGHT_YELLOW) + ], + vec![ + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::ENDS_WITH, + "xyz".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::BLACK_ON_LIGHT_GREEN), + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::ENDS_WITH, + "zzz".to_string(), + ), + ).palette(TableWidgetTextFormatPalette::GREEN_ON_WHITE), + TableWidgetTextFormatRule::new( + TableWidgetTextFormatMatch::new( + TableWidgetTextFormatMatchType::IS, + "animal".to_string(), + ), + ) + .custom_fg_color("#632ca6".to_string()) + .palette(TableWidgetTextFormatPalette::CUSTOM_TEXT) + ] + ], + ) + ], + TableWidgetDefinitionType::QUERY_TABLE, + ) + .has_search_bar(TableWidgetHasSearchBar::NEVER) + .title("".to_string()) + .title_align(WidgetTextAlign::LEFT) + .title_size("16".to_string()), + ), + ), + ).layout(WidgetLayout::new(4, 4, 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()); + } +} diff --git a/src/datadogV1/model/mod.rs b/src/datadogV1/model/mod.rs index 30e71c314..f0ffa8d0c 100644 --- a/src/datadogV1/model/mod.rs +++ b/src/datadogV1/model/mod.rs @@ -496,6 +496,24 @@ pub mod model_table_widget_has_search_bar; pub use self::model_table_widget_has_search_bar::TableWidgetHasSearchBar; pub mod model_table_widget_request; pub use self::model_table_widget_request::TableWidgetRequest; +pub mod model_table_widget_text_format_rule; +pub use self::model_table_widget_text_format_rule::TableWidgetTextFormatRule; +pub mod model_table_widget_text_format_match; +pub use self::model_table_widget_text_format_match::TableWidgetTextFormatMatch; +pub mod model_table_widget_text_format_match_type; +pub use self::model_table_widget_text_format_match_type::TableWidgetTextFormatMatchType; +pub mod model_table_widget_text_format_palette; +pub use self::model_table_widget_text_format_palette::TableWidgetTextFormatPalette; +pub mod model_table_widget_text_format_replace_all; +pub use self::model_table_widget_text_format_replace_all::TableWidgetTextFormatReplaceAll; +pub mod model_table_widget_text_format_replace_all_type; +pub use self::model_table_widget_text_format_replace_all_type::TableWidgetTextFormatReplaceAllType; +pub mod model_table_widget_text_format_replace_substring; +pub use self::model_table_widget_text_format_replace_substring::TableWidgetTextFormatReplaceSubstring; +pub mod model_table_widget_text_format_replace_substring_type; +pub use self::model_table_widget_text_format_replace_substring_type::TableWidgetTextFormatReplaceSubstringType; +pub mod model_table_widget_text_format_replace; +pub use self::model_table_widget_text_format_replace::TableWidgetTextFormatReplace; pub mod model_table_widget_definition_type; pub use self::model_table_widget_definition_type::TableWidgetDefinitionType; pub mod model_timeseries_widget_definition; diff --git a/src/datadogV1/model/model_table_widget_request.rs b/src/datadogV1/model/model_table_widget_request.rs index 2d4f342d0..06c729e02 100644 --- a/src/datadogV1/model/model_table_widget_request.rs +++ b/src/datadogV1/model/model_table_widget_request.rs @@ -71,6 +71,9 @@ pub struct TableWidgetRequest { /// The controls for sorting the widget. #[serde(rename = "sort")] pub sort: Option, + /// List of text formats for columns produced by tags. + #[serde(rename = "text_formats")] + pub text_formats: Option>>, #[serde(flatten)] pub additional_properties: std::collections::BTreeMap, #[serde(skip)] @@ -101,6 +104,7 @@ impl TableWidgetRequest { rum_query: None, security_query: None, sort: None, + text_formats: None, additional_properties: std::collections::BTreeMap::new(), _unparsed: false, } @@ -224,6 +228,14 @@ impl TableWidgetRequest { self } + pub fn text_formats( + mut self, + value: Vec>, + ) -> Self { + self.text_formats = Some(value); + self + } + pub fn additional_properties( mut self, value: std::collections::BTreeMap, @@ -287,6 +299,9 @@ impl<'de> Deserialize<'de> for TableWidgetRequest { let mut rum_query: Option = None; let mut security_query: Option = None; let mut sort: Option = None; + let mut text_formats: Option< + Vec>, + > = None; let mut additional_properties: std::collections::BTreeMap< String, serde_json::Value, @@ -450,6 +465,13 @@ impl<'de> Deserialize<'de> for TableWidgetRequest { } sort = Some(serde_json::from_value(v).map_err(M::Error::custom)?); } + "text_formats" => { + if v.is_null() { + continue; + } + text_formats = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } &_ => { if let Ok(value) = serde_json::from_value(v.clone()) { additional_properties.insert(k, value); @@ -479,6 +501,7 @@ impl<'de> Deserialize<'de> for TableWidgetRequest { rum_query, security_query, sort, + text_formats, additional_properties, _unparsed, }; diff --git a/src/datadogV1/model/model_table_widget_text_format_match.rs b/src/datadogV1/model/model_table_widget_text_format_match.rs new file mode 100644 index 000000000..a8df96e66 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_match.rs @@ -0,0 +1,114 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Match rule for the table widget text format. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TableWidgetTextFormatMatch { + /// Match or compare option. + #[serde(rename = "type")] + pub type_: crate::datadogV1::model::TableWidgetTextFormatMatchType, + /// Table Widget Match String. + #[serde(rename = "value")] + pub value: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TableWidgetTextFormatMatch { + pub fn new( + type_: crate::datadogV1::model::TableWidgetTextFormatMatchType, + value: String, + ) -> TableWidgetTextFormatMatch { + TableWidgetTextFormatMatch { + type_, + value, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatMatch { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TableWidgetTextFormatMatchVisitor; + impl<'a> Visitor<'a> for TableWidgetTextFormatMatchVisitor { + type Value = TableWidgetTextFormatMatch; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut type_: Option = + None; + let mut value: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV1::model::TableWidgetTextFormatMatchType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + "value" => { + value = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + let value = value.ok_or_else(|| M::Error::missing_field("value"))?; + + let content = TableWidgetTextFormatMatch { + type_, + value, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TableWidgetTextFormatMatchVisitor) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_match_type.rs b/src/datadogV1/model/model_table_widget_text_format_match_type.rs new file mode 100644 index 000000000..9ba38f162 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_match_type.rs @@ -0,0 +1,63 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TableWidgetTextFormatMatchType { + IS, + IS_NOT, + CONTAINS, + DOES_NOT_CONTAIN, + STARTS_WITH, + ENDS_WITH, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TableWidgetTextFormatMatchType { + fn to_string(&self) -> String { + match self { + Self::IS => String::from("is"), + Self::IS_NOT => String::from("is_not"), + Self::CONTAINS => String::from("contains"), + Self::DOES_NOT_CONTAIN => String::from("does_not_contain"), + Self::STARTS_WITH => String::from("starts_with"), + Self::ENDS_WITH => String::from("ends_with"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TableWidgetTextFormatMatchType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatMatchType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "is" => Self::IS, + "is_not" => Self::IS_NOT, + "contains" => Self::CONTAINS, + "does_not_contain" => Self::DOES_NOT_CONTAIN, + "starts_with" => Self::STARTS_WITH, + "ends_with" => Self::ENDS_WITH, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_palette.rs b/src/datadogV1/model/model_table_widget_text_format_palette.rs new file mode 100644 index 000000000..8efe24185 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_palette.rs @@ -0,0 +1,78 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TableWidgetTextFormatPalette { + WHITE_ON_RED, + WHITE_ON_YELLOW, + WHITE_ON_GREEN, + BLACK_ON_LIGHT_RED, + BLACK_ON_LIGHT_YELLOW, + BLACK_ON_LIGHT_GREEN, + RED_ON_WHITE, + YELLOW_ON_WHITE, + GREEN_ON_WHITE, + CUSTOM_BG, + CUSTOM_TEXT, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TableWidgetTextFormatPalette { + fn to_string(&self) -> String { + match self { + Self::WHITE_ON_RED => String::from("white_on_red"), + Self::WHITE_ON_YELLOW => String::from("white_on_yellow"), + Self::WHITE_ON_GREEN => String::from("white_on_green"), + Self::BLACK_ON_LIGHT_RED => String::from("black_on_light_red"), + Self::BLACK_ON_LIGHT_YELLOW => String::from("black_on_light_yellow"), + Self::BLACK_ON_LIGHT_GREEN => String::from("black_on_light_green"), + Self::RED_ON_WHITE => String::from("red_on_white"), + Self::YELLOW_ON_WHITE => String::from("yellow_on_white"), + Self::GREEN_ON_WHITE => String::from("green_on_white"), + Self::CUSTOM_BG => String::from("custom_bg"), + Self::CUSTOM_TEXT => String::from("custom_text"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TableWidgetTextFormatPalette { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatPalette { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "white_on_red" => Self::WHITE_ON_RED, + "white_on_yellow" => Self::WHITE_ON_YELLOW, + "white_on_green" => Self::WHITE_ON_GREEN, + "black_on_light_red" => Self::BLACK_ON_LIGHT_RED, + "black_on_light_yellow" => Self::BLACK_ON_LIGHT_YELLOW, + "black_on_light_green" => Self::BLACK_ON_LIGHT_GREEN, + "red_on_white" => Self::RED_ON_WHITE, + "yellow_on_white" => Self::YELLOW_ON_WHITE, + "green_on_white" => Self::GREEN_ON_WHITE, + "custom_bg" => Self::CUSTOM_BG, + "custom_text" => Self::CUSTOM_TEXT, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_replace.rs b/src/datadogV1/model/model_table_widget_text_format_replace.rs new file mode 100644 index 000000000..8e297a7d9 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_replace.rs @@ -0,0 +1,45 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::{Deserialize, Deserializer, Serialize}; + +/// Replace rule for the table widget text format. +#[non_exhaustive] +#[derive(Clone, Debug, PartialEq, Serialize)] +#[serde(untagged)] +pub enum TableWidgetTextFormatReplace { + TableWidgetTextFormatReplaceAll(Box), + TableWidgetTextFormatReplaceSubstring( + Box, + ), + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatReplace { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value: serde_json::Value = Deserialize::deserialize(deserializer)?; + if let Ok(_v) = serde_json::from_value::< + Box, + >(value.clone()) + { + if !_v._unparsed { + return Ok(TableWidgetTextFormatReplace::TableWidgetTextFormatReplaceAll(_v)); + } + } + if let Ok(_v) = serde_json::from_value::< + Box, + >(value.clone()) + { + if !_v._unparsed { + return Ok(TableWidgetTextFormatReplace::TableWidgetTextFormatReplaceSubstring(_v)); + } + } + + return Ok(TableWidgetTextFormatReplace::UnparsedObject( + crate::datadog::UnparsedObject { value }, + )); + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_replace_all.rs b/src/datadogV1/model/model_table_widget_text_format_replace_all.rs new file mode 100644 index 000000000..c9428657d --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_replace_all.rs @@ -0,0 +1,115 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Match All definition. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TableWidgetTextFormatReplaceAll { + /// Table widget text format replace all type. + #[serde(rename = "type")] + pub type_: crate::datadogV1::model::TableWidgetTextFormatReplaceAllType, + /// Replace All type. + #[serde(rename = "with")] + pub with: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TableWidgetTextFormatReplaceAll { + pub fn new( + type_: crate::datadogV1::model::TableWidgetTextFormatReplaceAllType, + with: String, + ) -> TableWidgetTextFormatReplaceAll { + TableWidgetTextFormatReplaceAll { + type_, + with, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatReplaceAll { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TableWidgetTextFormatReplaceAllVisitor; + impl<'a> Visitor<'a> for TableWidgetTextFormatReplaceAllVisitor { + type Value = TableWidgetTextFormatReplaceAll; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut type_: Option< + crate::datadogV1::model::TableWidgetTextFormatReplaceAllType, + > = None; + let mut with: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV1::model::TableWidgetTextFormatReplaceAllType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + "with" => { + with = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + let with = with.ok_or_else(|| M::Error::missing_field("with"))?; + + let content = TableWidgetTextFormatReplaceAll { + type_, + with, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TableWidgetTextFormatReplaceAllVisitor) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_replace_all_type.rs b/src/datadogV1/model/model_table_widget_text_format_replace_all_type.rs new file mode 100644 index 000000000..3ecc374b2 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_replace_all_type.rs @@ -0,0 +1,48 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TableWidgetTextFormatReplaceAllType { + ALL, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TableWidgetTextFormatReplaceAllType { + fn to_string(&self) -> String { + match self { + Self::ALL => String::from("all"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TableWidgetTextFormatReplaceAllType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatReplaceAllType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "all" => Self::ALL, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_replace_substring.rs b/src/datadogV1/model/model_table_widget_text_format_replace_substring.rs new file mode 100644 index 000000000..a7042ca8c --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_replace_substring.rs @@ -0,0 +1,126 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Match Sub-string definition. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TableWidgetTextFormatReplaceSubstring { + /// Text that will be replaced. + #[serde(rename = "substring")] + pub substring: String, + /// Table widget text format replace sub-string type. + #[serde(rename = "type")] + pub type_: crate::datadogV1::model::TableWidgetTextFormatReplaceSubstringType, + /// Text that will replace original sub-string. + #[serde(rename = "with")] + pub with: String, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TableWidgetTextFormatReplaceSubstring { + pub fn new( + substring: String, + type_: crate::datadogV1::model::TableWidgetTextFormatReplaceSubstringType, + with: String, + ) -> TableWidgetTextFormatReplaceSubstring { + TableWidgetTextFormatReplaceSubstring { + substring, + type_, + with, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatReplaceSubstring { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TableWidgetTextFormatReplaceSubstringVisitor; + impl<'a> Visitor<'a> for TableWidgetTextFormatReplaceSubstringVisitor { + type Value = TableWidgetTextFormatReplaceSubstring; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut substring: Option = None; + let mut type_: Option< + crate::datadogV1::model::TableWidgetTextFormatReplaceSubstringType, + > = None; + let mut with: Option = None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "substring" => { + substring = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "type" => { + type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _type_) = type_ { + match _type_ { + crate::datadogV1::model::TableWidgetTextFormatReplaceSubstringType::UnparsedObject(_type_) => { + _unparsed = true; + }, + _ => {} + } + } + } + "with" => { + with = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let substring = substring.ok_or_else(|| M::Error::missing_field("substring"))?; + let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?; + let with = with.ok_or_else(|| M::Error::missing_field("with"))?; + + let content = TableWidgetTextFormatReplaceSubstring { + substring, + type_, + with, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TableWidgetTextFormatReplaceSubstringVisitor) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_replace_substring_type.rs b/src/datadogV1/model/model_table_widget_text_format_replace_substring_type.rs new file mode 100644 index 000000000..6ceec2276 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_replace_substring_type.rs @@ -0,0 +1,48 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. + +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[non_exhaustive] +#[derive(Clone, Debug, Eq, PartialEq)] +pub enum TableWidgetTextFormatReplaceSubstringType { + SUBSTRING, + UnparsedObject(crate::datadog::UnparsedObject), +} + +impl ToString for TableWidgetTextFormatReplaceSubstringType { + fn to_string(&self) -> String { + match self { + Self::SUBSTRING => String::from("substring"), + Self::UnparsedObject(v) => v.value.to_string(), + } + } +} + +impl Serialize for TableWidgetTextFormatReplaceSubstringType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self { + Self::UnparsedObject(v) => v.serialize(serializer), + _ => serializer.serialize_str(self.to_string().as_str()), + } + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatReplaceSubstringType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let s: String = String::deserialize(deserializer)?; + Ok(match s.as_str() { + "substring" => Self::SUBSTRING, + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { + value: serde_json::Value::String(s.into()), + }), + }) + } +} diff --git a/src/datadogV1/model/model_table_widget_text_format_rule.rs b/src/datadogV1/model/model_table_widget_text_format_rule.rs new file mode 100644 index 000000000..0f504df78 --- /dev/null +++ b/src/datadogV1/model/model_table_widget_text_format_rule.rs @@ -0,0 +1,182 @@ +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2019-Present Datadog, Inc. +use serde::de::{Error, MapAccess, Visitor}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde_with::skip_serializing_none; +use std::fmt::{self, Formatter}; + +/// Text format rules. +#[non_exhaustive] +#[skip_serializing_none] +#[derive(Clone, Debug, PartialEq, Serialize)] +pub struct TableWidgetTextFormatRule { + /// Hex representation of the custom background color. Used with custom background palette option. + #[serde(rename = "custom_bg_color")] + pub custom_bg_color: Option, + /// Hex representation of the custom text color. Used with custom text palette option. + #[serde(rename = "custom_fg_color")] + pub custom_fg_color: Option, + /// Match rule for the table widget text format. + #[serde(rename = "match")] + pub match_: crate::datadogV1::model::TableWidgetTextFormatMatch, + /// Color-on-color palette to highlight replaced text. + #[serde(rename = "palette")] + pub palette: Option, + /// Replace rule for the table widget text format. + #[serde(rename = "replace")] + pub replace: Option, + #[serde(flatten)] + pub additional_properties: std::collections::BTreeMap, + #[serde(skip)] + #[serde(default)] + pub(crate) _unparsed: bool, +} + +impl TableWidgetTextFormatRule { + pub fn new( + match_: crate::datadogV1::model::TableWidgetTextFormatMatch, + ) -> TableWidgetTextFormatRule { + TableWidgetTextFormatRule { + custom_bg_color: None, + custom_fg_color: None, + match_, + palette: None, + replace: None, + additional_properties: std::collections::BTreeMap::new(), + _unparsed: false, + } + } + + pub fn custom_bg_color(mut self, value: String) -> Self { + self.custom_bg_color = Some(value); + self + } + + pub fn custom_fg_color(mut self, value: String) -> Self { + self.custom_fg_color = Some(value); + self + } + + pub fn palette(mut self, value: crate::datadogV1::model::TableWidgetTextFormatPalette) -> Self { + self.palette = Some(value); + self + } + + pub fn replace(mut self, value: crate::datadogV1::model::TableWidgetTextFormatReplace) -> Self { + self.replace = Some(value); + self + } + + pub fn additional_properties( + mut self, + value: std::collections::BTreeMap, + ) -> Self { + self.additional_properties = value; + self + } +} + +impl<'de> Deserialize<'de> for TableWidgetTextFormatRule { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + struct TableWidgetTextFormatRuleVisitor; + impl<'a> Visitor<'a> for TableWidgetTextFormatRuleVisitor { + type Value = TableWidgetTextFormatRule; + + fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("a mapping") + } + + fn visit_map(self, mut map: M) -> Result + where + M: MapAccess<'a>, + { + let mut custom_bg_color: Option = None; + let mut custom_fg_color: Option = None; + let mut match_: Option = None; + let mut palette: Option = + None; + let mut replace: Option = + None; + let mut additional_properties: std::collections::BTreeMap< + String, + serde_json::Value, + > = std::collections::BTreeMap::new(); + let mut _unparsed = false; + + while let Some((k, v)) = map.next_entry::()? { + match k.as_str() { + "custom_bg_color" => { + if v.is_null() { + continue; + } + custom_bg_color = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "custom_fg_color" => { + if v.is_null() { + continue; + } + custom_fg_color = + Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "match" => { + match_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + } + "palette" => { + if v.is_null() { + continue; + } + palette = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _palette) = palette { + match _palette { + crate::datadogV1::model::TableWidgetTextFormatPalette::UnparsedObject(_palette) => { + _unparsed = true; + }, + _ => {} + } + } + } + "replace" => { + if v.is_null() { + continue; + } + replace = Some(serde_json::from_value(v).map_err(M::Error::custom)?); + if let Some(ref _replace) = replace { + match _replace { + crate::datadogV1::model::TableWidgetTextFormatReplace::UnparsedObject(_replace) => { + _unparsed = true; + }, + _ => {} + } + } + } + &_ => { + if let Ok(value) = serde_json::from_value(v.clone()) { + additional_properties.insert(k, value); + } + } + } + } + let match_ = match_.ok_or_else(|| M::Error::missing_field("match_"))?; + + let content = TableWidgetTextFormatRule { + custom_bg_color, + custom_fg_color, + match_, + palette, + replace, + additional_properties, + _unparsed, + }; + + Ok(content) + } + } + + deserializer.deserialize_any(TableWidgetTextFormatRuleVisitor) + } +} diff --git a/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.frozen b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.frozen new file mode 100644 index 000000000..8c1436def --- /dev/null +++ b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.frozen @@ -0,0 +1 @@ +2024-09-11T14:33:18.508Z \ No newline at end of file diff --git a/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.json b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.json new file mode 100644 index 000000000..4bd089e68 --- /dev/null +++ b/tests/scenarios/cassettes/v1/dashboards/Create-a-new-dashboard-with-query-table-widget-and-text-formatting.json @@ -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_query_table_widget_and_text_formatting-1726065198\",\"widgets\":[{\"definition\":{\"has_search_bar\":\"never\",\"requests\":[{\"formulas\":[],\"queries\":[{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}\"},{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query2\",\"query\":\"avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}\"}],\"response_format\":\"scalar\",\"text_formats\":[[{\"match\":{\"type\":\"is\",\"value\":\"fruit\"},\"palette\":\"white_on_red\",\"replace\":{\"type\":\"all\",\"with\":\"vegetable\"}},{\"custom_bg_color\":\"#632ca6\",\"match\":{\"type\":\"is\",\"value\":\"animal\"},\"palette\":\"custom_bg\"},{\"match\":{\"type\":\"is\",\"value\":\"robot\"},\"palette\":\"red_on_white\"},{\"match\":{\"type\":\"is\",\"value\":\"ai\"},\"palette\":\"yellow_on_white\"}],[{\"match\":{\"type\":\"is_not\",\"value\":\"xyz\"},\"palette\":\"white_on_yellow\"}],[{\"match\":{\"type\":\"contains\",\"value\":\"test\"},\"palette\":\"white_on_green\",\"replace\":{\"type\":\"all\",\"with\":\"vegetable\"}}],[{\"match\":{\"type\":\"does_not_contain\",\"value\":\"blah\"},\"palette\":\"black_on_light_red\"}],[{\"match\":{\"type\":\"starts_with\",\"value\":\"abc\"},\"palette\":\"black_on_light_yellow\"}],[{\"match\":{\"type\":\"ends_with\",\"value\":\"xyz\"},\"palette\":\"black_on_light_green\"},{\"match\":{\"type\":\"ends_with\",\"value\":\"zzz\"},\"palette\":\"green_on_white\"},{\"custom_fg_color\":\"#632ca6\",\"match\":{\"type\":\"is\",\"value\":\"animal\"},\"palette\":\"custom_text\"}]]}],\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"query_table\"},\"layout\":{\"height\":4,\"width\":4,\"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\":\"462-puf-hkg\",\"title\":\"Test-Create_a_new_dashboard_with_query_table_widget_and_text_formatting-1726065198\",\"description\":\"\",\"author_handle\":\"frog@datadoghq.com\",\"author_name\":null,\"layout_type\":\"free\",\"url\":\"/dashboard/462-puf-hkg/test-createanewdashboardwithquerytablewidgetandtextformatting-1726065198\",\"is_read_only\":false,\"template_variables\":[],\"widgets\":[{\"definition\":{\"has_search_bar\":\"never\",\"requests\":[{\"formulas\":[],\"queries\":[{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query1\",\"query\":\"avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}\"},{\"aggregator\":\"avg\",\"data_source\":\"metrics\",\"name\":\"query2\",\"query\":\"avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}\"}],\"response_format\":\"scalar\",\"text_formats\":[[{\"match\":{\"type\":\"is\",\"value\":\"fruit\"},\"palette\":\"white_on_red\",\"replace\":{\"type\":\"all\",\"with\":\"vegetable\"}},{\"custom_bg_color\":\"#632ca6\",\"match\":{\"type\":\"is\",\"value\":\"animal\"},\"palette\":\"custom_bg\"},{\"match\":{\"type\":\"is\",\"value\":\"robot\"},\"palette\":\"red_on_white\"},{\"match\":{\"type\":\"is\",\"value\":\"ai\"},\"palette\":\"yellow_on_white\"}],[{\"match\":{\"type\":\"is_not\",\"value\":\"xyz\"},\"palette\":\"white_on_yellow\"}],[{\"match\":{\"type\":\"contains\",\"value\":\"test\"},\"palette\":\"white_on_green\",\"replace\":{\"type\":\"all\",\"with\":\"vegetable\"}}],[{\"match\":{\"type\":\"does_not_contain\",\"value\":\"blah\"},\"palette\":\"black_on_light_red\"}],[{\"match\":{\"type\":\"starts_with\",\"value\":\"abc\"},\"palette\":\"black_on_light_yellow\"}],[{\"match\":{\"type\":\"ends_with\",\"value\":\"xyz\"},\"palette\":\"black_on_light_green\"},{\"match\":{\"type\":\"ends_with\",\"value\":\"zzz\"},\"palette\":\"green_on_white\"},{\"custom_fg_color\":\"#632ca6\",\"match\":{\"type\":\"is\",\"value\":\"animal\"},\"palette\":\"custom_text\"}]]}],\"title\":\"\",\"title_align\":\"left\",\"title_size\":\"16\",\"type\":\"query_table\"},\"layout\":{\"height\":4,\"width\":4,\"x\":0,\"y\":0},\"id\":3373154044387493}],\"notify_list\":[],\"created_at\":\"2024-09-11T14:33:18.843540+00:00\",\"modified_at\":\"2024-09-11T14:33:18.843540+00:00\",\"experience_type\":\"default\",\"restricted_roles\":[]}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 11 Sep 2024 14:33:18 GMT" + }, + { + "request": { + "body": "", + "headers": { + "Accept": [ + "application/json" + ] + }, + "method": "delete", + "uri": "https://api.datadoghq.com/api/v1/dashboard/462-puf-hkg" + }, + "response": { + "body": { + "string": "{\"deleted_dashboard_id\":\"462-puf-hkg\"}\n", + "encoding": null + }, + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "status": { + "code": 200, + "message": "OK" + } + }, + "recorded_at": "Wed, 11 Sep 2024 14:33:18 GMT" + } + ], + "recorded_with": "VCR 6.0.0" +} \ No newline at end of file diff --git a/tests/scenarios/features/v1/dashboards.feature b/tests/scenarios/features/v1/dashboards.feature index 27f714940..33eaed7f4 100644 --- a/tests/scenarios/features/v1/dashboards.feature +++ b/tests/scenarios/features/v1/dashboards.feature @@ -580,6 +580,22 @@ Feature: Dashboards And the response "widgets[0].definition.requests[0].sort.order_by[0].type" is equal to "formula" And the response "widgets[0].definition.requests[0].sort.order_by[0].index" is equal to 0 + @team:DataDog/dashboards-backend + Scenario: Create a new dashboard with query_table widget and text formatting + Given new "CreateDashboard" request + And body from file "dashboards_json_payload/query_table_widget_text_formatting.json" + When the request is sent + Then the response status is 200 OK + And the response "widgets[0].definition.type" is equal to "query_table" + And the response "widgets[0].definition.requests[0].text_formats[0][0].match.type" is equal to "is" + And the response "widgets[0].definition.requests[0].text_formats[0][0].match.value" is equal to "fruit" + And the response "widgets[0].definition.requests[0].text_formats[0][0].palette" is equal to "white_on_red" + And the response "widgets[0].definition.requests[0].text_formats[0][0].replace.type" is equal to "all" + And the response "widgets[0].definition.requests[0].text_formats[0][0].replace.with" is equal to "vegetable" + And the response "widgets[0].definition.requests[0].text_formats[0][1].palette" is equal to "custom_bg" + And the response "widgets[0].definition.requests[0].text_formats[0][1].custom_bg_color" is equal to "#632ca6" + And the response "widgets[0].definition.requests[0].text_formats[5][2].custom_fg_color" is equal to "#632ca6" + @team:DataDog/dashboards-backend Scenario: Create a new dashboard with query_value widget Given new "CreateDashboard" request diff --git a/tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json b/tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json new file mode 100644 index 000000000..16ab24305 --- /dev/null +++ b/tests/scenarios/features/v1/dashboards_json_payload/query_table_widget_text_formatting.json @@ -0,0 +1,147 @@ +{ + "title": "{{ unique }}", + "description": "", + "widgets": [ + { + "definition": { + "title": "", + "title_size": "16", + "title_align": "left", + "type": "query_table", + "requests": [ + { + "queries": [ + { + "aggregator": "avg", + "data_source": "metrics", + "name": "query1", + "query": "avg:aws.stream.globalaccelerator.processed_bytes_in{*} by {aws_account,acceleratoripaddress}" + }, + { + "aggregator": "avg", + "data_source": "metrics", + "name": "query2", + "query": "avg:aws.stream.globalaccelerator.processed_bytes_out{*} by {aws_account,acceleratoripaddress}" + } + ], + "response_format": "scalar", + "text_formats": [ + [ + { + "match": { + "type": "is", + "value": "fruit" + }, + "palette": "white_on_red", + "replace": { + "type": "all", + "with": "vegetable" + } + }, + { + "match": { + "type": "is", + "value": "animal" + }, + "palette": "custom_bg", + "custom_bg_color": "#632ca6" + }, + { + "match": { + "type": "is", + "value": "robot" + }, + "palette": "red_on_white" + }, + { + "match": { + "type": "is", + "value": "ai" + }, + "palette": "yellow_on_white" + } + ], + [ + { + "match": { + "type": "is_not", + "value": "xyz" + }, + "palette": "white_on_yellow" + } + ], + [ + { + "match": { + "type": "contains", + "value": "test" + }, + "palette": "white_on_green", + "replace": { + "type": "all", + "with": "vegetable" + } + } + ], + [ + { + "match": { + "type": "does_not_contain", + "value": "blah" + }, + "palette": "black_on_light_red" + } + ], + [ + { + "match": { + "type": "starts_with", + "value": "abc" + }, + "palette": "black_on_light_yellow" + } + ], + [ + { + "match": { + "type": "ends_with", + "value": "xyz" + }, + "palette": "black_on_light_green" + }, + { + "match": { + "type": "ends_with", + "value": "zzz" + }, + "palette": "green_on_white" + }, + { + "match": { + "type": "is", + "value": "animal" + }, + "palette": "custom_text", + "custom_fg_color": "#632ca6" + } + ] + ], + "formulas": [ + ] + } + ], + "has_search_bar": "never" + }, + "layout": { + "x": 0, + "y": 0, + "width": 4, + "height": 4 + } + } + ], + "template_variables": [], + "layout_type": "free", + "is_read_only": false, + "notify_list": [] +}