From 1a31bddcd214b6f7a10d41b709857b4e7a95d336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20David=20Guti=C3=A9rrez?= Date: Mon, 19 Jul 2021 13:25:52 +0200 Subject: [PATCH 1/6] feat(frontend_module_tab_buttons): Refactor as the module tab buttons and view are redered. - Moved view to each tab in tab for each module - Now each module tab defines its buttons to display in the header - Adapted custom tab components adding the `withAgentSupportModule` - Created and refactor the logic of `Loader` component to a HOC `withModuleTabLoader` - Removed `Settings` and `Loader` components duw to are not used - Removed not used imports --- public/components/agents/fim/main.tsx | 3 +- public/components/agents/sca/main.tsx | 3 +- public/components/agents/vuls/main.tsx | 3 +- public/components/common/hocs/index.ts | 1 + .../common/hocs/withAgentSupportModule.tsx | 14 ++- .../common/hocs/with_module_tab_loader.tsx | 42 +++++++ .../components/common/hooks/useRootScope.ts | 8 +- .../modules/buttons/generate_report.tsx | 63 ++++++++++ .../common/modules/buttons/index.ts | 13 ++ .../components/common/modules/dashboard.tsx | 13 +- public/components/common/modules/events.tsx | 9 +- public/components/common/modules/index.ts | 8 +- public/components/common/modules/loader.tsx | 53 -------- .../components/common/modules/main-agent.tsx | 82 ++----------- .../components/common/modules/main-mitre.tsx | 3 +- .../common/modules/main-overview.tsx | 74 +++--------- public/components/common/modules/main.tsx | 113 +----------------- .../common/modules/modules-defaults.js | 81 +++++++++---- public/components/common/modules/settings.tsx | 70 ----------- .../compliance-table/compliance-table.tsx | 6 +- .../overview-actions/overview-actions.js | 62 +++++----- 21 files changed, 278 insertions(+), 446 deletions(-) create mode 100644 public/components/common/hocs/with_module_tab_loader.tsx create mode 100644 public/components/common/modules/buttons/generate_report.tsx create mode 100644 public/components/common/modules/buttons/index.ts delete mode 100644 public/components/common/modules/loader.tsx delete mode 100644 public/components/common/modules/settings.tsx diff --git a/public/components/agents/fim/main.tsx b/public/components/agents/fim/main.tsx index 99c593a792..e5d5f339a3 100644 --- a/public/components/agents/fim/main.tsx +++ b/public/components/agents/fim/main.tsx @@ -4,13 +4,14 @@ import '../../common/modules/module.scss'; import { connect } from 'react-redux'; import { PromptNoActiveAgent, PromptNoSelectedAgent } from '../prompts'; import { compose } from 'redux'; -import { withGuard, withUserAuthorizationPrompt } from '../../common/hocs'; +import { withAgentSupportModule, withGuard, withUserAuthorizationPrompt } from '../../common/hocs'; const mapStateToProps = (state) => ({ currentAgentData: state.appStateReducers.currentAgentData, }); export const MainFim = compose( + withAgentSupportModule, connect(mapStateToProps), withGuard( (props) => !(props.currentAgentData && props.currentAgentData.id && props.agent), diff --git a/public/components/agents/sca/main.tsx b/public/components/agents/sca/main.tsx index 8daf51de54..1307bfa734 100644 --- a/public/components/agents/sca/main.tsx +++ b/public/components/agents/sca/main.tsx @@ -15,13 +15,14 @@ import { Inventory } from './index'; import { connect } from 'react-redux'; import { compose } from 'redux'; import { PromptSelectAgent, PromptNoSelectedAgent } from '../prompts'; -import { withGuard, withUserAuthorizationPrompt } from '../../common/hocs'; +import { withGuard, withUserAuthorizationPrompt, withAgentSupportModule } from '../../common/hocs'; const mapStateToProps = (state) => ({ currentAgentData: state.appStateReducers.currentAgentData, }); export const MainSca = compose( + withAgentSupportModule, withUserAuthorizationPrompt([ [ {action: 'agent:read', resource: 'agent:id:*'}, diff --git a/public/components/agents/vuls/main.tsx b/public/components/agents/vuls/main.tsx index d4aa148163..07affef2de 100644 --- a/public/components/agents/vuls/main.tsx +++ b/public/components/agents/vuls/main.tsx @@ -4,13 +4,14 @@ import '../../common/modules/module.scss'; import { connect } from 'react-redux'; import { PromptNoSelectedAgent, PromptNoActiveAgent } from '../prompts'; import { compose } from 'redux'; -import { withGuard, withUserAuthorizationPrompt } from '../../common/hocs'; +import { withGuard, withUserAuthorizationPrompt, withAgentSupportModule } from '../../common/hocs'; const mapStateToProps = (state) => ({ currentAgentData: state.appStateReducers.currentAgentData, }); export const MainVuls = compose( + withAgentSupportModule, connect(mapStateToProps), withGuard( (props) => !((props.currentAgentData && props.currentAgentData.id) && props.agent), diff --git a/public/components/common/hocs/index.ts b/public/components/common/hocs/index.ts index a08b1f9c64..4c84b317e5 100644 --- a/public/components/common/hocs/index.ts +++ b/public/components/common/hocs/index.ts @@ -21,3 +21,4 @@ export * from './withButtonOpenOnClick'; export * from './withAgentSupportModule'; export * from './withUserLogged'; export * from './error-boundary/with-error-boundary'; +export * from './with_module_tab_loader'; diff --git a/public/components/common/hocs/withAgentSupportModule.tsx b/public/components/common/hocs/withAgentSupportModule.tsx index a613f39539..f5c738d63b 100644 --- a/public/components/common/hocs/withAgentSupportModule.tsx +++ b/public/components/common/hocs/withAgentSupportModule.tsx @@ -12,9 +12,17 @@ import { PromptAgentNoSupportModule } from '../../agents/prompts'; import { withGuard } from '../../common/hocs'; import { hasAgentSupportModule } from '../../../react-services/wz-agents'; +import { compose } from 'redux'; +import { connect } from 'react-redux'; -export const withAgentSupportModule = WrappedComponent => +const mapStateToProps = (state) => ({ + agent: state.appStateReducers.currentAgentData, +}); + +export const withAgentSupportModule = WrappedComponent => compose( + connect(mapStateToProps), withGuard( - ({agent, component}) => Object.keys(agent).length && !hasAgentSupportModule(agent, component), + ({agent, moduleID}) => Object.keys(agent).length && !hasAgentSupportModule(agent, moduleID), PromptAgentNoSupportModule - )(WrappedComponent) + ) +)(WrappedComponent) diff --git a/public/components/common/hocs/with_module_tab_loader.tsx b/public/components/common/hocs/with_module_tab_loader.tsx new file mode 100644 index 0000000000..cd5dccd92e --- /dev/null +++ b/public/components/common/hocs/with_module_tab_loader.tsx @@ -0,0 +1,42 @@ +/* + * Wazuh app - Integrity monitoring components + * Copyright (C) 2015-2021 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, { useEffect, useState } from 'react'; +import { EuiLoadingSpinner, EuiSpacer } from '@elastic/eui'; +import { useRootScope } from '../hooks'; + +export const withModuleTabLoader = WrappedComponent => props => { + const $rootScope = useRootScope(); + const [showTab, setShowTab] = useState(); + useEffect(() => { + if($rootScope){ + $rootScope.loadingDashboard = true; + $rootScope.$applyAsync(); + setTimeout(() => { + setShowTab(true); + }, 100); + return () => { + $rootScope.loadingDashboard = false; + $rootScope.$applyAsync(); + } + } + },[$rootScope]); + + return showTab ? : ( + <> + +
+ +
+ + ) +} \ No newline at end of file diff --git a/public/components/common/hooks/useRootScope.ts b/public/components/common/hooks/useRootScope.ts index de6d0b9628..1f36e253ea 100644 --- a/public/components/common/hooks/useRootScope.ts +++ b/public/components/common/hooks/useRootScope.ts @@ -9,14 +9,14 @@ * * Find more information about this on the LICENSE file. */ -import { useEffect, useRef } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { getAngularModule } from '../../../kibana-services'; export function useRootScope(){ - const refRootScope = useRef(); + const [refRootScope,setRefRootScope] = useState(); useEffect(() => { const app = getAngularModule(); - refRootScope.current = app.$injector.get('$rootScope'); + setRefRootScope(app.$injector.get('$rootScope')); },[]); - return refRootScope.current; + return refRootScope; }; diff --git a/public/components/common/modules/buttons/generate_report.tsx b/public/components/common/modules/buttons/generate_report.tsx new file mode 100644 index 0000000000..f56622bab6 --- /dev/null +++ b/public/components/common/modules/buttons/generate_report.tsx @@ -0,0 +1,63 @@ +/* + * Wazuh app - Component for the module generate reports + * Copyright (C) 2015-2021 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 from 'react'; +import { useAsyncAction } from '../../hooks'; +import { getUiSettings } from '../../../../kibana-services'; +import { ReportingService } from '../../../../react-services'; +import $ from 'jquery'; +import { WzButton } from '../../../common/buttons'; + + +export const ButtonModuleGenerateReport = ({agent, moduleID, disabledReport}) => { + const action = useAsyncAction(async () => { + const reportingService = new ReportingService(); + const isDarkModeTheme = getUiSettings().get('theme:darkMode'); + if (isDarkModeTheme) { + + //Patch to fix white text in dark-mode pdf reports + const defaultTextColor = '#DFE5EF'; + + //Patch to fix dark backgrounds in visualizations dark-mode pdf reports + const $labels = $('.euiButtonEmpty__text, .echLegendItem'); + const $vizBackground = $('.echChartBackground'); + const defaultVizBackground = $vizBackground.css('background-color'); + + try { + $labels.css('color', 'black'); + $vizBackground.css('background-color', 'transparent'); + await reportingService.startVis2Png(moduleID, agent?.id || false) + $vizBackground.css('background-color', defaultVizBackground); + $labels.css('color', defaultTextColor); + } catch (e) { + $labels.css('color', defaultTextColor); + $vizBackground.css('background-color', defaultVizBackground); + } + } else { + await reportingService.startVis2Png(moduleID, agent?.id || false) + } + }); + + return ( + + Generate report + + ) +} + diff --git a/public/components/common/modules/buttons/index.ts b/public/components/common/modules/buttons/index.ts new file mode 100644 index 0000000000..76dedb877b --- /dev/null +++ b/public/components/common/modules/buttons/index.ts @@ -0,0 +1,13 @@ +/* + * Wazuh app - Module buttons components + * Copyright (C) 2015-2021 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. + */ + +export * from './generate_report'; \ No newline at end of file diff --git a/public/components/common/modules/dashboard.tsx b/public/components/common/modules/dashboard.tsx index 4827c26e28..4f07a74b7e 100644 --- a/public/components/common/modules/dashboard.tsx +++ b/public/components/common/modules/dashboard.tsx @@ -13,8 +13,14 @@ import { Component } from 'react'; import { ModulesHelper } from './modules-helper' import { getAngularModule } from '../../../kibana-services'; +import { withAgentSupportModule, withModuleTabLoader } from '../hocs'; +import { compose } from 'redux'; +import React from 'react'; -export class Dashboard extends Component { +export const Dashboard = compose( + withAgentSupportModule, + withModuleTabLoader +)(class Dashboard extends Component { _isMount = false; constructor(props) { super(props); @@ -43,6 +49,7 @@ export class Dashboard extends Component { } render() { - return false; + return null; } -} +}) + diff --git a/public/components/common/modules/events.tsx b/public/components/common/modules/events.tsx index 2ad181eb7a..e0a264e793 100644 --- a/public/components/common/modules/events.tsx +++ b/public/components/common/modules/events.tsx @@ -20,8 +20,13 @@ import { PatternHandler } from '../../../react-services/pattern-handler'; import { enhanceDiscoverEventsCell } from './events-enhance-discover-fields'; import { toMountPoint } from '../../../../../../src/plugins/kibana_react/public'; +import { withAgentSupportModule, withModuleTabLoader } from '../hocs'; +import { compose } from 'redux'; -export class Events extends Component { +export const Events = compose( + withAgentSupportModule, + withModuleTabLoader +)(class Events extends Component { intervalCheckExistsDiscoverTableTime: number = 200; isMount: boolean; state: { @@ -276,4 +281,4 @@ export class Events extends Component { ) } -} +}) diff --git a/public/components/common/modules/index.ts b/public/components/common/modules/index.ts index 7b19779c33..bbf2232cd7 100644 --- a/public/components/common/modules/index.ts +++ b/public/components/common/modules/index.ts @@ -10,8 +10,6 @@ * Find more information about this on the LICENSE file. */ -export { Events } from './events'; -export { Dashboard } from './dashboard'; -export { Loader } from './loader'; -export { Settings } from './settings'; -export { ModulesHelper } from './modules-helper.js'; +export * from './dashboard'; +export * from './events'; +export * from './modules-helper.js'; diff --git a/public/components/common/modules/loader.tsx b/public/components/common/modules/loader.tsx deleted file mode 100644 index 98a069ec85..0000000000 --- a/public/components/common/modules/loader.tsx +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Wazuh app - Integrity monitoring components - * Copyright (C) 2015-2021 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, Fragment } from 'react'; -import { getAngularModule } from '../../../kibana-services'; -import { EuiLoadingSpinner, EuiSpacer } from '@elastic/eui'; - -const app = getAngularModule(); - -export class Loader extends Component { - constructor(props) { - super(props); - } - - componentDidMount() { - this.$rootScope = app.$injector.get('$rootScope'); - this.$rootScope.loadingDashboard = true; - this.$rootScope.$applyAsync(); - } - - componentWillUnmount() { - this.$rootScope.loadingDashboard = false; - this.$rootScope.$applyAsync(); - } - - redirect() { - setTimeout(() => { - this.props.loadSection(this.props.redirect); - }, 100); - } - - render() { - const redirect = this.redirect(); - return ( - - -
- -
- {redirect} -
- ); - } -} diff --git a/public/components/common/modules/main-agent.tsx b/public/components/common/modules/main-agent.tsx index 8b5eb683ba..5a02871986 100644 --- a/public/components/common/modules/main-agent.tsx +++ b/public/components/common/modules/main-agent.tsx @@ -31,18 +31,8 @@ import { FilterHandler } from '../../../utils/filter-handler'; import { AppState } from '../../../react-services/app-state'; import { ReportingService } from '../../../react-services/reporting'; import { WAZUH_MODULES } from '../../../../common/wazuh-modules'; -import { Events, Dashboard, Loader, Settings } from '../../common/modules'; -import WzReduxProvider from '../../../redux/wz-redux-provider'; import { AgentInfo } from '../../common/welcome/agents-info'; -import Overview from '../../wz-menu/wz-menu-overview'; -import { MainFim } from '../../agents/fim'; -import { MainSca } from '../../agents/sca'; -import { MainMitre } from '../modules/main-mitre'; import { getAngularModule } from '../../../kibana-services'; -import { withAgentSupportModule } from '../../../components/common/hocs'; -import { connect } from 'react-redux'; -import { compose } from 'redux'; -import { ModuleMitreAttackIntelligence } from '../../overview/mitre_attack_intelligence'; export class MainModuleAgent extends Component { props!: { @@ -248,22 +238,11 @@ export class MainModuleAgent extends Component { ); } - renderSettingsButton() { - return ( - - this.onSelectedTabChanged('settings')}> - Configuration - - - ); - } render() { const { agent, section, selectView } = this.props; const title = this.renderTitle(); + const ModuleTabView = this.props.tabs.find(tab => tab.id === selectView); return (
@@ -287,29 +266,26 @@ export class MainModuleAgent extends Component {
{this.props.renderTabs()} - {(selectView === 'dashboard') && - this.props.renderReportButton() - } - {(this.props.buttons || []).includes('dashboard') && - this.props.renderDashboardButton() - } - {(this.props.buttons || []).includes('settings') && - this.renderSettingsButton() - } + + + {ModuleTabView && ModuleTabView.buttons && ModuleTabView.buttons.map((ModuleViewButton, index) => + typeof ModuleViewButton !== 'string' ? : null)} + +
}
- {!['syscollector', 'configuration'].includes(this.props.section) && - + {!['syscollector', 'configuration'].includes(section) && + ModuleTabView && ModuleTabView.component && } } {(!agent || !agent.os) && @@ -318,41 +294,3 @@ export class MainModuleAgent extends Component { ); } } - - - -const mapStateToProps = state => ({ - agent: state.appStateReducers.currentAgentData -}); - -const ModuleTabViewer = compose( - connect(mapStateToProps), - withAgentSupportModule -)((props) => { - const { section, selectView } = props; - return <> - {selectView === 'events' && - - } - {selectView === 'loader' && - props.loadSection(section)} - redirect={props.afterLoad}> - } - {selectView === 'dashboard' && - - } - {selectView === 'settings' && - - } - - - {/* ---------------------MODULES WITH CUSTOM PANELS--------------------------- */} - {section === 'fim' && selectView==='inventory' && } - {section === 'sca' && selectView==='inventory' && } - {section === 'mitre' && selectView === 'inventory' && } - {section === 'mitre' && selectView === 'intelligence' && } - {/* {['pci', 'gdpr', 'hipaa', 'nist', 'tsc'].includes(section) && selectView === 'inventory' && props.onSelectedTabChanged(id)} />} */} - {/* -------------------------------------------------------------------------- */} - -}) \ No newline at end of file diff --git a/public/components/common/modules/main-mitre.tsx b/public/components/common/modules/main-mitre.tsx index 2cbaa7e2f5..1d8584658d 100644 --- a/public/components/common/modules/main-mitre.tsx +++ b/public/components/common/modules/main-mitre.tsx @@ -12,10 +12,11 @@ import React, { Component } from 'react'; import { Mitre } from '../../../components/overview/mitre/mitre'; -import { withUserAuthorizationPrompt } from '../hocs'; +import { withUserAuthorizationPrompt, withAgentSupportModule } from '../hocs'; import { compose } from 'redux'; export const MainMitre = compose( + withAgentSupportModule, withUserAuthorizationPrompt([ { action: 'mitre:read', resource: '*:*:*' }, ]) diff --git a/public/components/common/modules/main-overview.tsx b/public/components/common/modules/main-overview.tsx index 8cf7c4bf9b..e786f9c9e1 100644 --- a/public/components/common/modules/main-overview.tsx +++ b/public/components/common/modules/main-overview.tsx @@ -26,27 +26,20 @@ import { } from '@elastic/eui'; import '../../common/modules/module.scss'; import { updateGlobalBreadcrumb } from '../../../redux/actions/globalBreadcrumbActions'; + import store from '../../../redux/store'; import { ReportingService } from '../../../react-services/reporting'; import { AppNavigate } from '../../../react-services/app-navigate'; import { WAZUH_MODULES } from '../../../../common/wazuh-modules'; -import { Events, Dashboard, Loader, Settings } from '../../common/modules'; -import OverviewActions from '../../../controllers/overview/components/overview-actions/overview-actions'; -import { MainFim } from '../../agents/fim'; - -import { MainVuls } from '../../agents/vuls'; -import { MainSca } from '../../agents/sca'; -import { MainMitre } from './main-mitre'; -import WzReduxProvider from '../../../redux/wz-redux-provider'; -import { ComplianceTable } from '../../overview/compliance-table'; -import { withAgentSupportModule } from '../../../components/common/hocs'; import { connect } from 'react-redux'; -import { compose } from 'redux'; +import { getDataPlugin } from '../../../kibana-services'; -import { ModuleMitreAttackIntelligence } from '../../overview/mitre_attack_intelligence'; +const mapStateToProps = (state) => ({ + agent: state.appStateReducers.currentAgentData, +}); -export class MainModuleOverview extends Component { +export const MainModuleOverview = connect(mapStateToProps)(class MainModuleOverview extends Component { constructor(props) { super(props); this.reportingService = new ReportingService(); @@ -132,10 +125,13 @@ export class MainModuleOverview extends Component { } this.setGlobalBreadcrumb(); + const { filterManager } = getDataPlugin().query; + this.filterManager = filterManager; } render() { const { section, selectView } = this.props; + const ModuleTabView = this.props.tabs.find(tab => tab.id === selectView); return (
@@ -145,58 +141,18 @@ export class MainModuleOverview extends Component { {this.props.renderTabs()} - - - + + {ModuleTabView && ModuleTabView.buttons && ModuleTabView.buttons.map((ModuleViewButton, index) => + typeof ModuleViewButton !== 'string' ? : null)} + - {selectView === 'dashboard' && this.props.renderReportButton()} - {(this.props.buttons || []).includes('dashboard') && - this.props.renderDashboardButton()}
)} - + {ModuleTabView && ModuleTabView.component && } ); } -} - -const mapStateToProps = (state) => ({ - agent: state.appStateReducers.currentAgentData, -}); - -const ModuleTabViewer = compose( - connect(mapStateToProps), - withAgentSupportModule -)((props) => { - const { section, selectView } = props; - return ( - <> - {selectView === 'events' && } - {selectView === 'loader' && ( - props.loadSection(section)} - redirect={props.afterLoad} - > - )} - {selectView === 'dashboard' && } - {selectView === 'settings' && } - - {/* ---------------------MODULES WITH CUSTOM PANELS--------------------------- */} - {section === 'fim' && selectView === 'inventory' && } - {section === 'sca' && selectView === 'inventory' && } - - {section === 'vuls' && selectView === 'inventory' && } - - {section === 'mitre' && selectView === 'inventory' && } - {section === 'mitre' && selectView === 'intelligence' && } - {['pci', 'gdpr', 'hipaa', 'nist', 'tsc'].includes(section) && selectView === 'inventory' && ( - props.onSelectedTabChanged(id)} /> - )} - {/* -------------------------------------------------------------------------- */} - - ); -}); \ No newline at end of file +}) diff --git a/public/components/common/modules/main.tsx b/public/components/common/modules/main.tsx index 275abffa09..57bf4e03fa 100644 --- a/public/components/common/modules/main.tsx +++ b/public/components/common/modules/main.tsx @@ -21,7 +21,6 @@ import { } from '@elastic/eui'; import '../../common/modules/module.scss'; import { ReportingService } from '../../../react-services/reporting'; -import { AppNavigate } from '../../../react-services/app-navigate'; import { ModulesDefaults } from './modules-defaults'; import { getAngularModule, getDataPlugin, getUiSettings } from '../../../kibana-services'; import { MainModuleAgent } from './main-agent' @@ -46,18 +45,11 @@ export const MainModule = compose( }; const app = getAngularModule(); this.$rootScope = app.$injector.get('$rootScope'); - } - - async componentDidMount() { if (!(ModulesDefaults[this.props.section] || {}).notModule) { this.tabs = (ModulesDefaults[this.props.section] || {}).tabs || [ { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }, ]; - this.buttons = (ModulesDefaults[this.props.section] || {}).buttons || [ - 'reporting', - 'settings', - ]; } } @@ -104,103 +96,6 @@ export const MainModule = compose( ); } - startVis2PngByAgent = async () => { - const agent = - (this.props.agent || store.getState().appStateReducers.currentAgentData || {}).id || false; - await this.reportingService.startVis2Png(this.props.section, agent); - }; - - async startReport() { - try { - this.setState({ loadingReport: true }); - const isDarkModeTheme = getUiSettings().get('theme:darkMode'); - if (isDarkModeTheme) { - - //Patch to fix white text in dark-mode pdf reports - const defaultTextColor = '#DFE5EF'; - - //Patch to fix dark backgrounds in visualizations dark-mode pdf reports - const $labels = $('.euiButtonEmpty__text, .echLegendItem'); - const $vizBackground = $('.echChartBackground'); - const defaultVizBackground = $vizBackground.css('background-color'); - - try { - $labels.css('color', 'black'); - $vizBackground.css('background-color', 'transparent'); - await this.startVis2PngByAgent(); - $vizBackground.css('background-color', defaultVizBackground); - $labels.css('color', defaultTextColor); - } catch (e) { - $labels.css('color', defaultTextColor); - $vizBackground.css('background-color', defaultVizBackground); - this.setState({ loadingReport: false }); - } - } else { - await this.startVis2PngByAgent(); - } - } finally { - this.setState({ loadingReport: false }); - } - } - - renderReportButton() { - return ( - (this.props.disabledReport && ( - - - this.startReport()} - > - Generate report - - - - )) || ( - - this.startReport()} - > - Generate report - - - ) - ); - } - - renderDashboardButton() { - const href = `#/overview?tab=${this.props.section}&agentId=${this.props.agent.id}`; - return ( - - this.onSelectedTabChanged('dashboard')} - > - Dashboard - - - ); - } - - renderSettingsButton() { - return ( - - this.onSelectedTabChanged('settings')} - > - Configuration - - - ); - } - loadSection(id) { this.setState({ selectView: id }); } @@ -217,8 +112,7 @@ export const MainModule = compose( new RegExp('tabView=' + '[^&]*'), `tabView=${id === 'events' ? 'discover' : id === 'inventory' ? 'inventory' : 'panels'}` ); - this.afterLoad = id; - this.loadSection('loader'); + this.loadSection(id === 'panels' ? 'dashboard' : id === 'discover' ? 'events' : id); } else { this.loadSection(id === 'panels' ? 'dashboard' : id === 'discover' ? 'events' : id); } @@ -230,13 +124,8 @@ export const MainModule = compose( const { selectView } = this.state; const mainProps = { selectView, - afterLoad: this.afterLoad, - buttons: this.buttons, tabs: this.tabs, renderTabs: () => this.renderTabs(), - renderReportButton: () => this.renderReportButton(), - renderDashboardButton: () => this.renderDashboardButton(), - renderSettingsButton: () => this.renderSettingsButton(), loadSection: (id) => this.loadSection(id), onSelectedTabChanged: (id) => this.onSelectedTabChanged(id), }; diff --git a/public/components/common/modules/modules-defaults.js b/public/components/common/modules/modules-defaults.js index 0a7232f2c2..f4bdb89aa6 100644 --- a/public/components/common/modules/modules-defaults.js +++ b/public/components/common/modules/modules-defaults.js @@ -9,66 +9,99 @@ * * Find more information about this on the LICENSE file. */ +import { Dashboard } from './dashboard'; +import { Events } from './events'; +import { MainFim } from '../../agents/fim'; +import { MainSca } from '../../agents/sca'; +import { MainVuls } from '../../agents/vuls'; +import { MainMitre } from './main-mitre'; +import { ModuleMitreAttackIntelligence } from '../../overview/mitre_attack_intelligence'; +import { ComplianceTable } from '../../overview/compliance-table'; +import ButtonModuleExploreAgent from '../../../controllers/overview/components/overview-actions/overview-actions'; +import { ButtonModuleGenerateReport } from '../modules/buttons'; + +const DashboardTab = { id: 'dashboard', name: 'Dashboard', buttons: [ButtonModuleExploreAgent, ButtonModuleGenerateReport], component: Dashboard}; +const EventsTab = { id: 'events', name: 'Events', buttons: [ButtonModuleExploreAgent], component: Events }; +const RegulatoryComplianceTabs = [{ id: 'inventory', name: 'Controls', buttons: [ButtonModuleExploreAgent], component: ComplianceTable }, DashboardTab, EventsTab]; + export const ModulesDefaults = { general: { init: 'dashboard', - tabs: [{ id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: [DashboardTab, EventsTab] }, fim: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Inventory', onlyAgent: false }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting', 'settings'] + tabs: [{ id: 'inventory', name: 'Inventory', onlyAgent: false, buttons: [ButtonModuleExploreAgent], component: MainFim }, DashboardTab, EventsTab], + }, + aws: { + init: 'dashboard', + tabs: [DashboardTab, EventsTab] }, gcp: { init: 'dashboard', - tabs: [{ id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: [DashboardTab, EventsTab], + }, + pm: { + init: 'dashboard', + tabs: [DashboardTab, EventsTab], + }, + audit: { + init: 'dashboard', + tabs: [DashboardTab, EventsTab], }, sca: { init: 'inventory', - tabs: [{ id: 'inventory', name: 'Inventory' }, { id: 'events', name: 'Events' }], + tabs: [{ id: 'inventory', name: 'Inventory', buttons: [ButtonModuleExploreAgent], component: MainSca }, EventsTab], buttons: ['settings'] }, - mitre: { + ciscat: { init: 'dashboard', - tabs: [{id: 'intelligence', name: 'Intelligence'}, { id: 'inventory', name: 'Framework' }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: [DashboardTab, EventsTab], }, vuls: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Inventory', onlyAgent: false }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting', 'settings'] + tabs: [{ id: 'inventory', name: 'Inventory', onlyAgent: false, buttons: [ButtonModuleExploreAgent], component: MainVuls }, DashboardTab, EventsTab], + buttons: ['settings'] + }, + mitre: { + init: 'dashboard', + tabs: [{ id: 'intelligence', name: 'Intelligence', component: ModuleMitreAttackIntelligence }, { id: 'inventory', name: 'Framework', buttons: [ButtonModuleExploreAgent], component: MainMitre }, DashboardTab, EventsTab] }, virustotal: { init: 'dashboard', - tabs: [{ id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: [DashboardTab, EventsTab] + }, + pci: { + init: 'dashboard', + tabs: RegulatoryComplianceTabs + }, + osquery: { + init: 'dashboard', + tabs: [DashboardTab, EventsTab], + }, + oscap: { + init: 'dashboard', + tabs: [DashboardTab, EventsTab], }, pci: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Controls' }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: [DashboardTab, EventsTab], }, hipaa: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Controls' }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: RegulatoryComplianceTabs }, nist: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Controls' }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: RegulatoryComplianceTabs }, gdpr: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Controls' }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: RegulatoryComplianceTabs }, tsc: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Controls' }, { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }], - buttons: ['reporting'] + tabs: RegulatoryComplianceTabs }, syscollector: { notModule: true diff --git a/public/components/common/modules/settings.tsx b/public/components/common/modules/settings.tsx deleted file mode 100644 index 26045f995c..0000000000 --- a/public/components/common/modules/settings.tsx +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Wazuh app - Integrity monitoring components - * Copyright (C) 2015-2021 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 { EuiSpacer, EuiTitle, EuiPanel, EuiPage } from '@elastic/eui'; -import { i18n } from '@kbn/i18n'; -import WzBadge from '../../../controllers/management/components/management/configuration/util-components/badge' -import WzReduxProvider from '../../../redux/wz-redux-provider'; -import WzConfigurationIntegrityMonitoring from '../../../controllers/management/components/management/configuration/integrity-monitoring/integrity-monitoring'; -import WzConfigurationPolicyMonitoring from '../../../controllers/management/components/management/configuration/policy-monitoring/policy-monitoring'; -import WzConfigurationOpenSCAP from '../../../controllers/management/components/management/configuration/open-scap/open-scap'; -import WzConfigurationCisCat from '../../../controllers/management/components/management/configuration/cis-cat/cis-cat'; -import WzConfigurationVulnerabilities from '../../../controllers/management/components/management/configuration/vulnerabilities/vulnerabilities'; -import WzConfigurationOsquery from '../../../controllers/management/components/management/configuration/osquery/osquery'; -import WzConfigurationDockerListener from '../../../controllers/management/components/management/configuration/docker-listener/docker-listener'; - -type SettingsPropTypes = { - agent: { id: string }, - clusterNodeSelected?: string -} - -type SettingsState = { - badge: boolean | null -} -export class Settings extends Component { - constructor(props) { - super(props); - this.state = { - badge: null - } - } - updateBadge(badge) { - this.setState({ badge }) - } - render() { - const { badge } = this.state; - const { section } = this.props; - return ( - - - - - {i18n.translate('wazuh.configuration', { defaultMessage: 'Configuration' })} {typeof badge === 'boolean' ? - : null} - - - - {section === 'fim' && this.updateBadge(e)} />} - {(section === 'pm' || section === 'sca' || section === 'audit') && - this.updateBadge(e)} onlyShowTab={section === 'pm' ? 'Policy Monitoring' : section === 'audit' ? 'System audit' : section === 'sca' ? 'SCA': undefined}/>} - {section === 'oscap' && this.updateBadge(e)} />} - {section === 'ciscat' && this.updateBadge(e)} />} - {section === 'vuls' && this.updateBadge(e)} />} - {section === 'osquery' && this.updateBadge(e)} />} - {section === 'docker' && this.updateBadge(e)} />} - - - - ) - } -} diff --git a/public/components/overview/compliance-table/compliance-table.tsx b/public/components/overview/compliance-table/compliance-table.tsx index 2f3430708e..ca95757668 100644 --- a/public/components/overview/compliance-table/compliance-table.tsx +++ b/public/components/overview/compliance-table/compliance-table.tsx @@ -13,7 +13,6 @@ import React, { Component } from 'react'; import { EuiPanel, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { SearchBar, FilterManager } from '../../../../../../src/plugins/data/public/'; -import { I18nProvider } from '@kbn/i18n/react'; //@ts-ignore import { ComplianceRequirements } from './components/requirements'; import { ComplianceSubrequirements } from './components/subrequirements'; @@ -28,8 +27,9 @@ import { getDataPlugin } from '../../../kibana-services'; import { UI_LOGGER_LEVELS } from '../../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/types'; import { getErrorOrchestrator } from '../../../react-services/common-services'; +import { withAgentSupportModule } from '../../common/hocs'; -export class ComplianceTable extends Component { +export const ComplianceTable = withAgentSupportModule(class ComplianceTable extends Component { _isMount = false; timefilter: { getTime(): any; @@ -331,4 +331,4 @@ export class ComplianceTable extends Component { ); } -} +}) diff --git a/public/controllers/overview/components/overview-actions/overview-actions.js b/public/controllers/overview/components/overview-actions/overview-actions.js index 49034f2fba..cc045b78ae 100644 --- a/public/controllers/overview/components/overview-actions/overview-actions.js +++ b/public/controllers/overview/components/overview-actions/overview-actions.js @@ -168,43 +168,41 @@ class OverviewActions extends Component { } const agent = store.getState().appStateReducers.currentAgentData; return ( -
- - {!this.state.isAgent && ( - + <> + {!this.state.isAgent && ( + + this.showAgentModal()}> +   Explore agent + + + )} + {this.state.isAgent && ( +
+ this.showAgentModal()}> -   Explore agent - + {agent.name} ({agent.id}) + - )} - {this.state.isAgent && ( -
- - this.showAgentModal()}> - {agent.name} ({agent.id}) - - - - { - store.dispatch(updateCurrentAgentData({})); - this.removeAgentsFilter(); - }} - aria-label='Unpin agent' /> - -
- )} - + + { + store.dispatch(updateCurrentAgentData({})); + this.removeAgentsFilter(); + }} + aria-label='Unpin agent' /> + +
+ )} {modal} -
+ ); } } From d09c55826ccff69941795d07c29db325f1b1ef0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20David=20Guti=C3=A9rrez?= Date: Tue, 20 Jul 2021 13:01:10 +0200 Subject: [PATCH 2/6] feat(frontend_module_tab_buttons): Refactor `Explore agent` button - Refactor `Explore agent` button - Added `availabeFor` propery to `modules-defaults.json` used by `Explore agent` button. - Created `PromptModuleNotForAgent` component - Created `withModuleNotForAgent` HOC - Removed no used code and use component props intead use `store` in `public/components/common/modules/main.tsx` --- public/components/agents/prompts/index.ts | 11 +- .../prompts/prompt_module_not_for_agent.tsx | 52 +++++++++ .../common/hocs/with_module_not_for_agent.tsx | 19 ++++ .../common/modules/main-overview.tsx | 34 +++--- public/components/common/modules/main.tsx | 16 +-- .../common/modules/modules-defaults.js | 50 ++++++--- .../overview-actions/overview-actions.js | 106 +++++++++++++----- 7 files changed, 210 insertions(+), 78 deletions(-) create mode 100644 public/components/agents/prompts/prompt_module_not_for_agent.tsx create mode 100644 public/components/common/hocs/with_module_not_for_agent.tsx diff --git a/public/components/agents/prompts/index.ts b/public/components/agents/prompts/index.ts index 1e567a6281..5519dfa4e7 100644 --- a/public/components/agents/prompts/index.ts +++ b/public/components/agents/prompts/index.ts @@ -9,8 +9,9 @@ * * Find more information about this on the LICENSE file. */ -export { PromptAgentNoSupportModule } from './prompt-agent-no-support-module'; -export { PromptNoActiveAgent, PromptNoActiveAgentWithoutSelect } from './prompt-no-active-agent'; -export { PromptNoSelectedAgent } from './prompt-no-selected-agent'; -export { PromptSelectAgent } from './prompt-select-agent'; -export { PromptAgentFeatureVersion } from './prompt-agent-feature-version'; +export * from './prompt-agent-no-support-module'; +export * from './prompt-no-active-agent'; +export * from './prompt-no-selected-agent'; +export * from './prompt-select-agent'; +export * from './prompt-agent-feature-version'; +export * from './prompt_module_not_for_agent'; diff --git a/public/components/agents/prompts/prompt_module_not_for_agent.tsx b/public/components/agents/prompts/prompt_module_not_for_agent.tsx new file mode 100644 index 0000000000..5b43356f2f --- /dev/null +++ b/public/components/agents/prompts/prompt_module_not_for_agent.tsx @@ -0,0 +1,52 @@ +/* + * Wazuh app - Component for the module generate reports + * Copyright (C) 2015-2021 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 from 'react'; +import { useDispatch } from 'react-redux'; +import { EuiButton, EuiEmptyPrompt } from '@elastic/eui'; +import { updateCurrentAgentData } from '../../../redux/actions/appStateActions'; +import { useFilterManager } from '../../common/hooks'; + +type PromptSelectAgentProps = { + body?: string; + title: string; + agentSelectionProps: { + setAgent: (agent: boolean) => void + } +}; + +export const PromptModuleNotForAgent = ({ body, title, ...agentSelectionProps }: PromptSelectAgentProps) => { + const dispatch = useDispatch(); + const filterManager = useFilterManager(); + + const unpinAgent = async () => { + dispatch(updateCurrentAgentData({})); + await agentSelectionProps.setAgent(false); + const filters = filterManager.filters.filter(x => { + return x.meta.key !== 'agent.id'; + }); + filterManager.setFilters(filters); + }; + + return ( + {title}} + body={body &&

{body}

} + actions={ + + Unpin agent + + } + /> + ); +}; \ No newline at end of file diff --git a/public/components/common/hocs/with_module_not_for_agent.tsx b/public/components/common/hocs/with_module_not_for_agent.tsx new file mode 100644 index 0000000000..7fc5754ac6 --- /dev/null +++ b/public/components/common/hocs/with_module_not_for_agent.tsx @@ -0,0 +1,19 @@ + + +import { compose } from 'redux'; +import { connect } from 'react-redux'; +import { withGuard } from './withGuard'; +import { PromptModuleNotForAgent } from '../../agents/prompts'; +import React from 'react'; + +const mapStateToProps = (state) => ({ + agent: state.appStateReducers.currentAgentData, +}); + +export const withModuleNotForAgent = WrappedComponent => compose( + connect(mapStateToProps), + withGuard( + ({agent}) => agent?.id, + (props) => + ) +)(WrappedComponent); diff --git a/public/components/common/modules/main-overview.tsx b/public/components/common/modules/main-overview.tsx index e786f9c9e1..a50955fb5b 100644 --- a/public/components/common/modules/main-overview.tsx +++ b/public/components/common/modules/main-overview.tsx @@ -134,24 +134,22 @@ export const MainModuleOverview = connect(mapStateToProps)(class MainModuleOverv const ModuleTabView = this.props.tabs.find(tab => tab.id === selectView); return (
- -
- {this.props.tabs && this.props.tabs.length && ( -
- - {this.props.renderTabs()} - - - {ModuleTabView && ModuleTabView.buttons && ModuleTabView.buttons.map((ModuleViewButton, index) => - typeof ModuleViewButton !== 'string' ? : null)} - - - -
- )} -
- {ModuleTabView && ModuleTabView.component && } -
+
+ {this.props.tabs && this.props.tabs.length && ( +
+ + {this.props.renderTabs()} + + + {ModuleTabView && ModuleTabView.buttons && ModuleTabView.buttons.map((ModuleViewButton, index) => + typeof ModuleViewButton !== 'string' ? : null)} + + + +
+ )} +
+ {ModuleTabView && ModuleTabView.component && }
); } diff --git a/public/components/common/modules/main.tsx b/public/components/common/modules/main.tsx index 57bf4e03fa..7464f8b60b 100644 --- a/public/components/common/modules/main.tsx +++ b/public/components/common/modules/main.tsx @@ -22,10 +22,9 @@ import { import '../../common/modules/module.scss'; import { ReportingService } from '../../../react-services/reporting'; import { ModulesDefaults } from './modules-defaults'; -import { getAngularModule, getDataPlugin, getUiSettings } from '../../../kibana-services'; +import { getAngularModule, getDataPlugin } from '../../../kibana-services'; import { MainModuleAgent } from './main-agent' import { MainModuleOverview } from './main-overview'; -import store from '../../../redux/store'; import { compose } from 'redux'; import { withReduxProvider,withErrorBoundary } from '../hocs'; @@ -50,6 +49,7 @@ export const MainModule = compose( { id: 'dashboard', name: 'Dashboard' }, { id: 'events', name: 'Events' }, ]; + this.module = ModulesDefaults[this.props.section]; } } @@ -60,17 +60,6 @@ export const MainModule = compose( } } - canBeInit(tab) { - //checks if the init table can be set - let canInit = false; - this.tabs.forEach((element) => { - if (element.id === tab && (!element.onlyAgent || (element.onlyAgent && this.props.agent))) { - canInit = true; - } - }); - return canInit; - } - renderTabs(agent = false) { const { selectView } = this.state; if (!agent) { @@ -125,6 +114,7 @@ export const MainModule = compose( const mainProps = { selectView, tabs: this.tabs, + module: this.module, renderTabs: () => this.renderTabs(), loadSection: (id) => this.loadSection(id), onSelectedTabChanged: (id) => this.onSelectedTabChanged(id), diff --git a/public/components/common/modules/modules-defaults.js b/public/components/common/modules/modules-defaults.js index f4bdb89aa6..d5783601dd 100644 --- a/public/components/common/modules/modules-defaults.js +++ b/public/components/common/modules/modules-defaults.js @@ -27,81 +27,105 @@ const RegulatoryComplianceTabs = [{ id: 'inventory', name: 'Controls', buttons: export const ModulesDefaults = { general: { init: 'dashboard', - tabs: [DashboardTab, EventsTab] + tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, fim: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Inventory', onlyAgent: false, buttons: [ButtonModuleExploreAgent], component: MainFim }, DashboardTab, EventsTab], + tabs: [{ id: 'inventory', name: 'Inventory', buttons: [ButtonModuleExploreAgent], component: MainFim }, DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, aws: { init: 'dashboard', - tabs: [DashboardTab, EventsTab] + tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'], }, gcp: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, pm: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, audit: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, sca: { init: 'inventory', tabs: [{ id: 'inventory', name: 'Inventory', buttons: [ButtonModuleExploreAgent], component: MainSca }, EventsTab], - buttons: ['settings'] + buttons: ['settings'], + availableFor: ['manager','agent'] }, ciscat: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, vuls: { init: 'dashboard', - tabs: [{ id: 'inventory', name: 'Inventory', onlyAgent: false, buttons: [ButtonModuleExploreAgent], component: MainVuls }, DashboardTab, EventsTab], - buttons: ['settings'] + tabs: [{ id: 'inventory', name: 'Inventory', buttons: [ButtonModuleExploreAgent], component: MainVuls }, DashboardTab, EventsTab], + buttons: ['settings'], + availableFor: ['manager','agent'] }, mitre: { init: 'dashboard', - tabs: [{ id: 'intelligence', name: 'Intelligence', component: ModuleMitreAttackIntelligence }, { id: 'inventory', name: 'Framework', buttons: [ButtonModuleExploreAgent], component: MainMitre }, DashboardTab, EventsTab] + tabs: [{ id: 'intelligence', name: 'Intelligence', component: ModuleMitreAttackIntelligence }, { id: 'inventory', name: 'Framework', buttons: [ButtonModuleExploreAgent], component: MainMitre }, DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, virustotal: { init: 'dashboard', - tabs: [DashboardTab, EventsTab] + tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] + }, + docker: { + init: 'dashboard', + tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, pci: { init: 'dashboard', - tabs: RegulatoryComplianceTabs + tabs: RegulatoryComplianceTabs, + availableFor: ['manager','agent'] }, osquery: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, oscap: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, pci: { init: 'dashboard', tabs: [DashboardTab, EventsTab], + availableFor: ['manager','agent'] }, hipaa: { init: 'dashboard', - tabs: RegulatoryComplianceTabs + tabs: RegulatoryComplianceTabs, + availableFor: ['manager','agent'] }, nist: { init: 'dashboard', - tabs: RegulatoryComplianceTabs + tabs: RegulatoryComplianceTabs, + availableFor: ['manager','agent'] }, gdpr: { init: 'dashboard', - tabs: RegulatoryComplianceTabs + tabs: RegulatoryComplianceTabs, + availableFor: ['manager','agent'] }, tsc: { init: 'dashboard', - tabs: RegulatoryComplianceTabs + tabs: RegulatoryComplianceTabs, + availableFor: ['manager','agent'] }, syscollector: { notModule: true diff --git a/public/controllers/overview/components/overview-actions/overview-actions.js b/public/controllers/overview/components/overview-actions/overview-actions.js index cc045b78ae..993d504cd7 100644 --- a/public/controllers/overview/components/overview-actions/overview-actions.js +++ b/public/controllers/overview/components/overview-actions/overview-actions.js @@ -10,21 +10,18 @@ * Find more information about this on the LICENSE file. */ import React, { Component } from 'react'; -import store from '../../../../redux/store'; import { connect } from 'react-redux'; import { showExploreAgentModal, updateCurrentAgentData } from '../../../../redux/actions/appStateActions'; import { - EuiButtonEmpty, - EuiButtonIcon, - EuiFlexItem, - EuiIcon, + EuiModal, EuiModalBody, EuiModalHeader, EuiModalHeaderTitle, EuiOverlayMask, - EuiToolTip, + EuiPopover } from '@elastic/eui'; +import { WzButton } from '../../../../components/common/buttons'; import './agents-selector.scss'; import { AgentSelectionTable } from './agents-selection-table'; import { WAZUH_ALERTS_PATTERN } from '../../../../../common/constants'; @@ -52,21 +49,20 @@ class OverviewActions extends Component { } componentDidMount() { - const agentId = store.getState().appStateReducers.currentAgentData.id; + const { filterManager } = getDataPlugin().query; this.setState({ filterManager: filterManager }, () => { if (this.props.initialFilter) this.agentTableSearch([this.props.initialFilter]) - if (agentId) this.agentTableSearch([agentId]) + if (this.props.agent.id) this.agentTableSearch([this.props.agent.id]) }); } componentDidUpdate(){ - const agent = store.getState().appStateReducers.currentAgentData; - if(this.state.isAgent && !agent.id){ + if(this.state.isAgent && !this.props.agent.id){ this.setState({isAgent: false}) - }else if(agent.id && this.state.isAgent !== agent.id){ - this.setState({isAgent: agent.id}) + }else if(this.props.agent.id && this.state.isAgent !== this.props.agent.id){ + this.setState({isAgent: this.props.agent.id}) } } @@ -85,7 +81,7 @@ class OverviewActions extends Component { closeAgentModal() { this.setState({ isAgentModalVisible: false }); - store.dispatch(showExploreAgentModal(false)); + this.props.showExploreAgentModal(false); } showAgentModal() { @@ -166,10 +162,57 @@ class OverviewActions extends Component { ); } - const agent = store.getState().appStateReducers.currentAgentData; + + const thereAgentSelected = (this.props.agent || {}).id + + const avaliableForAgent = this.props.module.availableFor && this.props.module.availableFor.includes('agent'); + + let buttonUnpinAgent, buttonExploreAgent; + if(thereAgentSelected){ + buttonUnpinAgent = ( + { + this.props.updateCurrentAgentData({}); + this.removeAgentsFilter(); + }} + tooltip={{position: 'bottom', content: 'Unpin agent'}} + aria-label='Unpin agent' + /> + ); + }; + + buttonExploreAgent = ( + this.showAgentModal()}> + {thereAgentSelected ? `${this.props.agent.name} (${this.props.agent.id})` : 'Explore agent'} + + ) + return ( - <> - {!this.state.isAgent && ( +
+ {buttonExploreAgent} + {thereAgentSelected && ( + !avaliableForAgent && ( + {}}> + This module is not supported for agents. Remove the pinned agent. + + + ) || buttonUnpinAgent + )} + {/* {!this.state.isAgent && ( this.showAgentModal()}> {agent.name} ({agent.id}) - { - store.dispatch(updateCurrentAgentData({})); - this.removeAgentsFilter(); - }} - aria-label='Unpin agent' /> - -
- )} + {}}> + This module is not supported for agents. Remove the pinned agent. + + */} + {/* + )} */} {modal} - + ); } } @@ -210,7 +252,13 @@ class OverviewActions extends Component { const mapStateToProps = state => { return { state: state.appStateReducers, + agent: state.appStateReducers.currentAgentData }; }; -export default connect(mapStateToProps, null)(OverviewActions); +const mapDispatchToProps = dispatch => ({ + updateCurrentAgentData: (agent) => dispatch(updateCurrentAgentData(agent)), + showExploreAgentModal: (data) => dispatch(showExploreAgentModal(data)) +}); + +export default connect(mapStateToProps, mapDispatchToProps)(OverviewActions); From 0c28ccf3c3ef359a171af3378767e5f9e080ba47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20David=20Guti=C3=A9rrez?= Date: Tue, 20 Jul 2021 13:22:40 +0200 Subject: [PATCH 3/6] changelog: Add PR to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f692b6dc04..fe74e59b76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Refactored all try catch strategy on Controller/Agent section [#3398](https://github.com/wazuh/wazuh-kibana-app/issues/3398) - Refactored all try catch value of context for ErrorOrchestrator service. [#3432](https://github.com/wazuh/wazuh-kibana-app/issues/3432) - Refactored all try catch strategy on Controller/Groups section [#3415](https://github.com/wazuh/wazuh-kibana-app/issues/3415) +- Refactored as module tabs and buttons are rendered [#3494](https://github.com/wazuh/wazuh-kibana-app/pull/3494) ### Fixed From 11dec871c8013a45c56d5532203d551da2aee994 Mon Sep 17 00:00:00 2001 From: CPAlejandro Date: Fri, 6 Aug 2021 13:31:55 +0200 Subject: [PATCH 4/6] Fixing error generating report in security events --- public/react-services/reporting.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/react-services/reporting.js b/public/react-services/reporting.js index ed2326f1e5..2a2b8d8b83 100644 --- a/public/react-services/reporting.js +++ b/public/react-services/reporting.js @@ -82,16 +82,20 @@ export class ReportingService { idArray = rawVisualizations.map(item => item.id); } + const visualizationIDList = []; for (const item of idArray) { const tmpHTMLElement = $(`#${item}`); - this.vis2png.assignHTMLItem(item, tmpHTMLElement); + if(tmpHTMLElement[0]){ + this.vis2png.assignHTMLItem(item, tmpHTMLElement); + visualizationIDList.push(item); + } } const appliedFilters = await this.visHandlers.getAppliedFilters( syscollectorFilters ); - const array = await this.vis2png.checkArray(idArray); + const array = await this.vis2png.checkArray(visualizationIDList); const name = `wazuh-${ agents ? `agent-${agents}` : 'overview' }-${tab}-${(Date.now() / 1000) | 0}.pdf`; From 460d5a07768a75bd98244ff2057169439125473a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20David=20Guti=C3=A9rrez?= Date: Fri, 6 Aug 2021 15:11:49 +0200 Subject: [PATCH 5/6] fix(frontend): Add license block to `with_module_not_for_agent.tsx` and `with_module_tab_loader.tsx` --- .../common/hocs/with_module_not_for_agent.tsx | 14 ++++++++++++-- .../common/hocs/with_module_tab_loader.tsx | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/components/common/hocs/with_module_not_for_agent.tsx b/public/components/common/hocs/with_module_not_for_agent.tsx index 7fc5754ac6..ca362f85a1 100644 --- a/public/components/common/hocs/with_module_not_for_agent.tsx +++ b/public/components/common/hocs/with_module_not_for_agent.tsx @@ -1,10 +1,20 @@ +/* + * Wazuh app - React HOC to show a prompt when a module is not available for agents and let to unpin the agent + * Copyright (C) 2015-2021 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 from 'react'; import { compose } from 'redux'; import { connect } from 'react-redux'; import { withGuard } from './withGuard'; import { PromptModuleNotForAgent } from '../../agents/prompts'; -import React from 'react'; const mapStateToProps = (state) => ({ agent: state.appStateReducers.currentAgentData, diff --git a/public/components/common/hocs/with_module_tab_loader.tsx b/public/components/common/hocs/with_module_tab_loader.tsx index cd5dccd92e..637dda21da 100644 --- a/public/components/common/hocs/with_module_tab_loader.tsx +++ b/public/components/common/hocs/with_module_tab_loader.tsx @@ -1,5 +1,5 @@ /* - * Wazuh app - Integrity monitoring components + * Wazuh app - React HOC to show a loader used for Dashboard adn Events module tabs * Copyright (C) 2015-2021 Wazuh, Inc. * * This program is free software; you can redistribute it and/or modify From 21f5f840aee8b54a86f5e793bd018b1ae8e1ab4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20David=20Guti=C3=A9rrez?= Date: Mon, 9 Aug 2021 11:11:46 +0200 Subject: [PATCH 6/6] fix(frontend): Fixed description in license for a prompt component file --- .../components/agents/prompts/prompt_module_not_for_agent.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/components/agents/prompts/prompt_module_not_for_agent.tsx b/public/components/agents/prompts/prompt_module_not_for_agent.tsx index 5b43356f2f..500b230c3d 100644 --- a/public/components/agents/prompts/prompt_module_not_for_agent.tsx +++ b/public/components/agents/prompts/prompt_module_not_for_agent.tsx @@ -1,5 +1,5 @@ /* - * Wazuh app - Component for the module generate reports + * Wazuh app - Prompt when an agent doesn't support some module * Copyright (C) 2015-2021 Wazuh, Inc. * * This program is free software; you can redistribute it and/or modify