(cherry picked from commit 01deae2105)
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
co-authored by
Ryan McKinley
parent
ac1ca2e4b5
commit
258f3eae32
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user