mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelOptions: fix array with siblings (#39620)
This commit is contained in:
@@ -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 = {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user