Skip to content

Commit 76d202d

Browse files
[BUGFIX] Table: don't fail migration on duplicated rename
Signed-off-by: AntoineThebaud <antoine.thebaud@yahoo.fr>
1 parent 15a6498 commit 76d202d

3 files changed

Lines changed: 66 additions & 6 deletions

File tree

table/schemas/migrate/migrate.cue

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,34 @@ spec: {
5959
}
6060

6161
// Retrieve the settings defined in transformations
62-
_columnSettingsFromTansform: {
62+
// We collect possible values first, then resolve to the last one to mimic Grafana precedence.
63+
_columnSettingsFromTransformRaw: {
6364
for transformation in (*#panel.transformations | []) if transformation.id == "organize" {
6465
for columnName, columnIndex in (*transformation.options.indexByName | {}) {
65-
"\({_renameAnonymousFields & {#var: columnName}}.output)": index: columnIndex
66+
"\({_renameAnonymousFields & {#var: columnName}}.output)": indexes: "\(columnIndex)": true
6667
}
6768
for columnName, hidden in (*transformation.options.excludeByName | {}) {
68-
"\({_renameAnonymousFields & {#var: columnName}}.output)": hide: hidden
69+
"\({_renameAnonymousFields & {#var: columnName}}.output)": hides: "\(hidden)": true
6970
}
7071
for columnName, displayName in (*transformation.options.renameByName | {}) {
71-
"\({_renameAnonymousFields & {#var: columnName}}.output)": header: displayName
72+
"\({_renameAnonymousFields & {#var: columnName}}.output)": headers: "\(displayName)": true
73+
}
74+
}
75+
}
76+
_columnSettingsFromTransform: {
77+
for name, settings in _columnSettingsFromTransformRaw {
78+
"\(name)": {
79+
if settings.indexes != _|_ if len(settings.indexes) > 0 {
80+
_index: {_getLastKey & {#map: settings.indexes}}.output
81+
index: strconv.Atoi(_index)
82+
}
83+
if settings.hides != _|_ if len(settings.hides) > 0 {
84+
_hide: {_getLastKey & {#map: settings.hides}}.output
85+
hide: _hide == "true"
86+
}
87+
if settings.headers != _|_ if len(settings.headers) > 0 {
88+
header: {_getLastKey & {#map: settings.headers}}.output
89+
}
7290
}
7391
}
7492
}
@@ -78,7 +96,7 @@ spec: {
7896
#var: string
7997
output: [
8098
// Check if the column was renamed by a transform
81-
for k, v in _columnSettingsFromTansform if #var == (*v.header | null) {k},
99+
for k, v in _columnSettingsFromTransform if #var == (*v.header | null) {k},
82100
{_renameAnonymousFields & {#var: this.#var}}.output,
83101
][0]
84102
}
@@ -131,7 +149,7 @@ spec: {
131149
}
132150
}
133151
}
134-
for name, settings in _columnSettingsFromTansform {
152+
for name, settings in _columnSettingsFromTransform {
135153
"\(name)": [
136154
// We have to hande potential name conflicts due to the overrides.
137155
// In Grafana field overrides take precedence over the organize transformations.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"kind": "Table",
3+
"spec": {
4+
"columnSettings": [
5+
{
6+
"header": "Instance",
7+
"name": "instance"
8+
}
9+
],
10+
"density": "compact"
11+
}
12+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"type": "table",
3+
"options": {
4+
"cellHeight": "sm"
5+
},
6+
"fieldConfig": {
7+
"defaults": {
8+
"mappings": []
9+
},
10+
"overrides": []
11+
},
12+
"transformations": [
13+
{
14+
"id": "organize",
15+
"options": {
16+
"renameByName": {
17+
"instance": "instance"
18+
}
19+
}
20+
},
21+
{
22+
"id": "organize",
23+
"options": {
24+
"renameByName": {
25+
"instance": "Instance"
26+
}
27+
}
28+
}
29+
]
30+
}

0 commit comments

Comments
 (0)