From fee11227daf94802494eadc07a137c8fe0e70969 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Sat, 25 Sep 2021 11:58:09 -0400 Subject: [PATCH] PanelOptions: fix array with siblings (#39620) (#39623) (cherry picked from commit c9ae46a9adde629e762a298f1d3001c89ed88aa3) Co-authored-by: Ryan McKinley --- .../app/features/dashboard/components/PanelEditor/utils.test.ts | 1 + public/app/features/dashboard/components/PanelEditor/utils.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/public/app/features/dashboard/components/PanelEditor/utils.test.ts b/public/app/features/dashboard/components/PanelEditor/utils.test.ts index 6c3df98517c..b1466d3f724 100644 --- a/public/app/features/dashboard/components/PanelEditor/utils.test.ts +++ b/public/app/features/dashboard/components/PanelEditor/utils.test.ts @@ -98,6 +98,7 @@ describe('setOptionImmutably', () => { ${{}} | ${'a.b[2]'} | ${'x'} | ${{ a: { b: [undefined, undefined, 'x'] } }} ${{}} | ${'a[0]'} | ${1} | ${{ a: [1] }} ${{}} | ${'a[0].b.c'} | ${1} | ${{ a: [{ b: { c: 1 } }] }} + ${{ a: [{ b: 1 }] }} | ${'a[0].c'} | ${2} | ${{ a: [{ b: 1, c: 2 }] }} `('property value:${value', ({ source, path, value, expected }) => { expect(setOptionImmutably(source, path, value)).toEqual(expected); }); diff --git a/public/app/features/dashboard/components/PanelEditor/utils.ts b/public/app/features/dashboard/components/PanelEditor/utils.ts index f7febcd196f..37c626d4c5b 100644 --- a/public/app/features/dashboard/components/PanelEditor/utils.ts +++ b/public/app/features/dashboard/components/PanelEditor/utils.ts @@ -75,6 +75,7 @@ export function setOptionImmutably(options: T, path: string | let current = (options as Record)[propKey]; const arr = Array.isArray(current) ? [...current] : []; if (splat.length) { + current = arr[index]; if (current == null || typeof current !== 'object') { current = {}; }