Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom branding: centralize the plugin's settings #4443

Closed
13 tasks done
Tracked by #4392
Desvelao opened this issue Sep 6, 2022 · 6 comments · Fixed by #4501
Closed
13 tasks done
Tracked by #4392

Custom branding: centralize the plugin's settings #4443

Desvelao opened this issue Sep 6, 2022 · 6 comments · Fixed by #4501
Assignees
Labels
type/enhancement Enhancement issue

Comments

@Desvelao
Copy link
Member

Desvelao commented Sep 6, 2022

Description

The settings of the app are currently distributed in different files, and there are some repetitive tasks and bad practices. Adding a new setting has a high cost in development time.

Goal

  • Centralize the definition of the plugin's settings, so every side of the app reads the settings from the same source.
  • Reduce the future cost, in time, to add or remove plugin settings.

Tasks

  • Define a schema of properties to manage the current plugin logic
  • Adapt the affected sections of the plugin to use the new plugin setting definition, dynamically.
    • Default configuration file
    • Configuration in Settings/Configuration
  • Refactor the form
  • Create new hooks to manage the form state
  • Refactor the input components to do them uncontrolled.
  • Sort the plugin setting categories
  • Add description to category.
  • Tests
    • Default configuration file
    • useForm hook
    • InputForm component
@Desvelao Desvelao added the type/bug Bug issue label Sep 6, 2022
@Desvelao Desvelao self-assigned this Sep 6, 2022
@Desvelao Desvelao moved this to Triage in Release 4.4.0 Sep 6, 2022
@Desvelao Desvelao moved this from Triage to In Progress in Release 4.4.0 Sep 6, 2022
@Desvelao
Copy link
Member Author

Desvelao commented Sep 6, 2022

Automatic management of the plugin's settings

We're centralizing the plugin settings definitions in a single source.

These definitions are used by:

  • the generation of the initial/default plugin configuration file.
  • the Settings/Configuration UI section.

Both sections have been updated to use this new centralized mechanism to read the plugin's settings. This work will simplify the additions of new settings related to this white-labeling issue and future developments.

Objective

  • Reduce and simplify the time to add or remove a new setting. This will reduce the cost in time when we need to add or remove settings in the future.
  • Dynamically generate the sections that depend on the plugin's settings, by importing the settings and their descriptions from the centralized plugin's setting definitions file.

For example, a new setting is added in the definitions file, then:

  • It is included in the initial configuration file (wazuh.yml) automatically, at plugin's start.
  • The UI Settings/Configuration section reads the settings and generates the form dynamically.

Implementation

The settings are defined with a specific structure, as follows:

Property Definition
title Define the text displayed in the UI.
description Description.
category Category.
type Type of setting.
default Default value.
defaultHidden? Value used when there is no user value.
isConfigurableFromFile? This can be customized in the plugin configuration file.
isConfigurableFromUI? This can be customized from the UI.
requiresRunningHealthCheck? Require the health check of the plugin is run.
requiresReloadingBrowserTab? Require to reload the browser tab.
requiresRestartingPluginPlatform? Require to restart the plugin platform service.
options? Options to define the possible values, requirements, or extra data. This could be expanded.
uiFormTransformChangedInputValue? Transform the input value. The result is saved in the form of Settings/Configuration.
uiFormTransformInputValueToConfigurationValue? Transform the configuration value or default as initial value for the input in Settings/Configuration
uiFormTransformConfigurationValueToInputValue? Transform the input value changed in the form of Settings/Configuration and returned in the changed property of the hook useForm
validate? Validate the value. Return a string if there is some validation error.
validateBackend? Validate the value in the related endpoints. Use schema of @kbn/config-schema package.

Removed no longer used code

Some files were removed because of the centralization of the plugin settings definitions.

Adaptions

Adapted:

  • The generation of the initial plugin configuration file is now made according to the centralized plugin's settings.
  • The Settings/Configuration UI section has been updated:
    • The UI form has been updated.
    • The search bar and filter by categories has been updated.
  • Removed unnecessary components: Categories

@Desvelao
Copy link
Member Author

Desvelao commented Sep 7, 2022

  • Renamed the validationOptions to validate
  • Added new properties to manage how the assets are stored:
    • Define the relative target path of the plugin where the file will be stored
    • Define the target filename
    • Define the resolved URL which is exposed (public)

@Desvelao
Copy link
Member Author

Desvelao commented Sep 8, 2022

  • Added new options type related to the editor input form.

@Desvelao
Copy link
Member Author

Desvelao commented Sep 9, 2022

  • Added new setting property
Property Required Description
transformUIInputValue No Transforms the value of the input HTML element

This setting helps to transform the expected value for the settings of type switch whose possible values are: true or "" that don't match with the current requirements of true/false (boolean).

@AlexRuiz7 AlexRuiz7 changed the title Centralize the plugin settings definition Centralize the plugin's settings definition Sep 12, 2022
@Desvelao Desvelao linked a pull request Sep 13, 2022 that will close this issue
@AlexRuiz7 AlexRuiz7 changed the title Centralize the plugin's settings definition Custom branding: centralize the plugin's settings Sep 14, 2022
@Desvelao
Copy link
Member Author

Desvelao commented Sep 16, 2022

Due to a requirement for a new feature, it is required to refactor the form and input components, so their state is controlled in the form parent component.

Tasks:

  • Refactor the form
  • Create new hooks to manage the form state
  • Refactor the input components to delegate their state to the parent controller.

@Desvelao
Copy link
Member Author

Desvelao commented Sep 21, 2022

Added tests for:

  • useForm hook.
  • default configuration file.
  • InputForm component.

@vikman90 vikman90 added this to the Release 4.4.0 milestone Sep 26, 2022
@asteriscos asteriscos self-assigned this Sep 28, 2022
@AlexRuiz7 AlexRuiz7 moved this from In Progress to On Hold in Release 4.4.0 Sep 29, 2022
@AlexRuiz7 AlexRuiz7 moved this from On Hold to In Review in Release 4.4.0 Oct 11, 2022
Repository owner moved this from In Review to Done in Release 4.4.0 Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Enhancement issue
Projects
No open projects
Status: Done
4 participants