Skip to content

Commit

Permalink
[SecuritySolution] Fix Entity risk score visualization displays 'N/A'…
Browse files Browse the repository at this point in the history
… instead of score (elastic#177448)

## Summary

Add a new property to the `LensVisualization` that prevents the table
and tab filters from being applied.

### BEFORE
<img
src="https://github.com/elastic/kibana/assets/1490444/e13deb8f-d023-404d-9cea-e749b8ee2694"
width="500" />

### AFTER
<img
src="https://github.com/elastic/kibana/assets/1490444/ad12325d-fe4f-40cd-83a8-45d755707061"
width="500" />


### How to test it?
* Open the User flyout on the host's page / Events
* The risk score visualization should not be filtered by *exists
host.name"

### Checklist

Delete any items that are not applicable to this PR.


- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
machadoum authored and fkanout committed Mar 4, 2024
1 parent d766b15 commit 5bd106c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const LensComponentWrapper = styled.div<{

const LensEmbeddableComponent: React.FC<LensEmbeddableComponentProps> = ({
applyGlobalQueriesAndFilters = true,
applyPageAndTabsFilters = true,
extraActions,
extraOptions,
getLensAttributes,
Expand Down Expand Up @@ -99,6 +100,7 @@ const LensEmbeddableComponent: React.FC<LensEmbeddableComponentProps> = ({
const { searchSessionId } = useVisualizationResponse({ visualizationId: id });
const attributes = useLensAttributes({
applyGlobalQueriesAndFilters,
applyPageAndTabsFilters,
extraOptions,
getLensAttributes,
lensAttributes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type GetLensAttributes = (

export interface UseLensAttributesProps {
applyGlobalQueriesAndFilters?: boolean;
applyPageAndTabsFilters?: boolean;
extraOptions?: ExtraOptions;
getLensAttributes?: GetLensAttributes;
lensAttributes?: LensAttributes | null;
Expand Down Expand Up @@ -83,6 +84,7 @@ export enum VisualizationContextMenuDefaultActionName {

export interface LensEmbeddableComponentProps {
applyGlobalQueriesAndFilters?: boolean;
applyPageAndTabsFilters?: boolean;
extraActions?: Action[];
extraOptions?: ExtraOptions;
getLensAttributes?: GetLensAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,31 @@ describe('useLensAttributes', () => {
]);
});

it('should not apply tabs and pages when applyPageAndTabsFilters = false', () => {
(useRouteSpy as jest.Mock).mockReturnValue([
{
detailName: 'elastic',
pageName: 'user',
tabName: 'events',
},
]);
const { result } = renderHook(
() =>
useLensAttributes({
applyPageAndTabsFilters: false,
getLensAttributes: getExternalAlertLensAttributes,
stackByField: 'event.dataset',
}),
{ wrapper }
);

expect(result?.current?.state.filters).toEqual([
...getExternalAlertLensAttributes().state.filters,
...getIndexFilters(['auditbeat-*']),
...filterFromSearchBar,
]);
});

it('should add data view id to references', () => {
const { result } = renderHook(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {

export const useLensAttributes = ({
applyGlobalQueriesAndFilters = true,
applyPageAndTabsFilters = true,
extraOptions,
getLensAttributes,
lensAttributes,
Expand Down Expand Up @@ -95,8 +96,8 @@ export const useLensAttributes = ({
...(applyGlobalQueriesAndFilters ? { query } : {}),
filters: [
...attrs.state.filters,
...pageFilters,
...tabsFilters,
...(applyPageAndTabsFilters ? pageFilters : []),
...(applyPageAndTabsFilters ? tabsFilters : []),
...indexFilters,
...(applyGlobalQueriesAndFilters ? filters : []),
],
Expand All @@ -108,6 +109,7 @@ export const useLensAttributes = ({
} as LensAttributes;
}, [
applyGlobalQueriesAndFilters,
applyPageAndTabsFilters,
attrs,
dataViewId,
filters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ const RiskSummaryComponent = <T extends RiskScoreEntity>({
{riskData && (
<VisualizationEmbeddable
applyGlobalQueriesAndFilters={false}
applyPageAndTabsFilters={false}
lensAttributes={lensAttributes}
id={`RiskSummary-risk_score_metric`}
timerange={timerange}
Expand Down

0 comments on commit 5bd106c

Please sign in to comment.