PanelOptions: fix array with siblings (#39620)

pull/39625/head
Ryan McKinley 4 years ago committed by GitHub
parent 0db6ba9d70
commit c9ae46a9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      public/app/features/dashboard/components/PanelEditor/utils.test.ts
  2. 1
      public/app/features/dashboard/components/PanelEditor/utils.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);
});

@ -75,6 +75,7 @@ export function setOptionImmutably<T extends object>(options: T, path: string |
let current = (options as Record<string, any>)[propKey];
const arr = Array.isArray(current) ? [...current] : [];
if (splat.length) {
current = arr[index];
if (current == null || typeof current !== 'object') {
current = {};
}

Loading…
Cancel
Save