From 070d4b2ee466274a3cd145e107ab7690b0661eba Mon Sep 17 00:00:00 2001 From: Oscar Kilhed Date: Mon, 3 Mar 2025 11:19:17 +0100 Subject: [PATCH] SchemaV2: Accept rows with no panel property (#101503) accept rows with no panel property --- .../dashboard/api/ResponseTransformers.test.ts | 14 +++++++++++++- .../features/dashboard/api/ResponseTransformers.ts | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/public/app/features/dashboard/api/ResponseTransformers.test.ts b/public/app/features/dashboard/api/ResponseTransformers.test.ts index 4a7a29cf711..41064867a87 100644 --- a/public/app/features/dashboard/api/ResponseTransformers.test.ts +++ b/public/app/features/dashboard/api/ResponseTransformers.test.ts @@ -406,6 +406,13 @@ describe('ResponseTransformers', () => { ], collapsed: true, }, + { + id: 6, + type: 'row', + title: 'Row with no panel property', + gridPos: { x: 0, y: 25, w: 12, h: 1 }, + collapsed: true, + }, ], }; @@ -483,7 +490,7 @@ describe('ResponseTransformers', () => { // Panel expect(spec.layout.kind).toBe('GridLayout'); const layout = spec.layout as GridLayoutKind; - expect(layout.spec.items).toHaveLength(4); + expect(layout.spec.items).toHaveLength(5); expect(layout.spec.items[0].spec).toEqual({ element: { kind: 'ElementReference', @@ -606,6 +613,11 @@ describe('ResponseTransformers', () => { height: 8, }); + const rowWithNoPanelProperty = layout.spec.items[4].spec as GridLayoutRowSpec; + expect(rowWithNoPanelProperty.collapsed).toBe(true); + expect(rowWithNoPanelProperty.title).toBe('Row with no panel property'); + expect(rowWithNoPanelProperty.elements).toHaveLength(0); + // Variables validateVariablesV1ToV2(spec.variables[0], dashboardV1.templating?.list?.[0]); validateVariablesV1ToV2(spec.variables[1], dashboardV1.templating?.list?.[1]); diff --git a/public/app/features/dashboard/api/ResponseTransformers.ts b/public/app/features/dashboard/api/ResponseTransformers.ts index 5ad1d7836d6..4dc01f06a99 100644 --- a/public/app/features/dashboard/api/ResponseTransformers.ts +++ b/public/app/features/dashboard/api/ResponseTransformers.ts @@ -298,7 +298,7 @@ function getElementsFromPanels( const rowElements = []; - for (const panel of p.panels) { + for (const panel of p.panels || []) { const [element, name] = buildElement(panel); elements[name] = element; rowElements.push(buildGridItemKind(panel, name, yOffsetInRows(panel, p.gridPos!.y)));