Compare commits

..

1 Commits

Author SHA1 Message Date
Naman Verma
a238ed367d fix: choose first panel during migration (#12353)
Some checks are pending
build-staging / prepare (push) Waiting to run
build-staging / js-build (push) Blocked by required conditions
build-staging / go-build (push) Blocked by required conditions
build-staging / staging (push) Blocked by required conditions
Release Drafter / update_release_draft (push) Waiting to run
* fix: choose first panel during migration

* test: add unit test
2026-07-31 08:59:13 +00:00
2 changed files with 21 additions and 0 deletions

View File

@@ -41,6 +41,9 @@ func (d *v1Decoder) convertV1Panels(raw any) map[string]*Panel {
if !ok || id == "" {
continue
}
if _, present := panels[id]; present {
continue
}
var panel *Panel
panelType := d.readString(widget, "panelTypes")
switch panelType {

View File

@@ -238,6 +238,24 @@ func TestConvertV1PanelsSkipsUnknownType(t *testing.T) {
require.NoError(t, d.errIfHasMalformedFields())
}
// TestConvertV1PanelsKeepsFirstOfDuplicateIDs verifies that when two widgets share
// an id, the first is kept and later ones dropped — matching v1's widgets.find()
// lookup, which returns the first match.
func TestConvertV1PanelsKeepsFirstOfDuplicateIDs(t *testing.T) {
widgets := []any{
map[string]any{"id": "dup", "panelTypes": "graph", "title": "First", "query": singleLogsBuilderQuery()},
map[string]any{"id": "dup", "panelTypes": "graph", "title": "Second", "query": singleLogsBuilderQuery()},
}
d := &v1Decoder{}
panels := d.convertV1Panels(widgets)
require.NoError(t, d.errIfHasMalformedFields())
require.Len(t, panels, 1)
require.Contains(t, panels, "dup")
assert.Equal(t, "First", panels["dup"].Spec.Display.Name)
}
func TestConvertGraphWidgetToTimeSeriesPanel(t *testing.T) {
widget := map[string]any{
"id": "widget-1",