-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove agent AngularJS controller (#6618)
* Create AgentView component to replace controller * Replace Kibana visualization * Improve Events count evolution chart * Fix Dashboard embeddable * Fix url update when change tab * Move file export-configuration * Fix imports to move file export-configuration * Delete agents angularjs controller * Get agent on change tab * Update CHANGELOG * Remove unused VisFactoryHandler * Improve code and remove unused code --------- Co-authored-by: Federico Rodriguez <[email protected]>
- Loading branch information
1 parent
98c64df
commit aee0268
Showing
18 changed files
with
700 additions
and
1,370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
plugins/main/public/components/agents/export-configuration.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* Wazuh app - React component for exporting the configuration of a group. | ||
* Copyright (C) 2015-2022 Wazuh, Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Find more information about this on the LICENSE file. | ||
*/ | ||
import React, { Component } from 'react'; | ||
|
||
import { | ||
EuiPopover, | ||
EuiButton, | ||
EuiCheckboxGroup, | ||
EuiSpacer, | ||
EuiButtonEmpty, | ||
} from '@elastic/eui'; | ||
|
||
import PropTypes from 'prop-types'; | ||
import { UnsupportedComponents } from '../../utils/components-os-support'; | ||
import { WAZUH_AGENTS_OS_TYPE } from '../../../common/constants'; | ||
import { withErrorBoundary } from '../common/hocs'; | ||
|
||
export const ExportConfiguration = withErrorBoundary( | ||
class ExportConfiguration extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
buttonDisabled: false, | ||
isPopoverOpen: false, | ||
}; | ||
|
||
const agentOptions = [ | ||
'Global configuration', | ||
'Communication', | ||
'Anti-flooding settings', | ||
'Labels', | ||
'Policy monitoring', | ||
{ name: 'oscap', desc: 'OpenSCAP' }, | ||
'CIS-CAT', | ||
'Osquery', | ||
'Inventory data', | ||
'Active response', | ||
'Commands', | ||
{ name: 'docker', desc: 'Docker listener' }, | ||
'Log collection', | ||
'Integrity monitoring', | ||
]; | ||
const groupOptions = ['Configurations', 'Agents in group']; | ||
|
||
this.options = []; | ||
const list = this.props.type === 'agent' ? agentOptions : groupOptions; | ||
list.forEach((x, idx) => { | ||
if ( | ||
typeof x === 'string' || | ||
(x.name && | ||
!( | ||
UnsupportedComponents[this.props.agentPlatform] || | ||
UnsupportedComponents[WAZUH_AGENTS_OS_TYPE.OTHERS] | ||
).includes(x.name)) | ||
) { | ||
this.options.push({ id: `${idx}`, label: x.desc || x }); | ||
} | ||
}); | ||
|
||
let initialChecks = {}; | ||
this.options.forEach(x => { | ||
initialChecks[x.id] = true; | ||
}); | ||
this.state.checkboxIdToSelectedMap = initialChecks; | ||
} | ||
|
||
selectAll(flag) { | ||
let newCheckboxIdToSelectedMap = {}; | ||
for (let i = 0; i < this.options.length; i++) { | ||
newCheckboxIdToSelectedMap[`${this.options[i].id}`] = flag; | ||
} | ||
this.setState({ | ||
checkboxIdToSelectedMap: newCheckboxIdToSelectedMap, | ||
buttonDisabled: !flag, | ||
}); | ||
} | ||
|
||
exportClick() { | ||
this.setState({ | ||
isPopoverOpen: !this.state.isPopoverOpen, | ||
}); | ||
} | ||
|
||
closePopover() { | ||
this.setState({ | ||
isPopoverOpen: false, | ||
}); | ||
} | ||
|
||
onChange = optionId => { | ||
const newCheckboxIdToSelectedMap = { | ||
...this.state.checkboxIdToSelectedMap, | ||
...{ | ||
[optionId]: !this.state.checkboxIdToSelectedMap[optionId], | ||
}, | ||
}; | ||
let result = false; | ||
for (let i = 0; i < this.options.length; i++) { | ||
if (newCheckboxIdToSelectedMap[`${this.options[i].id}`] === true) { | ||
result = true; | ||
} | ||
} | ||
this.setState({ | ||
checkboxIdToSelectedMap: newCheckboxIdToSelectedMap, | ||
buttonDisabled: !result, | ||
}); | ||
}; | ||
|
||
render() { | ||
const button = ( | ||
<EuiButtonEmpty | ||
iconType='importAction' | ||
iconSide='left' | ||
size='s' | ||
style={{ marginTop: '4px' }} | ||
onClick={this.exportClick.bind(this)} | ||
> | ||
Export PDF | ||
</EuiButtonEmpty> | ||
); | ||
return ( | ||
<EuiPopover | ||
id='trapFocus' | ||
ownFocus | ||
button={button} | ||
isOpen={this.state.isPopoverOpen} | ||
closePopover={this.closePopover.bind(this)} | ||
anchorPosition='downRight' | ||
> | ||
<EuiCheckboxGroup | ||
options={this.options} | ||
idToSelectedMap={this.state.checkboxIdToSelectedMap} | ||
onChange={this.onChange} | ||
compressed | ||
/> | ||
<EuiSpacer size='s' /> | ||
{this.options.length > 3 && ( | ||
<> | ||
<EuiButtonEmpty size='xs' onClick={() => this.selectAll(true)}> | ||
Select all | ||
</EuiButtonEmpty> | ||
<EuiSpacer size='s' /> | ||
<EuiButtonEmpty size='xs' onClick={() => this.selectAll(false)}> | ||
Unselect all | ||
</EuiButtonEmpty> | ||
</> | ||
)} | ||
<EuiSpacer size='m' /> | ||
<EuiButton | ||
isDisabled={this.state.buttonDisabled} | ||
onClick={() => { | ||
this.closePopover(); | ||
this.props.exportConfiguration( | ||
this.state.checkboxIdToSelectedMap, | ||
); | ||
}} | ||
fill | ||
> | ||
Generate PDF report | ||
</EuiButton> | ||
</EuiPopover> | ||
); | ||
} | ||
}, | ||
); | ||
|
||
ExportConfiguration.propTypes = { | ||
exportConfiguration: PropTypes.func, | ||
type: PropTypes.string, | ||
agentPlatform: PropTypes.string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.