Options: support array value paths for panel options (#39499) (#39596)

(cherry picked from commit 01deae2105)

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-09-23 10:58:14 -07:00
committed by GitHub
co-authored by Ryan McKinley
parent ac1ca2e4b5
commit 258f3eae32
4 changed files with 53 additions and 7 deletions
@@ -182,6 +182,27 @@ describe('PanelPlugin', () => {
expect(panel.fieldConfigDefaults.defaults.custom).toEqual(expectedDefaults);
});
test('throw error with array fieldConfigs', () => {
const panel = new PanelPlugin(() => {
return <div>Panel</div>;
});
panel.useFieldConfig({
useCustomConfig: (builder) => {
builder.addCustomEditor({
id: 'somethingUnique',
path: 'numericOption[0]',
name: 'Option editor',
description: 'Option editor description',
defaultValue: 10,
} as any);
},
});
expect(() => panel.fieldConfigRegistry).toThrowErrorMatchingInlineSnapshot(
`"[undefined] Field config paths do not support arrays: custom.somethingUnique"`
);
});
test('default values for nested paths', () => {
const panel = new PanelPlugin(() => {
return <div>Panel</div>;
@@ -75,6 +75,13 @@ export function createFieldConfigRegistry<TFieldConfigOptions>(
}
}
// assert that field configs do not use array path syntax
for (const item of registry.list()) {
if (item.path.indexOf('[') > 0) {
throw new Error(`[${pluginName}] Field config paths do not support arrays: ${item.id}`);
}
}
return registry;
}