Skip to content

Commit

Permalink
Remove groups autoformat (#6999)
Browse files Browse the repository at this point in the history
* Remove groups autoformat

* Add changelog
  • Loading branch information
asteriscos authored Sep 19, 2024
1 parent 59c8784 commit 2373b8c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 192 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ All notable changes to the Wazuh app project will be documented in this file.
- Upgraded the `follow-redirects` dependency to `1.15.6` [#6982](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6982)
- Changed many loading spinners in some views to loading search progress [#6956](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6956)

### Removed

- Removed the XML autoformat function group configuration due to performance [#6999](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6999)

## Wazuh v4.9.0 - OpenSearch Dashboards 2.13.0 - Revision 07

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,69 +31,6 @@ class WzGroupsActionButtonsFiles extends Component {
this.refreshTimeoutId = null;
}

autoFormat = xml => {
var reg = /(>)\s*(<)(\/*)/g;
var wsexp = / *(.*) +\n/g;
var contexp = /(<.+>)(.+\n)/g;
xml = xml
.replace(reg, '$1\n$2$3')
.replace(wsexp, '$1\n')
.replace(contexp, '$1\n$2');
var formatted = '';
var lines = xml.split('\n');
var indent = 0;
var lastType = 'other';
var transitions = {
'single->single': 0,
'single->closing': -1,
'single->opening': 0,
'single->other': 0,
'closing->single': 0,
'closing->closing': -1,
'closing->opening': 0,
'closing->other': 0,
'opening->single': 1,
'opening->closing': 0,
'opening->opening': 1,
'opening->other': 1,
'other->single': 0,
'other->closing': -1,
'other->opening': 0,
'other->other': 0,
};

for (var i = 0; i < lines.length; i++) {
var ln = lines[i];
if (ln.match(/\s*<\?xml/)) {
formatted += ln + '\n';
continue;
}
var single = Boolean(ln.match(/<.+\/>/)); // is this line a single tag? ex. <br />
var closing = Boolean(ln.match(/<\/.+>/)); // is this a closing tag? ex. </a>
var opening = Boolean(ln.match(/<[^!].*>/)); // is this even a tag (that's not <!something>)
var type = single
? 'single'
: closing
? 'closing'
: opening
? 'opening'
: 'other';
var fromTo = lastType + '->' + type;
lastType = type;
var padding = '';

indent += transitions[fromTo];
for (var j = 0; j < indent; j++) {
padding += '\t';
}
if (fromTo == 'opening->closing')
formatted = formatted.substr(0, formatted.length - 1) + ln + '\n';
// substr removes line break (\n) from prev loop
else formatted += padding + ln + '\n';
}
return formatted.trim();
};

async showGroupConfiguration() {
const { itemDetail } = this.props.state;
let result = await this.groupsHandler.getFileContent(
Expand All @@ -104,7 +41,7 @@ class WzGroupsActionButtonsFiles extends Component {
result = '';
}

const data = this.autoFormat(result);
const data = result?.toString();

const file = {
name: 'agent.conf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,76 +173,13 @@ export class WzGroupsOverview extends Component {

const file = {
name: 'agent.conf',
content: this.autoFormat(result),
content: result?.toString(),
isEditable: true,
groupName: groupId,
};
this.props.updateFileContent(file);
}

autoFormat = xml => {
var reg = /(>)\s*(<)(\/*)/g;
var wsexp = / *(.*) +\n/g;
var contexp = /(<.+>)(.+\n)/g;
xml = xml
.replace(reg, '$1\n$2$3')
.replace(wsexp, '$1\n')
.replace(contexp, '$1\n$2');
var formatted = '';
var lines = xml.split('\n');
var indent = 0;
var lastType = 'other';
var transitions = {
'single->single': 0,
'single->closing': -1,
'single->opening': 0,
'single->other': 0,
'closing->single': 0,
'closing->closing': -1,
'closing->opening': 0,
'closing->other': 0,
'opening->single': 1,
'opening->closing': 0,
'opening->opening': 1,
'opening->other': 1,
'other->single': 0,
'other->closing': -1,
'other->opening': 0,
'other->other': 0,
};

for (var i = 0; i < lines.length; i++) {
var ln = lines[i];
if (ln.match(/\s*<\?xml/)) {
formatted += ln + '\n';
continue;
}
var single = Boolean(ln.match(/<.+\/>/)); // is this line a single tag? ex. <br />
var closing = Boolean(ln.match(/<\/.+>/)); // is this a closing tag? ex. </a>
var opening = Boolean(ln.match(/<[^!].*>/)); // is this even a tag (that's not <!something>)
var type = single
? 'single'
: closing
? 'closing'
: opening
? 'opening'
: 'other';
var fromTo = lastType + '->' + type;
lastType = type;
var padding = '';

indent += transitions[fromTo];
for (var j = 0; j < indent; j++) {
padding += '\t';
}
if (fromTo == 'opening->closing')
formatted = formatted.substr(0, formatted.length - 1) + ln + '\n';
// substr removes line break (\n) from prev loop
else formatted += padding + ln + '\n';
}
return formatted.trim();
};

render() {
const actionButtons = [
<WzGroupsActionButtons reloadTable={this.reloadTable} />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class GroupsFilesColumns {
}

const data = edit
? this.autoFormat(result)
? result?.toString()
: typeof result === 'object'
? JSON.stringify(result, null, 2)
: result.toString();
Expand Down Expand Up @@ -94,67 +94,4 @@ export default class GroupsFilesColumns {

this.buildColumns();
}

autoFormat = xml => {
var reg = /(>)\s*(<)(\/*)/g;
var wsexp = / *(.*) +\n/g;
var contexp = /(<.+>)(.+\n)/g;
xml = xml
.replace(reg, '$1\n$2$3')
.replace(wsexp, '$1\n')
.replace(contexp, '$1\n$2');
var formatted = '';
var lines = xml.split('\n');
var indent = 0;
var lastType = 'other';
var transitions = {
'single->single': 0,
'single->closing': -1,
'single->opening': 0,
'single->other': 0,
'closing->single': 0,
'closing->closing': -1,
'closing->opening': 0,
'closing->other': 0,
'opening->single': 1,
'opening->closing': 0,
'opening->opening': 1,
'opening->other': 1,
'other->single': 0,
'other->closing': -1,
'other->opening': 0,
'other->other': 0,
};

for (var i = 0; i < lines.length; i++) {
var ln = lines[i];
if (ln.match(/\s*<\?xml/)) {
formatted += ln + '\n';
continue;
}
var single = Boolean(ln.match(/<.+\/>/)); // is this line a single tag? ex. <br />
var closing = Boolean(ln.match(/<\/.+>/)); // is this a closing tag? ex. </a>
var opening = Boolean(ln.match(/<[^!].*>/)); // is this even a tag (that's not <!something>)
var type = single
? 'single'
: closing
? 'closing'
: opening
? 'opening'
: 'other';
var fromTo = lastType + '->' + type;
lastType = type;
var padding = '';

indent += transitions[fromTo];
for (var j = 0; j < indent; j++) {
padding += '\t';
}
if (fromTo == 'opening->closing')
formatted = formatted.substr(0, formatted.length - 1) + ln + '\n';
// substr removes line break (\n) from prev loop
else formatted += padding + ln + '\n';
}
return formatted.trim();
};
}

0 comments on commit 2373b8c

Please sign in to comment.