[MM-57418] Implement support for defining plugin settings sections (#27654)

* Implement support for defining plugin settings sections

* Implement custom plugin configuration sections

* Tests

* Update test

* Improvements
Этот коммит содержится в:
Claudio Costa
2024-07-17 18:24:33 +02:00
коммит произвёл GitHub
родитель c0a7a19294
Коммит be94c47607
17 изменённых файлов: 545 добавлений и 25 удалений

Просмотреть файл

@@ -91,6 +91,29 @@ type PluginSetting struct {
Hosting string `json:"hosting"`
}
type PluginSettingsSection struct {
// A unique identifier for this section.
Key string `json:"key" yaml:"key"`
// Optional text to display as section title.
Title string `json:"title" yaml:"title"`
// Optional text to display as section subtitle.
Subtitle string `json:"subtitle" yaml:"subtitle"`
// A list of setting definitions to display inside the section.
Settings []*PluginSetting `json:"settings" yaml:"settings"`
// Optional text to display above the settings. Supports Markdown formatting.
Header string `json:"header" yaml:"header"`
// Optional text to display below the settings. Supports Markdown formatting.
Footer string `json:"footer" yaml:"footer"`
// If true, the section will load the custom component registered using `registry.registerAdminConsoleCustomSection`
Custom bool `json:"custom" yaml:"custom"`
}
type PluginSettingsSchema struct {
// Optional text to display above the settings. Supports Markdown formatting.
Header string `json:"header" yaml:"header"`
@@ -100,6 +123,9 @@ type PluginSettingsSchema struct {
// A list of setting definitions.
Settings []*PluginSetting `json:"settings" yaml:"settings"`
// A list of settings section definitions.
Sections []*PluginSettingsSection `json:"sections" yaml:"sections"`
}
// The plugin manifest defines the metadata required to load and present your plugin. The manifest
@@ -330,6 +356,27 @@ func (s *PluginSettingsSchema) isValid() error {
}
}
for _, section := range s.Sections {
if err := section.IsValid(); err != nil {
return err
}
}
return nil
}
func (s *PluginSettingsSection) IsValid() error {
if s.Key == "" {
return errors.New("invalid empty Key")
}
for _, setting := range s.Settings {
err := setting.isValid()
if err != nil {
return err
}
}
return nil
}