Skip to content
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
21 changes: 9 additions & 12 deletions table/schemas/migrate/migrate.cue
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ if (*#panel.type | null) == "table" {
#width: *property.value | "auto"
width: #width
}
// NB: enrich this part when this is done https://github.com/perses/perses/issues/2852
}
},
],
])

// Using flatten to avoid having an array of arrays with "value" mappings
// Using flatten to get rid of the nested array for "value" mappings
// (https://cuelang.org/docs/howto/use-list-flattenn-to-flatten-lists/)
let x = list.FlattenN([
if (*#panel.fieldConfig.defaults.mappings | null) != null for mapping in #panel.fieldConfig.defaults.mappings {
#cellSettings: list.FlattenN([
for mapping in (*#panel.fieldConfig.defaults.mappings | []) {
if mapping.type == "value" {
[for key, option in mapping.options {
condition: {
Expand All @@ -113,8 +114,7 @@ if (*#panel.type | null) == "table" {
}
}]
}

if mapping.type == "range" || mapping.type == "regex" || mapping.type == "special" {
if mapping.type != "value" { // else
condition: [//switch
if mapping.type == "range" {
kind: "Range"
Expand Down Expand Up @@ -144,7 +144,6 @@ if (*#panel.type | null) == "table" {
}
},
][0]

if mapping.options.result.text != _|_ {
text: mapping.options.result.text
}
Expand All @@ -153,14 +152,12 @@ if (*#panel.type | null) == "table" {
}
}
},
], 1)

if len(x) > 0 {
cellSettings: x
], 1),
if len(#cellSettings) != 0 {
cellSettings: #cellSettings
}

// Logic to build transforms:

if #panel.transformations != _|_ {
#transforms: [
for transformation in #panel.transformations if transformation.id == "merge" || transformation.id == "joinByField" {
Expand Down
23 changes: 13 additions & 10 deletions timeserieschart/schemas/migrate/migrate.cue
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,19 @@ spec: {
}

// migrate byName-based fixedColor overrides to querySettings when applicable
querySettings: [
#querySettings: [
for override in (*#panel.fieldConfig.overrides | [])
if override.matcher.id == "byName" && override.matcher.options != _|_
for property in override.properties
if (*property.value.fixedColor | null) != null
for i, target in (*#panel.targets | [])
if target.legendFormat == override.matcher.options {
queryIndex: i
colorMode: "fixed"
colorValue: property.value.fixedColor
}
if override.matcher.id == "byName" && override.matcher.options != _|_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would have been great to keep the indentation, the code is harder to read now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more correct like this because all the for & if are chained here (notice that there's no opening brace at the end of each line), so this doesnt mislead you in thinking we are generating structs in the middle of the chain. Actually if we were enforcing file formatting I think that would be the output since this is what I get on CUE playground:
image

for property in override.properties
if (*property.value.fixedColor | null) != null
for i, target in (*#panel.targets | [])
if target.legendFormat == override.matcher.options {
queryIndex: i
colorMode: "fixed"
colorValue: property.value.fixedColor
}
]
if len(#querySettings) != 0 {
querySettings: #querySettings
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"sum"
]
},
"querySettings": [],
"visual": {
"areaOpacity": 0,
"connectNulls": true,
Expand Down
1 change: 0 additions & 1 deletion timeserieschart/schemas/migrate/tests/basic/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"position": "bottom",
"values": []
},
"querySettings": [],
"visual": {
"areaOpacity": 0.1,
"connectNulls": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"kind": "TimeSeriesChart",
"spec": {
"querySettings": []
}
"spec": {}
}