Skip to content

Commit

Permalink
Fixed keeping filters between dashboard and inventory using visualiza…
Browse files Browse the repository at this point in the history
…tions call to actions (#6448)

* Fixed keeping filters between dashboard and inventory using visualizations call to actions

* Added CHANGELOG

* Fixed to remove auto loaded agent.id filters

* Fix CHANGELOG

* Fixed hideManagerAlerts filter

* Fixed filters order
  • Loading branch information
jbiset authored Feb 28, 2024
1 parent f3d3904 commit 8c39829
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Added the ability to check if there are available updates from the UI. [#6093](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6093) [#6256](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6256) [#6328](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6328)
- Added remember server address check [#5791](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5791)
- Added the ssl_agent_ca configuration to the SSL Settings form [#6083](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6083)
- Added global vulnerabilities dashboards [#5896](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5896) [#6179](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6179) [#6173](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6173) [#6147](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6147) [#6231](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6231) [#6246](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6246) [#6321](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6321) [#6338](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6338) [#6356](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6356) [#6396](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6396) [#6399](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6399) [#6405](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6405) [#6410](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6410) [#6424](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6424) [#6422](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6422) [#6429](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6429)
- Added global vulnerabilities dashboards [#5896](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5896) [#6179](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6179) [#6173](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6173) [#6147](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6147) [#6231](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6231) [#6246](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6246) [#6321](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6321) [#6338](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6338) [#6356](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6356) [#6396](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6396) [#6399](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6399) [#6405](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6405) [#6410](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6410) [#6424](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6424) [#6422](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6422) [#6429](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6429) [#6448](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6448)
- Added an agent selector to the IT Hygiene application [#5840](https://github.com/wazuh/wazuh-dashboard-plugins/pull/5840)
- Added query results limit when the search exceed 10000 hits [#6106](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6106)
- Added a redirection button to Endpoint Summary from IT Hygiene application [#6176](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6176)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,24 @@ const cleanFilters = (
);
return mappedFilters;
};

export const updateFiltersStorage = (filters: Filter[]) => {
const storagePreviousFilters = sessionStorage.getItem(
SESSION_STORAGE_FILTERS_NAME,
);
if (storagePreviousFilters) {
const previousFilters = JSON.parse(storagePreviousFilters);
const previousImplicitFilters = previousFilters.filter(
(filter: Filter) => filter?.$state?.isImplicit,
);
/* Normal filters added to storagePreviousFilters are added to keep them between dashboard and inventory tab */
const newFilters = filters.filter(
(filter: Filter) => !filter?.$state?.isImplicit,
);

sessionStorage.setItem(
SESSION_STORAGE_FILTERS_NAME,
JSON.stringify([...previousImplicitFilters, ...newFilters]),
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
vulnerabilityIndexFiltersAdapter,
restorePrevIndexFiltersAdapter,
onUpdateAdapter,
updateFiltersStorage,
} from '../../common/vulnerability_detector_adapters';
import { search } from '../inventory/inventory_service';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
Expand All @@ -28,6 +29,7 @@ import { compose } from 'redux';
import { withVulnerabilitiesStateDataSource } from '../../common/hocs/validate-vulnerabilities-states-index-pattern';
import { ModuleEnabledCheck } from '../../common/components/check-module-enabled';
import { DataSourceFilterManagerVulnerabilitiesStates } from '../../../../../react-services/data-sources';
import { DashboardContainerInput } from '../../../../../../../../src/plugins/dashboard/public';

const plugins = getPlugins();

Expand All @@ -50,12 +52,20 @@ const DashboardVulsComponent: React.FC = () => {
onUnMount: restorePrevIndexFiltersAdapter,
});

/* This function is responsible for updating the storage filters so that the
filters between dashboard and inventory added using visualizations call to actions.
Without this feature, filters added using visualizations call to actions are
not maintained between dashboard and inventory tabs */
const handleFilterByVisualization = (newInput: DashboardContainerInput) => {
updateFiltersStorage(newInput.filters);
};

const fetchFilters = DataSourceFilterManagerVulnerabilitiesStates.getFilters(
searchBarProps.filters,
VULNERABILITIES_INDEX_PATTERN_ID,
);

const { isLoading, filters, query, indexPatterns } = searchBarProps;
const { isLoading, query, indexPatterns } = searchBarProps;

const [isSearching, setIsSearching] = useState<boolean>(false);
const [results, setResults] = useState<SearchResponse>({} as SearchResponse);
Expand Down Expand Up @@ -128,6 +138,7 @@ const DashboardVulsComponent: React.FC = () => {
},
hidePanelTitles: true,
}}
onInputUpdated={handleFilterByVisualization}
/>
</div>
<DashboardByRenderer
Expand All @@ -151,6 +162,7 @@ const DashboardVulsComponent: React.FC = () => {
},
hidePanelTitles: true,
}}
onInputUpdated={handleFilterByVisualization}
/>
<DashboardByRenderer
input={{
Expand All @@ -173,6 +185,7 @@ const DashboardVulsComponent: React.FC = () => {
},
hidePanelTitles: false,
}}
onInputUpdated={handleFilterByVisualization}
/>
</div>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import {
useQueryManager,
useTimeFilter,
} from '../../../common/hooks';
import {
AUTHORIZED_AGENTS,
DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER,
} from '../../../../../common/constants';

// Input - types
type tUseSearchBarCustomInputs = {
Expand Down Expand Up @@ -134,7 +138,21 @@ const useSearchBarConfiguration = (
const searchBarProps: Partial<SearchBarProps> = {
isLoading,
...(indexPatternSelected && { indexPatterns: [indexPatternSelected] }), // indexPattern cannot be empty or empty []
filters: filters,
filters: filters
.filter(
(filter: Filter) =>
![
AUTHORIZED_AGENTS,
DATA_SOURCE_FILTER_CONTROLLED_EXCLUDE_SERVER,
].includes(filter?.meta?.controlledBy), // remove auto loaded agent.id filters
)
.sort((a: Filter, b: Filter) => {
return a?.$state?.isImplicit && !(a?.meta?.key === 'agent.id')
? -1
: b?.$state?.isImplicit
? 1
: -1;
}),
query,
timeHistory,
dateRangeFrom: timeFilter.from,
Expand Down
10 changes: 9 additions & 1 deletion scripts/vulnerabilities-events-injector/DIS_Template.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@
}
}
},
"manager": {
"properties": {
"name": {
"ignore_above": 1024,
"type": "keyword"
}
}
},
"node": {
"properties": {
"name": {
Expand All @@ -262,4 +270,4 @@
"refresh_interval": "2s"
}
}
}
}

0 comments on commit 8c39829

Please sign in to comment.