diff --git a/CHANGELOG.md b/CHANGELOG.md index acff45fbfe..d9cb53a750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,12 +10,13 @@ All notable changes to the Wazuh app project will be documented in this file. - Added AngularJS dependencies [#6145](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6145) - Added a migration task to setup the configuration using a configuration file [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) - Added the ability to manage the API hosts from the Server APIs [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) [#6519](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6519) -- Added edit agent groups and upgrade agents actions to Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) [#6476](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6476) [#6274](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6274) [#6501](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6501) +- Improve fleet management by adding 'Edit Agent Groups' and 'Upgrade Agents' actions, as well as a filter to show only outdated agents [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) [#6476](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6476) [#6274](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6274) [#6501](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6501) [#6529](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6529) - Added propagation of updates from the table to dashboard visualizations in Endpoints summary [#6460](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6460) +- Handle index pattern selector on new discover [#6499](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6499) ### Changed -- Removed embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) [#6235](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6235) [#6254](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6254) [#6285](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6285) [#6288](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6288) [#6290](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6290) [#6289](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6289) [#6286](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6286) [#6275](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6275) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6297](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6297) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6291](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6459](https://github.com/wazuh/wazuh-dashboard-plugins/pull/#6459) +- Removed embedded discover [#6120](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6120) [#6235](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6235) [#6254](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6254) [#6285](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6285) [#6288](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6288) [#6290](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6290) [#6289](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6289) [#6286](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6286) [#6275](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6275) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6297](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6297) [#6287](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6291](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6287) [#6459](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6459) [#6434](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6434) - Develop logic of a new index for the fim module [#6227](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6227) - Allow editing groups for an agent from Endpoints Summary [#6250](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6250) - Changed as the configuration is defined and stored [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) @@ -23,6 +24,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Changed the usage of the endpoint GET /groups/{group_id}/files/{file_name} [#6385](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6385) - Refactoring and redesign endpoints summary visualizations [#6268](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6268) - Move the AngularJS controller and template of blank screen to ReactJS component [#6538](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6538) +- Remove AngularJS controller for manage groups [#6543](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6543) ### Fixed diff --git a/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap b/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap index 665925c7d8..df26ef4255 100644 --- a/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap +++ b/plugins/main/public/components/agents/syscollector/__snapshots__/inventory.test.tsx.snap @@ -141,7 +141,7 @@ exports[`Inventory component A Apple agent should be well rendered. 1`] = ` class="euiFlexItem" >
{ +const WzButtons: { [key in WzButtonType]: React.FunctionComponent } = { + default: EuiButton, + empty: EuiButtonEmpty, + icon: EuiButtonIcon, + link: EuiLink, + switch: EuiSwitch, +}; + +export const WzButton = ({ + buttonType = WzButtonType.default, + tooltip, + ...rest +}: WzButtonProps) => { const Button = WzButtons[buttonType]; - - const button = + + Show only outdated + +
+ +
+
+
@@ -368,7 +447,7 @@ exports[`AgentsTable component Renders correctly to match the snapshot 1`] = `
+
+
+
+ +
+ + + Show only outdated + +
+
+
+
+
@@ -1030,7 +1189,7 @@ exports[`AgentsTable component Renders correctly to match the snapshot with cust
+
+
+
+ +
+ + + Show only outdated + +
+
+
+
+
@@ -1644,7 +1883,7 @@ exports[`AgentsTable component Renders correctly to match the snapshot with no p
({ appStateReducers: state => state, })); +jest.mock( + '../../../../../../node_modules/@elastic/eui/lib/services/accessibility/html_id_generator', + () => ({ + htmlIdGenerator: () => () => 'htmlId', + }), +); + const permissionsStore = { appStateReducers: { userAccount: { @@ -336,32 +343,13 @@ describe('AgentsTable component', () => { jest.fn()} - wzReq={WzRequest.apiReq} - addingNewAgent={() => jest.fn()} - downloadCsv={() => jest.fn()} - clickAction={() => jest.fn()} - formatUIDate={date => jest.fn()} - reload={() => jest.fn()} + showOnlyOutdated={false} + setShowOnlyOutdated={() => jest.fn()} + totalOutdated={0} /> , ); - // Set table id to avoid snapshot changes - const tableId = '__table_d203a723-1198-11ee-ab9b-75fc624fc672'; - wrapper.find('table')[0]['attribs']['id'] = tableId; - - // Set select all checkbox id to avoid snapshot changes - const checkBoxSelectId = - '_selection_column-checkbox_i6bf14741-d0fa-11ee-81c4-29d002524ab5'; - - //Mobile - wrapper.find('.euiCheckbox__input')[0]['attribs']['id'] = checkBoxSelectId; - wrapper.find('.euiCheckbox__label')[0]['attribs']['for'] = checkBoxSelectId; - - //Desktop - wrapper.find('.euiCheckbox__input')[1]['attribs']['id'] = checkBoxSelectId; - expect(wrapper).toMatchSnapshot(); expect( window.localStorage.getItem('wz-agents-overview-table-visible-fields'), @@ -373,32 +361,13 @@ describe('AgentsTable component', () => { jest.fn()} - wzReq={WzRequest.apiReq} - addingNewAgent={() => jest.fn()} - downloadCsv={() => jest.fn()} - clickAction={() => jest.fn()} - formatUIDate={date => jest.fn()} - reload={() => jest.fn()} + showOnlyOutdated={false} + setShowOnlyOutdated={() => jest.fn()} + totalOutdated={0} /> , ); - // Set table id to avoid snapshot changes - const tableId = '__table_d203a723-1198-11ee-ab9b-75fc624fc672'; - wrapper.find('table')[0]['attribs']['id'] = tableId; - - // Set select all checkbox id to avoid snapshot changes - const checkBoxSelectId = - '_selection_column-checkbox_i6bf14741-d0fa-11ee-81c4-29d002524ab5'; - - //Mobile - wrapper.find('.euiCheckbox__input')[0]['attribs']['id'] = checkBoxSelectId; - wrapper.find('.euiCheckbox__label')[0]['attribs']['for'] = checkBoxSelectId; - - //Desktop - wrapper.find('.euiCheckbox__input')[1]['attribs']['id'] = checkBoxSelectId; - expect(wrapper).toMatchSnapshot(); expect( window.localStorage.getItem('wz-agents-overview-table-visible-fields'), @@ -414,32 +383,13 @@ describe('AgentsTable component', () => { jest.fn()} - wzReq={WzRequest.apiReq} - addingNewAgent={() => jest.fn()} - downloadCsv={() => jest.fn()} - clickAction={() => jest.fn()} - formatUIDate={date => jest.fn()} - reload={() => jest.fn()} + showOnlyOutdated={false} + setShowOnlyOutdated={() => jest.fn()} + totalOutdated={0} /> , ); - // Set table id to avoid snapshot changes - const tableId = '__table_d203a723-1198-11ee-ab9b-75fc624fc672'; - wrapper.find('table')[0]['attribs']['id'] = tableId; - - // Set select all checkbox id to avoid snapshot changes - const checkBoxSelectId = - '_selection_column-checkbox_i6bf14741-d0fa-11ee-81c4-29d002524ab5'; - - //Mobile - wrapper.find('.euiCheckbox__input')[0]['attribs']['id'] = checkBoxSelectId; - wrapper.find('.euiCheckbox__label')[0]['attribs']['for'] = checkBoxSelectId; - - //Desktop - wrapper.find('.euiCheckbox__input')[1]['attribs']['id'] = checkBoxSelectId; - expect(wrapper).toMatchSnapshot(); expect( window.localStorage.getItem('wz-agents-overview-table-visible-fields'), diff --git a/plugins/main/public/components/endpoints-summary/table/agents-table.tsx b/plugins/main/public/components/endpoints-summary/table/agents-table.tsx index e84419283a..fe97484304 100644 --- a/plugins/main/public/components/endpoints-summary/table/agents-table.tsx +++ b/plugins/main/public/components/endpoints-summary/table/agents-table.tsx @@ -18,6 +18,7 @@ import { EuiPanel, EuiCallOut, EuiButton, + EuiToolTip, } from '@elastic/eui'; import { WzButtonPermissions } from '../../common/permissions/button'; import { withErrorBoundary } from '../../common/hocs'; @@ -46,6 +47,7 @@ import { UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/ import { getErrorOrchestrator } from '../../../react-services/common-services'; import { AgentUpgradesInProgress } from './upgrades-in-progress/upgrades-in-progress'; import { AgentUpgradesTaskDetailsModal } from './upgrade-task-details-modal'; +import { WzButton } from '../../common/buttons'; const searchBarWQLOptions = { implicitQuery: { @@ -67,6 +69,9 @@ interface AgentsTableProps { filters: any; updateCurrentAgentData: (agent) => void; externalReload?: boolean; + showOnlyOutdated: boolean; + setShowOnlyOutdated: (newValue: boolean) => void; + totalOutdated?: number; setExternalReload?: (newValue: number) => void; } @@ -177,7 +182,9 @@ export const AgentsTable = compose( const agentIds = data?.items?.map(agent => agent.id); try { - const outdatedAgents = await getOutdatedAgents(agentIds); + const outdatedAgents = agentIds?.length + ? (await getOutdatedAgents({ agentIds })).affected_items + : []; setOutdatedAgents(outdatedAgents); } catch (error) { setOutdatedAgents([]); @@ -205,31 +212,49 @@ export const AgentsTable = compose( ? agentList.totalItems : selectedItems.length; - const selectedtemsRenderer = selectedItems.length ? ( - - - - - {showSelectAllItems ? ( + const selectedtemsRenderer = ( + + {selectedItems.length ? ( - - {!allAgentsSelected - ? `Select all ${agentList.totalItems} agents` - : `Clear ${agentList.totalItems} agents selected`} - + + + + + {showSelectAllItems ? ( + + + {!allAgentsSelected + ? `Select all ${agentList.totalItems} agents` + : `Clear ${agentList.totalItems} agents selected`} + + + ) : null} + ) : null} + + props.setShowOnlyOutdated(!props.showOnlyOutdated)} + /> + - ) : null; + ); const tableRender = () => { // The EuiBasicTable tableLayout is set to "auto" to improve the use of empty space in the component. @@ -250,7 +275,7 @@ export const AgentsTable = compose( allowGetTasks={!denyGetTasks} /> } - actionButtons={({ filters }) => ( + actionButtons={ - )} + } postActionButtons={({ filters }) => ( )} - endpoint='/agents' + endpoint={props.showOnlyOutdated ? '/agents/outdated' : '/agents'} tableColumns={agentsTableColumns( !denyEditGroups, !denyUpgrade, @@ -326,7 +351,7 @@ export const AgentsTable = compose( label: 'dateAdd', description: 'filter by registration date', }, - { label: 'id', description: 'filter by id' }, + { label: 'id', description: 'filter by ID' }, { label: 'ip', description: 'filter by IP address' }, { label: 'group', description: 'filter by group' }, { diff --git a/plugins/main/public/components/endpoints-summary/table/global-actions/edit-groups/result.tsx b/plugins/main/public/components/endpoints-summary/table/global-actions/edit-groups/result.tsx index 4058e70462..8d050e1595 100644 --- a/plugins/main/public/components/endpoints-summary/table/global-actions/edit-groups/result.tsx +++ b/plugins/main/public/components/endpoints-summary/table/global-actions/edit-groups/result.tsx @@ -52,7 +52,7 @@ export const EditAgentsGroupsModalResult = ({ sortable: true, }, ]} - pagination={agents.length > 10} + pagination={true} sorting={{ sort: { field: 'id', @@ -88,12 +88,12 @@ export const EditAgentsGroupsModalResult = ({ }, { field: 'id', - name: 'Agent Ids', + name: 'Agent IDs', align: 'left', render: ids => ids.join(', '), }, ]} - pagination={errors.length > 10} + pagination={true} /> ); diff --git a/plugins/main/public/components/endpoints-summary/table/global-actions/global-actions.tsx b/plugins/main/public/components/endpoints-summary/table/global-actions/global-actions.tsx index 78f4078758..4a0e1e89c5 100644 --- a/plugins/main/public/components/endpoints-summary/table/global-actions/global-actions.tsx +++ b/plugins/main/public/components/endpoints-summary/table/global-actions/global-actions.tsx @@ -5,6 +5,7 @@ import { EuiContextMenuPanel, EuiContextMenuItem, EuiHorizontalRule, + EuiToolTip, } from '@elastic/eui'; import { WzElementPermissions } from '../../../common/permissions/element'; import { Agent } from '../../types'; @@ -65,6 +66,18 @@ export const AgentsTableGlobalActions = ({ ? allAgentsCount : selectedAgents.length; + const selectAgentsTooltip = (content: React.ReactNode) => ( + + {content} + + ); + + const actions = { + addGroups: 'Add groups to agents', + removeGroups: 'Remove groups from agents', + upgrade: 'Upgrade agents', + }; + return ( <> - - - Add groups to agents - {totalAgents ? ` (${totalAgents})` : ''} - - + {allowEditGroups && !totalAgents ? ( + selectAgentsTooltip(actions.addGroups) + ) : ( + + + {actions.addGroups} + {totalAgents ? ` (${totalAgents})` : ''} + + + )} { setAddOrRemoveGroups('remove'); closePopover(); setIsEditGroupsVisible(true); }} > - - - Remove groups from agents - {totalAgents ? ` (${totalAgents})` : ''} - - + {allowEditGroups && !totalAgents ? ( + selectAgentsTooltip(actions.removeGroups) + ) : ( + + + {actions.removeGroups} + {totalAgents ? ` (${totalAgents})` : ''} + + + )} { closePopover(); setIsUpgradeAgentsVisible(true); }} > - - - Upgrade agents - {totalAgents ? ` (${totalAgents})` : ''} - - + {allowUpgrade && !totalAgents ? ( + selectAgentsTooltip(actions.upgrade) + ) : ( + + + {actions.upgrade} + {totalAgents ? ` (${totalAgents})` : ''} + + + )} 10} + pagination={true} sorting={{ sort: { field: 'id', @@ -72,7 +72,7 @@ export const UpgradeAgentsModalResult = ({ columns={[ { field: 'agent', - name: 'Agent id', + name: 'Agent ID', align: 'left', sortable: true, }, @@ -90,12 +90,12 @@ export const UpgradeAgentsModalResult = ({ }, { field: 'task_id', - name: 'task id', + name: 'Task ID', align: 'left', sortable: true, }, ]} - pagination={tasks.length > 10} + pagination={true} sorting={{ sort: { field: 'agent', @@ -131,12 +131,12 @@ export const UpgradeAgentsModalResult = ({ }, { field: 'id', - name: 'Agent Ids', + name: 'Agent IDs', align: 'left', render: ids => ids.join(', '), }, ]} - pagination={errors.length > 10} + pagination={true} /> ); diff --git a/plugins/main/public/components/endpoints-summary/table/upgrade-task-details-modal.tsx b/plugins/main/public/components/endpoints-summary/table/upgrade-task-details-modal.tsx index 2197da597f..63f16fd205 100644 --- a/plugins/main/public/components/endpoints-summary/table/upgrade-task-details-modal.tsx +++ b/plugins/main/public/components/endpoints-summary/table/upgrade-task-details-modal.tsx @@ -48,7 +48,7 @@ export const AgentUpgradesTaskDetailsModal = ({ tableColumns={[ { field: 'task_id', - name: 'Task id', + name: 'Task ID', sortable: true, searchable: true, show: true, @@ -56,7 +56,7 @@ export const AgentUpgradesTaskDetailsModal = ({ }, { field: 'agent_id', - name: 'Agent id', + name: 'Agent ID', sortable: true, searchable: true, show: true, @@ -151,7 +151,7 @@ export const AgentUpgradesTaskDetailsModal = ({ return [ { label: 'agent_id', - description: 'filter by agent id', + description: 'filter by agent ID', }, { label: 'status', description: 'filter by status' }, { @@ -162,7 +162,7 @@ export const AgentUpgradesTaskDetailsModal = ({ label: 'last_update_time', description: 'filter by last update date', }, - { label: 'task_id', description: 'filter by task id' }, + { label: 'task_id', description: 'filter by task ID' }, ]; }, value: async (currentValue, { field }) => { diff --git a/plugins/main/public/components/overview/mitre_attack_intelligence/__snapshots__/intelligence.test.tsx.snap b/plugins/main/public/components/overview/mitre_attack_intelligence/__snapshots__/intelligence.test.tsx.snap index 718fee7b6a..84909f720c 100644 --- a/plugins/main/public/components/overview/mitre_attack_intelligence/__snapshots__/intelligence.test.tsx.snap +++ b/plugins/main/public/components/overview/mitre_attack_intelligence/__snapshots__/intelligence.test.tsx.snap @@ -161,7 +161,7 @@ exports[`Module Mitre Att&ck intelligence container should render the component class="euiFlexItem" >
{ - try { - const newPattern = event.target; - if (!AppState.getPatternSelector()) return; - await PatternHandler.changePattern(newPattern.value); - this.setState({ currentSelectedPattern: newPattern.value }); - if (this.state.currentMenuTab !== 'wazuh-dev') { - this.router.reload(); - } - - if (newPattern?.id === 'selectIndexPatternBar') { - this.updatePatternAndApi(); - } - } catch (error) { - const options = { - context: `${WzMenu.name}.changePattern`, - level: UI_LOGGER_LEVELS.ERROR, - severity: UI_ERROR_SEVERITIES.BUSINESS, - store: false, - display: true, - error: { - error: error, - message: error.message || error, - title: `Error changing the Index Pattern`, - }, - }; - getErrorOrchestrator().handleError(options); - } - }; - updatePatternAndApi = async () => { this.setState({ menuOpened: false, @@ -429,38 +405,6 @@ export const WzMenu = withWindowSize( } }; - buildPatternSelector() { - return ( - - { - return { value: item.id, text: item.title }; - })} - value={this.state.currentSelectedPattern} - onChange={this.changePattern} - aria-label='Index pattern selector' - /> - - ); - } - - buildApiSelector() { - return ( - - { - return { value: item.id, text: item.id }; - })} - value={this.state.currentAPI} - onChange={this.changeAPI} - aria-label='API selector' - /> - - ); - } - buildWazuhNotReadyYet() { const container = document.getElementsByClassName('wazuhNotReadyYet'); return ReactDOM.createPortal( @@ -517,20 +461,6 @@ export const WzMenu = withWindowSize( }); } - thereAreSelectors() { - return ( - (AppState.getAPISelector() && - this.state.currentAPI && - this.state.APIlist && - this.state.APIlist.length > 1) || - !this.state.currentAPI || - (AppState.getPatternSelector() && - this.state.theresPattern && - this.state.patternList && - this.state.patternList.length > 1) - ); - } - getApiSelectorComponent() { let style = { minWidth: 100, textOverflow: 'ellipsis' }; if (this.showSelectorsInPopover) { @@ -560,6 +490,30 @@ export const WzMenu = withWindowSize( ); } + onChangePattern = async pattern => { + try { + this.setState({ currentSelectedPattern: pattern.id }); + if (this.state.currentMenuTab !== 'wazuh-dev') { + this.router.reload(); + } + await this.updatePatternAndApi(); + } catch (error) { + const options = { + context: `${WzMenu.name}.onChangePattern`, + level: UI_LOGGER_LEVELS.ERROR, + severity: UI_ERROR_SEVERITIES.BUSINESS, + store: false, + display: true, + error: { + error: error, + message: error.message || error, + title: `Error changing the Index Pattern`, + }, + }; + getErrorOrchestrator().handleError(options); + } + }; + getIndexPatternSelectorComponent() { let style = { maxWidth: 200, maxHeight: 50 }; if (this.showSelectorsInPopover) { @@ -571,19 +525,12 @@ export const WzMenu = withWindowSize(

Index pattern

-
- { - return { value: item.id, text: item.title }; - })} - value={this.state.currentSelectedPattern} - onChange={this.changePattern} - aria-label='Index pattern selector' - /> +
diff --git a/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap b/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap index 2923c94f31..792a26b3e0 100644 --- a/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap +++ b/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap @@ -33,23 +33,6 @@ exports[`Group main component renders correctly to match the snapshot 1`] = ` }, } } - groupsProps={ - Object { - "closeAddingAgents": false, - "exportConfigurationProps": Object { - "type": "group", - }, - "items": Array [ - Object { - "configSum": "ab73af41699f13fdd81903b5f23d8d00", - "count": 1, - "mergedSum": "2c45c95db2954d2c7d0ea533f09e81a5", - "name": "default", - }, - ], - "selectedGroup": false, - } - } logtestProps={ Object { "onFlyout": true, diff --git a/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js b/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js index 39e04635a5..fa3ffc0a7d 100644 --- a/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js +++ b/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js @@ -15,9 +15,7 @@ import { EuiFlexItem, EuiButtonEmpty } from '@elastic/eui'; import { connect } from 'react-redux'; -import { - updateShowAddAgents, -} from '../../../../../redux/actions/groupsActions'; +import { updateShowAddAgents } from '../../../../../redux/actions/groupsActions'; import GroupsHandler from './utils/groups-handler'; import { ExportConfiguration } from '../../../../agent/components/export-configuration'; @@ -30,22 +28,21 @@ class WzGroupsActionButtonsAgents extends Component { super(props); this.reportingService = new ReportingService(); - this.groupsHandler = GroupsHandler; } - showManageAgents() { - const { itemDetail } = this.props.state; - - this.props.groupsProps.showAddingAgents(true, itemDetail); this.props.updateShowAddAgents(true); } render() { // Add new group button const manageAgentsButton = ( - this.showManageAgents()}> + this.showManageAgents()} + > Manage agents ); @@ -53,14 +50,14 @@ class WzGroupsActionButtonsAgents extends Component { // Export PDF button const exportPDFButton = ( + exportConfiguration={enabledComponents => this.reportingService.startConfigReport( this.props.state.itemDetail, 'groupConfig', - enabledComponents + enabledComponents, ) } - type="group" + type='group' /> ); @@ -73,16 +70,20 @@ class WzGroupsActionButtonsAgents extends Component { } } -const mapStateToProps = (state) => { +const mapStateToProps = state => { return { state: state.groupsReducers, }; }; -const mapDispatchToProps = (dispatch) => { +const mapDispatchToProps = dispatch => { return { - updateShowAddAgents: (showAddAgents) => dispatch(updateShowAddAgents(showAddAgents)), + updateShowAddAgents: showAddAgents => + dispatch(updateShowAddAgents(showAddAgents)), }; }; -export default connect(mapStateToProps, mapDispatchToProps)(WzGroupsActionButtonsAgents); +export default connect( + mapStateToProps, + mapDispatchToProps, +)(WzGroupsActionButtonsAgents); diff --git a/plugins/main/public/controllers/management/components/management/groups/groups-main.js b/plugins/main/public/controllers/management/components/management/groups/groups-main.js index 3898978ec3..83cf53c972 100644 --- a/plugins/main/public/controllers/management/components/management/groups/groups-main.js +++ b/plugins/main/public/controllers/management/components/management/groups/groups-main.js @@ -30,6 +30,7 @@ import { getErrorOrchestrator } from '../../../../../react-services/common-servi import { compose } from 'redux'; import { withGlobalBreadcrumb } from '../../../../../components/common/hocs'; import { endpointGroups } from '../../../../../utils/applications'; +import { MultipleAgentSelector } from '../../../../../components/management/groups/multiple-agent-selector'; class WzGroups extends Component { constructor(props) { @@ -71,29 +72,15 @@ class WzGroups extends Component { } UNSAFE_componentWillReceiveProps(nextProps) { - if ( - nextProps.groupsProps.closeAddingAgents && - this.props.state.showAddAgents - ) { + if (this.props.state.showAddAgents) { this.props.updateShowAddAgents(false); } - if ( - nextProps.groupsProps.selectedGroup && - nextProps.groupsProps.selectedGroup !== - this.props.groupsProps.selectedGroup - ) { - store.dispatch(updateGroupDetail(nextProps.groupsProps.selectedGroup)); - } } componentWillUnmount() { // When the component is going to be unmounted the groups state is reset this.props.resetGroup(); } - componentDidUpdate() { - if (this.props.groupsProps.selectedGroup) { - this.props.groupsProps.updateProps(); - } - } + render() { const { itemDetail, showAddAgents, fileContent } = this.props.state; return ( @@ -101,6 +88,12 @@ class WzGroups extends Component { {!showAddAgents && ((itemDetail && !fileContent && ) || (fileContent && ) || )} + {showAddAgents && itemDetail && ( + this.props.updateShowAddAgents(false)} + /> + )} ); } diff --git a/plugins/main/public/controllers/management/components/management/groups/groups-main.test.tsx b/plugins/main/public/controllers/management/components/management/groups/groups-main.test.tsx index 8b3d0009f6..ca0462bd50 100644 --- a/plugins/main/public/controllers/management/components/management/groups/groups-main.test.tsx +++ b/plugins/main/public/controllers/management/components/management/groups/groups-main.test.tsx @@ -28,21 +28,6 @@ jest.mock('../../../../../kibana-services', () => ({ const mockProps = { section: 'groups', - groupsProps: { - items: [ - { - name: 'default', - count: 1, - mergedSum: '2c45c95db2954d2c7d0ea533f09e81a5', - configSum: 'ab73af41699f13fdd81903b5f23d8d00', - }, - ], - closeAddingAgents: false, - exportConfigurationProps: { - type: 'group', - }, - selectedGroup: false, - }, configurationProps: { agent: { id: '000', diff --git a/plugins/main/public/controllers/management/groups.js b/plugins/main/public/controllers/management/groups.js deleted file mode 100644 index caf3bf29f1..0000000000 --- a/plugins/main/public/controllers/management/groups.js +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Wazuh app - Management groups controller - * 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 { WazuhConfig } from '../../react-services/wazuh-config'; -import { WzRequest } from '../../react-services/wz-request'; -import { ShareAgent } from '../../factories/share-agent'; -import { GroupHandler } from '../../react-services/group-handler'; -import { ErrorHandler } from '../../react-services/error-handler'; -import { ReportingService } from '../../react-services/reporting'; - -export class GroupsController { - constructor($scope, $location, errorHandler) { - this.scope = $scope; - this.location = $location; - this.errorHandler = errorHandler; - this.shareAgent = new ShareAgent(); - this.groupHandler = GroupHandler; - this.wazuhConfig = new WazuhConfig(); - this.reportingService = new ReportingService(); - } - - async $onInit() { - try { - this.mctrl = this.scope.mctrl; - this.addingGroup = false; - this.load = false; - await this.loadGroups(); - - // Listeners - - // Resetting the factory configuration - this.scope.$on('$destroy', () => {}); - - this.scope.$watch('lookingGroup', value => { - this.addingAgents = false; - if (!value) { - this.file = false; - this.filename = false; - } - }); - - // Props - this.exportConfigurationProps = { - exportConfiguration: enabledComponents => - this.exportConfiguration(enabledComponents), - type: 'group', - }; - - this.filesInGroupTableProps = { - exportConfigurationProps: this.exportConfigurationProps, - }; - - return; - } catch (error) { - ErrorHandler.handle(error, 'Groups'); - } - } - - /** - * Loads the initial information - */ - async loadGroups() { - try { - // If come from agents - // Store a boolean variable to check if come from agents - this.globalAgent = this.shareAgent.getAgent(); - if (this.globalAgent || this.location.search()?.group) { - const globalGroup = - this.shareAgent.getSelectedGroup() || this.location.search().group; - // Get ALL groups - const data = await WzRequest.apiReq('GET', '/groups', {}); - const filtered = data.data.data.affected_items.filter( - group => group.name === globalGroup, - ); - if (Array.isArray(filtered) && filtered.length) { - // Load that our group - this.buildGroupsTableProps(data.data.data.items, { - group: filtered[0], - }); - } else { - throw Error(`Group ${globalGroup} not found`); - } - - this.shareAgent.deleteAgent(); - } else { - const loadedGroups = await WzRequest.apiReq('GET', '/groups', {}); - this.buildGroupsTableProps(loadedGroups.data.data.affected_items); - this.load = false; - } - this.scope.$applyAsync(); - } catch (error) { - return Promise.reject(error); - } - } - - toggle() { - this.lookingGroup = true; - } - - /** - * This navigate to a selected agent - * @param {Number} agentId - */ - showAgent(agent) { - this.shareAgent.setAgent(agent); - this.location.search('tab', null); - this.location.path('/agents'); - this.scope.$applyAsync(); - } - - /** - * - * @param {Object} enabledComponents - */ - exportConfiguration(enabledComponents, group) { - this.reportingService.startConfigReport( - group, - 'groupConfig', - enabledComponents, - ); - } - - async cancelButton() { - this.mctrl.managementProps.groupsProps.closeAddingAgents = true; - this.addingAgents = false; - } - - switchAddingGroup() { - this.addingGroup = !this.addingGroup; - } - - buildGroupsTableProps(items, params = {}) { - this.redirectGroup = params.group || false; - this.groupsTableProps = { - items, - closeAddingAgents: false, - showAddingAgents: (status, group) => { - this.showAddingAgents(status, group); - }, - exportConfigurationProps: { - exportConfiguration: (enabledComponents, group) => - this.exportConfiguration(enabledComponents, group), - type: 'group', - }, - currentGroup: group => { - this.currentGroup = group; - }, - updateProps: () => { - this.loadGroups(); - }, - showAgent: agent => { - this.showAgent(agent); - }, - selectedGroup: this.redirectGroup, - }; - this.mctrl.managementProps.groupsProps = this.groupsTableProps; - } - - async showAddingAgents(status, group) { - this.load = true; - this.mctrl.managementProps.groupsProps.closeAddingAgents = false; - this.currentGroup = group; - this.lookingGroup = true; - this.addingAgents = status; - this.load = false; - this.multipleAgentSelectorProps = { - currentGroup: this.currentGroup, - cancelButton: () => this.cancelButton(), - }; - this.scope.$applyAsync(); - } -} diff --git a/plugins/main/public/controllers/management/index.js b/plugins/main/public/controllers/management/index.js index 6ed7e0517c..f879da31d1 100644 --- a/plugins/main/public/controllers/management/index.js +++ b/plugins/main/public/controllers/management/index.js @@ -10,7 +10,6 @@ * Find more information about this on the LICENSE file. */ -import { GroupsController } from './groups'; import { ManagementController } from './management'; import { ClusterController } from './monitoring'; import WzManagement from './components/management/management-provider'; @@ -24,7 +23,6 @@ WzManagementConfiguration.displayName = 'WzManagementConfiguration'; app .controller('managementController', ManagementController) - .controller('groupsPreviewController', GroupsController) .controller('clusterController', ClusterController) .value('WzManagement', WzManagement) .value('WzManagementConfiguration', WzManagementConfiguration); diff --git a/plugins/main/public/controllers/overview/components/overview-actions/agents-selection-table.js b/plugins/main/public/controllers/overview/components/overview-actions/agents-selection-table.js index 083782f380..149eae7f1b 100644 --- a/plugins/main/public/controllers/overview/components/overview-actions/agents-selection-table.js +++ b/plugins/main/public/controllers/overview/components/overview-actions/agents-selection-table.js @@ -186,7 +186,7 @@ export class AgentSelectionTable extends Component { {/* agent name (agent id) Unpin button right aligned, require justifyContent="flexEnd" in the EuiFlexGroup */} - + >
- -
- -
- -
-
-