defaultValue as object in customEditor

I’m not sure if it’s a bug or the intended behaviour so I prefer to ask a question here first before to open an issue.

I developped a plugin which use a json configuration as option and this option is modifiable with a custom editor (based on CodeEditor).

in the types.ts file, I declare my option as an object and define a default value as follow:

    export interface SimpleOptions{
      config: object;
    }

    export const defaults: SimpleOptions = {
      config: {
        title:"My title",
        line:{
          color:"red",
          width:4
        }
      }
    }

Then in module.ts, I add my custom editor with the default value

    .addCustomEditor({
      id: 'config',
      path: 'config',
      name: 'Configuration',
      description: 'Configuration of the chart',
      editor: PanelOptionCode,
      settings: {
        language: 'json'
      },
      defaultValue: defaults.config,
    })

Then I try to edit my configuration in the editor.
If I update a value or add a new attribute everything works fine but if I I remove an attribute (ie width), the attribute is automatically added when I try to re-edit my configuration.
I understand that Grafana forces the configuration object to have all the specify attributes in the default value. Is that the correct behaviour? If yes, then my default value should be an empty object but is there a way to specifiy an init value to help the user when he’s creating a new panel?

Thanks for your help

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.