93c14c52da
* wip: trying to understand how to get the ds info from migrator * add datasource info provider * Use DS service to fetch DS data * add more tests cases to match with migrator cases * Add snapshots * Non-existing DS * Add different DS for snapshots * fix import * Fix tests: guard against double initialization * don't use full datasource package in test * min version should be 35 * fix test * fix conversion test * Dashboards: Support schemaVersion v35 migration in backend * Dashboards: Support schemaVersion v34 migration in backend * Dashboards: Support schemaVersion v33 migration in backend * Apply suggestions from code review Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com> * Apply feedback * Remove unused parameters * Refactor to follow Go patterns * Update logic * Only write final migration result as output * Compare backend and frontend results * Improve snapshots to cover all possible use cases * Linter * wip make it consistent v33 * apply feedback * Return default when the ref cannot be found * Update apps/dashboard/pkg/migration/schemaversion/v33.go Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com> * apply feedback * Use same mocks backend/frontend * restore migrations * update snapshots * Adapt migration tests to use min versions * Ensure v40-v41 works * Ensure v39-v40 works * Simplify the naming of the files * adjust jest to new input convention * Ensure every migration v36-v41 works * Improve v38 naming * Ensure v36 migrates correctly * Skip v36 refs migrations on rows * Treat rows as frontend and ensure same results for v36 * Ensure v34 runs with the same logic than the frontend * Leave empty stadistics as valid option * ensure v33 is working as the frontend * Update tests * Undo frontend changes for legend handling * Remove filtering by version in the frontend * linter * Clean up v33 input JSON --------- Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com> Co-authored-by: Haris Rozajac <haris.rozajac12@gmail.com> Co-authored-by: Stephanie Hingtgen <stephanie.hingtgen@grafana.com>
129 lines
2.9 KiB
Go
129 lines
2.9 KiB
Go
package schemaversion
|
|
|
|
// V37 normalizes legend configuration to use `showLegend` property consistently.
|
|
//
|
|
// This migration addresses inconsistencies in how legend visibility was handled.
|
|
// There were two ways to hide the legend:
|
|
// 1. Using displayMode: "hidden"
|
|
// 2. Using showLegend: false
|
|
//
|
|
// The migration normalizes both approaches to use showLegend consistently:
|
|
// - If displayMode is "hidden" OR showLegend is false, set displayMode to "list" and showLegend to false
|
|
// - For all other existing legend objects, ensure showLegend is true
|
|
//
|
|
// Note: This migration only processes legend configurations that already exist as objects.
|
|
// Boolean legend values are not processed by this migration.
|
|
//
|
|
// Example transformations:
|
|
//
|
|
// Before migration (hidden displayMode):
|
|
//
|
|
// options: {
|
|
// legend: {
|
|
// displayMode: "hidden",
|
|
// placement: "bottom"
|
|
// }
|
|
// }
|
|
//
|
|
// After migration:
|
|
//
|
|
// options: {
|
|
// legend: {
|
|
// displayMode: "list",
|
|
// showLegend: false,
|
|
// placement: "bottom"
|
|
// }
|
|
// }
|
|
//
|
|
// Before migration (showLegend false):
|
|
//
|
|
// options: {
|
|
// legend: {
|
|
// displayMode: "table",
|
|
// showLegend: false
|
|
// }
|
|
// }
|
|
//
|
|
// After migration:
|
|
//
|
|
// options: {
|
|
// legend: {
|
|
// displayMode: "list",
|
|
// showLegend: false
|
|
// }
|
|
// }
|
|
//
|
|
// Before migration (visible legend):
|
|
//
|
|
// options: {
|
|
// legend: {
|
|
// displayMode: "table",
|
|
// placement: "bottom"
|
|
// }
|
|
// }
|
|
//
|
|
// After migration:
|
|
//
|
|
// options: {
|
|
// legend: {
|
|
// displayMode: "table",
|
|
// placement: "bottom",
|
|
// showLegend: true
|
|
// }
|
|
// }
|
|
func V37(dashboard map[string]interface{}) error {
|
|
dashboard["schemaVersion"] = int(37)
|
|
|
|
panels, ok := dashboard["panels"].([]interface{})
|
|
if !ok {
|
|
return nil
|
|
}
|
|
|
|
// Process all panels, including nested ones
|
|
processPanelsV37(panels)
|
|
|
|
return nil
|
|
}
|
|
|
|
// processPanelsV37 recursively processes panels, including nested panels within rows
|
|
func processPanelsV37(panels []interface{}) {
|
|
for _, panel := range panels {
|
|
p, ok := panel.(map[string]interface{})
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
// Process nested panels if this is a row panel
|
|
if p["type"] == "row" {
|
|
if nestedPanels, ok := p["panels"].([]interface{}); ok {
|
|
processPanelsV37(nestedPanels)
|
|
}
|
|
continue
|
|
}
|
|
|
|
options, ok := p["options"].(map[string]interface{})
|
|
if !ok {
|
|
continue
|
|
}
|
|
|
|
// Only process legend if it exists and is an object (not boolean)
|
|
legendValue := options["legend"]
|
|
legend, ok := legendValue.(map[string]interface{})
|
|
if !ok || legend == nil {
|
|
continue
|
|
}
|
|
|
|
displayMode, _ := legend["displayMode"].(string)
|
|
showLegend, hasShowLegend := legend["showLegend"].(bool)
|
|
|
|
// If displayMode is "hidden" OR showLegend is false, normalize to hidden legend
|
|
if displayMode == "hidden" || (hasShowLegend && !showLegend) {
|
|
legend["displayMode"] = "list"
|
|
legend["showLegend"] = false
|
|
} else {
|
|
// For all other cases, ensure showLegend is true
|
|
legend["showLegend"] = true
|
|
}
|
|
}
|
|
}
|