Fix dashboard migration discrepancies between backend and frontend implementations (use toEqual) (#110268)
**Highlights**
* **Single-version migrations**: add `targetVersion` to migrator & model, separate outputs, enforce exact version.
* **Datasource fixes**: include `apiVersion` in tests, empty-string → `{}`, preserve `{}` refs, drop unwanted defaults.
* **Panel defaults & nesting**: only top-level panels get defaults; preserve empty `transformations` context-aware; filter repeated panels.
* **Migration parity**
* V16: collapsed rows, grid height parsing (`px`).
* V17: omit `maxPerRow` when `minSpan=1`.
* V19–V20: cleanup defaults (`targetBlank`, style).
* V23–V24: template vars + table panel consistency.
* V28: full singlestat/stat parity, mappings & color.
* V30–V36: threshold logic, empty refs, nested targets.
* **Save-model cleanup**: replicate frontend defaults/filtering, drop null IDs, metadata, unused props.
* **Testing**: unified suites, dev dashboards (v42), full unit coverage for major migrations.
Co-authored-by: Ivan Ortega [ivanortegaalba@gmail.com](mailto:ivanortegaalba@gmail.com)
Co-authored-by: Dominik Prokop [dominik.prokop@grafana.com](mailto:dominik.prokop@grafana.com)
This commit is contained in:
co-authored by
Ivan Ortega [ivanortegaalba@gmail.com](mailto:ivanortegaalba@gmail.com)
Dominik Prokop [dominik.prokop@grafana.com](mailto:dominik.prokop@grafana.com)
parent
98fd3e8fe9
commit
a72e02f88a
@@ -82,7 +82,8 @@ func migrateMinSpanToMaxPerRow(panel map[string]interface{}) {
|
||||
max := gridColumnCount / minSpan
|
||||
factors := getFactors(gridColumnCount)
|
||||
|
||||
// Find the first factor greater than max
|
||||
// Find the first factor greater than max, then use the previous factor
|
||||
// This matches the frontend logic: findIndex(factors, (o) => o > max) - 1
|
||||
factorIndex := -1
|
||||
for i, factor := range factors {
|
||||
if float64(factor) > max {
|
||||
@@ -91,16 +92,20 @@ func migrateMinSpanToMaxPerRow(panel map[string]interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// Use the previous factor as maxPerRow
|
||||
// Use the previous factor as maxPerRow (matching frontend logic exactly)
|
||||
// The frontend code does: factors[findIndex(factors, (o) => o > max) - 1]
|
||||
// When findIndex returns -1, this becomes factors[-2] which is undefined
|
||||
// So we need to match this behavior
|
||||
if factorIndex > 0 {
|
||||
panel["maxPerRow"] = factors[factorIndex-1]
|
||||
} else if factorIndex == 0 {
|
||||
// If the first factor is already greater than max, use 1
|
||||
panel["maxPerRow"] = 1
|
||||
} else {
|
||||
// If no factor is greater than max, use the largest factor
|
||||
panel["maxPerRow"] = factors[len(factors)-1]
|
||||
}
|
||||
// If no factor is greater than max, don't set maxPerRow
|
||||
// This matches frontend behavior when findIndex returns -1
|
||||
// The frontend sets maxPerRow to undefined, which gets filtered out
|
||||
// So we don't set it at all
|
||||
|
||||
// Remove the minSpan property
|
||||
delete(panel, "minSpan")
|
||||
|
||||
Reference in New Issue
Block a user