From ba8a48ac75d5cc28af25d558cb42978c3624cbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Cu=C3=A9llar=20Peinado?= Date: Tue, 2 Mar 2021 19:08:33 +0100 Subject: [PATCH] Fixed that alerts table is empty when switching pinned agents (#3008) * Fixed that alerts table is empty when switching pinned agents * Fixed blanks * Refactor discover.tsx - Merging filter managers * Deleted searchbar state * Set discover stand-alone fileManager * Code cleaning * Fix adding previous filters * Added changes to changelog --- CHANGELOG.md | 11 ++++ .../agents/fim/inventory/fileDetail.tsx | 9 ++- .../common/modules/discover/discover.tsx | 58 +++++++------------ .../requirement-flyout/requirement-flyout.tsx | 7 ++- .../flyout-technique/flyout-technique.tsx | 7 ++- .../visualize/components/security-alerts.tsx | 2 +- public/kibana-integrations/kibana-discover.js | 2 +- 7 files changed, 53 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df7b19257d..e2500ca3b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,17 @@ All notable changes to the Wazuh app project will be documented in this file. - Overlay Wazuh menu when Kibana menu is opened or docked [#3038](https://github.com/wazuh/wazuh-kibana-app/pull/3038) +## Wazuh v4.1.1 - Kibana 7.10.0 , 7.10.2 - Revision 4103 + +### Fixed + +- Fix SCA policy detail showing name and check results about another policy [#3007](https://github.com/wazuh/wazuh-kibana-app/pull/3007) +- Fix pagination in SCA checks table when expand some row [#3018](https://github.com/wazuh/wazuh-kibana-app/pull/3018) +- Fix manager is shown in suggestions in Agents section [#3025](https://github.com/wazuh/wazuh-kibana-app/pull/3025) +- Fix disabled loading on inventory when request fail [#3016](https://github.com/wazuh/wazuh-kibana-app/issues/3016) +- Fix restarting selected cluster instead of all of them [#3032](https://github.com/wazuh/wazuh-kibana-app/pull/3032) +- Fixed that alerts table is empty when switching pinned agents [#3008](https://github.com/wazuh/wazuh-kibana-app/pull/3008) + ## Wazuh v4.1.1 - Kibana 7.10.0 , 7.10.2 - Revision 4102 ### Added diff --git a/public/components/agents/fim/inventory/fileDetail.tsx b/public/components/agents/fim/inventory/fileDetail.tsx index 886937506b..6330a4dd8f 100644 --- a/public/components/agents/fim/inventory/fileDetail.tsx +++ b/public/components/agents/fim/inventory/fileDetail.tsx @@ -32,9 +32,10 @@ import { getIndexPattern } from '../../../overview/mitre/lib'; import moment from 'moment-timezone'; import { AppNavigate } from '../../../../react-services/app-navigate'; import { TruncateHorizontalComponents } from '../../../common/util'; -import { getDataPlugin } from '../../../../kibana-services'; +import { getDataPlugin,getUiSettings } from '../../../../kibana-services'; import { RegistryValues } from './registryValues'; import { TimeService } from '../../../../react-services/time-service'; +import { FilterManager } from '../../../../../../../src/plugins/data/public/'; export class FileDetails extends Component { props!: { @@ -68,6 +69,8 @@ export class FileDetails extends Component { ); indexPattern!: IIndexPattern; + discoverFilterManager: FilterManager; + constructor(props) { super(props); @@ -76,6 +79,8 @@ export class FileDetails extends Component { totalHits: 0, }; this.viewInEvents.bind(this); + + this.discoverFilterManager = new FilterManager(getUiSettings()); } componentDidMount() { @@ -475,6 +480,8 @@ export class FileDetails extends Component { this.state[field] !== prevState[field]) || (this.state.tsUpdated !== prevState.tsUpdated)){ @@ -262,10 +251,6 @@ export const Discover = compose( return result; } - onFiltersChange = (filters) => { - this.setState({ filters: this.filtersAsArray(filters) }); - } - toggleDetails = item => { const itemIdToExpandedRowMap = { ...this.state.itemIdToExpandedRowMap }; if (itemIdToExpandedRowMap[item._id]) { @@ -282,7 +267,6 @@ export const Discover = compose( buildFilter() { const dateParse = ds => /\d+-\d+-\d+T\d+:\d+:\d+.\d+Z/.test(ds) ? DateMatch.parse(ds).toDate().getTime() : ds; - const { searchBarFilters } = this.state; const { query } = this.state; const { hideManagerAlerts } = this.wazuhConfig.getConfig(); const extraFilters = []; @@ -300,12 +284,14 @@ export const Discover = compose( $state: { store: 'appState' } }); - const shareFilterManager = this.props.shareFilterManager || []; + const filters = this.props.shareFilterManager ? this.props.shareFilterManager.filters : []; + const previousFilters = this.KibanaServices && this.KibanaServices.query.filterManager.filters ? this.KibanaServices.query.filterManager.filters : []; + const elasticQuery = buildEsQuery( undefined, query, - [...searchBarFilters, ...extraFilters, ...shareFilterManager], + [...previousFilters, ...filters, ...extraFilters], getEsQueryConfig(getUiSettings()) ); @@ -355,12 +341,12 @@ export const Discover = compose( } ); if (this._isMount) { - this.setState({ alerts: alerts.data.hits.hits, total: alerts.data.hits.total.value, isLoading: false, requestFilters: newFilters, filters: newFilters.filters }); + this.setState({ alerts: alerts.data.hits.hits, total: alerts.data.hits.total.value, isLoading: false, requestFilters: newFilters}); this.props.updateTotalHits(alerts.data.hits.total.value); } } catch (err) { if (this._isMount) { - this.setState({ alerts: [], total: 0, isLoading: false, requestFilters: newFilters, filters: newFilters.filters }); + this.setState({ alerts: [], total: 0, isLoading: false, requestFilters: newFilters}); this.props.updateTotalHits(0); } } @@ -521,19 +507,17 @@ export const Discover = compose( * @param filter */ addFilterOut(filter) { + const filterManager = this.props.shareFilterManager; const key = Object.keys(filter)[0]; const value = filter[key]; const valuesArray = Array.isArray(value) ? [...value] : [value]; - const filters = this.state.searchBarFilters; valuesArray.map((item) => { const formattedFilter = buildPhraseFilter({ name: key, type: "string" }, item, this.indexPattern); formattedFilter.meta.negate = true; - filters.push(formattedFilter); + filterManager.addFilters(formattedFilter); }) - - this.filterManager.setFilters(filters); - if (!this.props.shareFilterManager) this.setState({ searchBarFilters: filters }); + this.setState({ pageIndex: 0 , tsUpdated: Date.now()}); } /** @@ -541,20 +525,18 @@ export const Discover = compose( * @param filter */ addFilter(filter) { + const filterManager = this.props.shareFilterManager; const key = Object.keys(filter)[0]; const value = filter[key]; const valuesArray = Array.isArray(value) ? [...value] : [value]; - const filters = []; //this.state.searchBarFilters; valuesArray.map((item) => { const formattedFilter = buildPhraseFilter({ name: key, type: "string" }, item, this.indexPattern); if (formattedFilter.meta.key === 'manager.name' || formattedFilter.meta.key === 'cluster.name') { formattedFilter.meta["removable"] = false; } - filters.push(formattedFilter); + filterManager.addFilters(formattedFilter); }) - this.filterManager.addFilters(filters); - if (!this.props.shareFilterManager) this.setState({ searchBarFilters: filters }); - + this.setState({ pageIndex: 0 , tsUpdated: Date.now()}); } onQuerySubmit = (payload: { dateRange: TimeRange, query: Query | undefined }) => { @@ -562,7 +544,7 @@ export const Discover = compose( } onFiltersUpdated = (filters: Filter[]) => { - this.setState({ searchBarFilters: filters }); + this.setState({ pageIndex: 0 , tsUpdated: Date.now()}); } closeMitreFlyout = () => { @@ -624,9 +606,9 @@ export const Discover = compose( return (
- {!this.props.shareFilterManager && diff --git a/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx b/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx index da8350d0e0..f2b655ad94 100644 --- a/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx +++ b/public/components/overview/compliance-table/components/requirement-flyout/requirement-flyout.tsx @@ -30,6 +30,8 @@ import { import { Discover } from '../../../../common/modules/discover'; import { AppState } from '../../../../../react-services/app-state'; import { requirementGoal } from '../../requirement-goal'; +import { getUiSettings } from '../../../../../kibana-services'; +import { FilterManager } from '../../../../../../../../src/plugins/data/public/'; @@ -41,10 +43,13 @@ export class RequirementFlyout extends Component { props!: { }; + filterManager: FilterManager; + constructor(props) { super(props); this.state = { } + this.filterManager = new FilterManager(getUiSettings()); } componentDidMount() { @@ -164,7 +169,7 @@ export class RequirementFlyout extends Component { initialIsOpen={true}> - this.updateTotalHits(total)} /> + this.updateTotalHits(total)} /> diff --git a/public/components/overview/mitre/components/techniques/components/flyout-technique/flyout-technique.tsx b/public/components/overview/mitre/components/techniques/components/flyout-technique/flyout-technique.tsx index 8047db8ac3..dfda83fe2e 100644 --- a/public/components/overview/mitre/components/techniques/components/flyout-technique/flyout-technique.tsx +++ b/public/components/overview/mitre/components/techniques/components/flyout-technique/flyout-technique.tsx @@ -39,6 +39,8 @@ import { WzRequest } from '../../../../../../../react-services/wz-request'; import { AppState } from '../../../../../../../react-services/app-state'; import { AppNavigate } from '../../../../../../../react-services/app-navigate'; import { Discover } from '../../../../../../common/modules/discover'; +import { getUiSettings } from '../../../../../../../kibana-services'; +import { FilterManager } from '../../../../../../../../../../src/plugins/data/public/'; export class FlyoutTechnique extends Component { _isMount = false; @@ -56,6 +58,8 @@ export class FlyoutTechnique extends Component { currentTechnique: string } + filterManager: FilterManager; + constructor(props) { super(props); this.state = { @@ -64,6 +68,7 @@ export class FlyoutTechnique extends Component { }, loading: false } + this.filterManager = new FilterManager(getUiSettings()); } async componentDidMount() { @@ -315,7 +320,7 @@ export class FlyoutTechnique extends Component { initialIsOpen={true}> - this.updateTotalHits(total)}/> + this.updateTotalHits(total)}/> diff --git a/public/components/visualize/components/security-alerts.tsx b/public/components/visualize/components/security-alerts.tsx index c89993d2b2..5a10439714 100644 --- a/public/components/visualize/components/security-alerts.tsx +++ b/public/components/visualize/components/security-alerts.tsx @@ -21,7 +21,7 @@ export const SecurityAlerts = () => { return ( { //Patch empty fields const filters = filterManager.getAppFilters(); - if(filters.filter(item=>item.meta.params.query==='').length){ + if(filters.filter(item=> item.meta.params && item.meta.params.query === '').length){ getToasts().add({ color: 'warning', title: 'Invalid field value',