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

[Backport 4.4-2.3-wzd] Add multi-line validation parameters in config description #4797

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added agent synchronization status in the agent module. [#3874](https://github.com/wazuh/wazuh-kibana-app/pull/3874)
- Redesign the SCA table from agent's dashboard [#4512](https://github.com/wazuh/wazuh-kibana-app/pull/4512)
- Enhanced the plugin setting description displayed in the UI and the configuration file. [#4501](https://github.com/wazuh/wazuh-kibana-app/pull/4501)
- Added validation to the plugin settings in the form of `Settings/Configuration` and the endpoint to update the plugin configuration [#4503](https://github.com/wazuh/wazuh-kibana-app/pull/4503)
- Added validation to the plugin settings in the form of `Settings/Configuration` and the endpoint to update the plugin configuration [#4503](https://github.com/wazuh/wazuh-kibana-app/pull/4503)[#4785](https://github.com/wazuh/wazuh-kibana-app/pull/4785)
- Added new plugin settings to customize the header and footer on the PDF reports [#4505](https://github.com/wazuh/wazuh-kibana-app/pull/4505)
- Add a new plugin setting to enable or disable the customization [#4507](https://github.com/wazuh/wazuh-kibana-app/pull/4507)

Expand Down
13 changes: 7 additions & 6 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ export enum SettingCategory {
};

type TPluginSettingOptionsTextArea = {
rowsSize?: number
maxRows?: number
minRows?: number
maxLength?: number
};

Expand Down Expand Up @@ -1115,11 +1116,11 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
defaultValueIfNotSet: REPORTS_PAGE_FOOTER_TEXT,
isConfigurableFromFile: true,
isConfigurableFromUI: true,
options: { rowsSize: 2, maxLength: 30 },
options: { maxRows: 2, maxLength: 30 },
validate: function (value) {
return SettingsValidator.multipleLinesString({
max: this.options.rowsSize,
maxLength: this.options.maxLength
maxRows: this.options?.maxRows,
maxLength: this.options?.maxLength
})(value)
},
validateBackend: function (schema) {
Expand All @@ -1135,10 +1136,10 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
defaultValueIfNotSet: REPORTS_PAGE_HEADER_TEXT,
isConfigurableFromFile: true,
isConfigurableFromUI: true,
options: { rowsSize: 3, maxLength: 20 },
options: { maxRows: 3, maxLength: 20 },
validate: function (value) {
return SettingsValidator.multipleLinesString({
max: this.options.rowsSize,
maxRows: this.options?.maxRows,
maxLength: this.options?.maxLength
})(value)
},
Expand Down
10 changes: 5 additions & 5 deletions common/services/settings-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ export class SettingsValidator {
* @param options
* @returns
*/
static multipleLinesString(options: { min?: number, max?: number, maxLength?: number } = {}) {
static multipleLinesString(options: { minRows?: number, maxRows?: number, maxLength?: number } = {}) {
return function (value: number) {
const lines = value.split(/\r\n|\r|\n/).length;
if (typeof options.maxLength !== 'undefined' && value.split('\n').some(line => line.length > options.maxLength)) {
return `The maximum length of a line is ${options.maxLength} characters.`;
};
if (typeof options.min !== 'undefined' && lines < options.min) {
return `The string should have more or ${options.min} line/s.`;
if (typeof options.minRows !== 'undefined' && lines < options.minRows) {
return `The string should have more or ${options.minRows} line/s.`;
};
if (typeof options.max !== 'undefined' && lines > options.max) {
return `The string should have less or equal to ${options.max} line/s.`;
if (typeof options.maxRows !== 'undefined' && lines > options.maxRows) {
return `The string should have less or equal to ${options.maxRows} line/s.`;
};
}
};
Expand Down
4 changes: 4 additions & 0 deletions common/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export function groupSettingsByCategory(settings: TPluginSettingWithKey[]){
// File size
...((options?.file?.size && typeof options.file.size.minBytes !== 'undefined') ? [`Minimum file size: ${formatBytes(options.file.size.minBytes)}.`] : []),
...((options?.file?.size && typeof options.file.size.maxBytes !== 'undefined') ? [`Maximum file size: ${formatBytes(options.file.size.maxBytes)}.`] : []),
// Multi line text
...((options?.maxRows && typeof options.maxRows !== 'undefined' ? [`Maximum amount of lines: ${options.maxRows}.`] : [])),
...((options?.minRows && typeof options.minRows !== 'undefined' ? [`Minimum amount of lines: ${options.minRows}.`] : [])),
...((options?.maxLength && typeof options.maxLength !== 'undefined' ? [`Maximum lines length is ${options.maxLength} characters.`] : [])),
].join(' ');
};

Expand Down