Skip to content

Commit

Permalink
Added file saving conditions in File Editor (#4970)
Browse files Browse the repository at this point in the history
* Added Rule editor validation

* Updated CHANGELOG

Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit ec10fc7)
  • Loading branch information
Machi3mfl authored and github-actions[bot] committed Dec 15, 2022
1 parent 14224c2 commit 5ddb52b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added powerPC architecture in redhat7, in the section 'Deploy new agent'. [4833](https://github.com/wazuh/wazuh-kibana-app/pull/4833)
- Added a centralized service to handle the requests [#4831](https://github.com/wazuh/wazuh-kibana-app/pull/4831)
- Added data-test-subj create policy [#4873](https://github.com/wazuh/wazuh-kibana-app/pull/4873)
- Added file saving conditions in File Editor [#4970](https://github.com/wazuh/wazuh-kibana-app/pull/4970)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ class WzFileEditor extends Component {
this._isMounted = true;
}

/**
* Check if the file content has changed and is not empty
*/
contentHasChanged() {
return !!this.state.content.trim() && (this.state.content.trim() !== this.state.initContent.trim());
}

/**
* Save the new content
Expand Down Expand Up @@ -129,7 +135,7 @@ class WzFileEditor extends Component {

let toastMessage;

if (this.props.state.addingFile != false) {
if (this.props.addingFile != false) {
//remove current invalid file if the file is new.
await this.resourcesHandler.deleteFile(name);
toastMessage = 'The new file was deleted.';
Expand Down Expand Up @@ -243,7 +249,7 @@ class WzFileEditor extends Component {
fill
iconType={isEditable && xmlError ? 'alert' : 'save'}
isLoading={this.state.isSaving}
isDisabled={nameForSaving.length <= 4 || !!(isEditable && xmlError)}
isDisabled={nameForSaving.length <= 4 || !!(isEditable && xmlError) || !this.contentHasChanged()}
onClick={() => this.save(nameForSaving, overwrite)}
>
{isEditable && xmlError ? 'XML format error' : 'Save'}
Expand Down

0 comments on commit 5ddb52b

Please sign in to comment.