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

Added file saving conditions in File Editor #4970

Merged
merged 3 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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:/wazuh/wazuh-kibana-app/pull/4833)
- Added a centralized service to handle the requests [#4831](https:/wazuh/wazuh-kibana-app/pull/4831)
- Added data-test-subj create policy [#4873](https:/wazuh/wazuh-kibana-app/pull/4873)
- Added file saving conditions in File Editor [#4970](https:/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