Skip to content

Commit db82481

Browse files
committed
fix variable name, update left panel props so it accepts findingsIndex and findingsResult check
1 parent 083467b commit db82481

5 files changed

Lines changed: 89 additions & 33 deletions

File tree

x-pack/plugins/security_solution/public/cloud_security_posture/components/misconfiguration/misconfiguration_preview.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) =>
143143
const failedFindings = data?.count.failed || 0;
144144

145145
const { euiTheme } = useEuiTheme();
146-
const hasMisconfigurationFindings = passedFindings > 0 || failedFindings > 0;
146+
const hasMisconfigurationFindingsForThisQuery = passedFindings > 0 || failedFindings > 0;
147147
const hasMisconfigurationFindingsIndex =
148148
useCspSetupStatusApi().data?.hasMisconfigurationsFindings || false;
149149
const hostNameFilterQuery = useMemo(
@@ -168,20 +168,27 @@ export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) =>
168168
params: {
169169
name: hostName,
170170
isRiskScoreExist,
171-
isMisconfigurationFindingsExist: hasMisconfigurationFindingsIndex,
171+
isMisconfigurationFindingsIndexExist: hasMisconfigurationFindingsIndex,
172+
isMisconfigurationFindingsForThisQueryExist: hasMisconfigurationFindingsForThisQuery,
172173
path: { tab: 'csp_insights' },
173174
},
174175
});
175-
}, [hasMisconfigurationFindingsIndex, hostName, isRiskScoreExist, openLeftPanel]);
176+
}, [
177+
hasMisconfigurationFindingsForThisQuery,
178+
hasMisconfigurationFindingsIndex,
179+
hostName,
180+
isRiskScoreExist,
181+
openLeftPanel,
182+
]);
176183
const link = useMemo(
177184
() =>
178185
!isPreviewMode
179186
? {
180187
callback: goToEntityInsightTab,
181188
tooltip: (
182189
<FormattedMessage
183-
id="xpack.securitySolution.flyout.right.insights.threatIntelligence.threatIntelligenceTooltip"
184-
defaultMessage="Show all threat intelligence"
190+
id="xpack.securitySolution.flyout.right.insights.misconfiguration.misconfigurationTooltip"
191+
defaultMessage="Show all misconfiguration findings"
185192
/>
186193
),
187194
}
@@ -191,7 +198,7 @@ export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) =>
191198
return (
192199
<ExpandablePanel
193200
header={{
194-
iconType: hasMisconfigurationFindings ? 'arrowStart' : '',
201+
iconType: hasMisconfigurationFindingsForThisQuery ? 'arrowStart' : '',
195202
title: (
196203
<EuiText
197204
size="xs"
@@ -205,12 +212,12 @@ export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) =>
205212
/>
206213
</EuiText>
207214
),
208-
link: hasMisconfigurationFindings ? link : undefined,
215+
link: hasMisconfigurationFindingsForThisQuery ? link : undefined,
209216
}}
210217
data-test-subj={'securitySolutionFlyoutInsightsMisconfigurations'}
211218
>
212219
<EuiFlexGroup gutterSize="none">
213-
{hasMisconfigurationFindings ? (
220+
{hasMisconfigurationFindingsForThisQuery ? (
214221
<MisconfigurationPreviewScore
215222
passedFindings={passedFindings}
216223
failedFindings={failedFindings}

x-pack/plugins/security_solution/public/entity_analytics/components/entity_details_flyout/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { RiskInputsTab } from './tabs/risk_inputs/risk_inputs_tab';
1414
import { InsightsTabCsp } from '../../../cloud_security_posture/components/csp_details/insights_tab_csp';
1515

1616
export const RISK_INPUTS_TAB_TEST_ID = `${PREFIX}RiskInputsTab` as const;
17+
export const INSIGHTS_TAB_TEST_ID = `${PREFIX}InsightInputsTab` as const;
1718

1819
export const getRiskInputTab = ({ entityType, entityName, scopeId }: RiskInputsTabProps) => ({
1920
id: EntityDetailsLeftPanelTab.RISK_INPUTS,
@@ -29,7 +30,7 @@ export const getRiskInputTab = ({ entityType, entityName, scopeId }: RiskInputsT
2930

3031
export const getInsightsInputTab = ({ name }: { name: string }) => ({
3132
id: EntityDetailsLeftPanelTab.CSP_INSIGHTS,
32-
'data-test-subj': 'cspInsightDataTestId',
33+
'data-test-subj': INSIGHTS_TAB_TEST_ID,
3334
name: (
3435
<FormattedMessage
3536
id="xpack.securitySolution.flyout.entityDetails.userDetails.riskInputs.tabLabel"

x-pack/plugins/security_solution/public/flyout/entity_details/host_details_left/index.test.tsx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
* 2.0.
66
*/
77

8-
import { RISK_INPUTS_TAB_TEST_ID } from '../../../entity_analytics/components/entity_details_flyout';
8+
import {
9+
RISK_INPUTS_TAB_TEST_ID,
10+
INSIGHTS_TAB_TEST_ID,
11+
} from '../../../entity_analytics/components/entity_details_flyout';
912
import { render } from '@testing-library/react';
1013
import React from 'react';
1114
import { HostDetailsPanel } from '.';
@@ -59,4 +62,52 @@ describe('HostDetailsPanel', () => {
5962
);
6063
expect(queryByTestId(RISK_INPUTS_TAB_TEST_ID)).not.toBeInTheDocument();
6164
});
65+
66+
it("doesn't render insights panel when there no misconfiguration findings index", () => {
67+
const { queryByTestId } = render(
68+
<HostDetailsPanel
69+
name="elastic"
70+
isRiskScoreExist={false}
71+
scopeId={'scopeId'}
72+
isMisconfigurationFindingsIndexExist={false}
73+
isMisconfigurationFindingsForThisQueryExist={true}
74+
/>,
75+
{
76+
wrapper: TestProviders,
77+
}
78+
);
79+
expect(queryByTestId(INSIGHTS_TAB_TEST_ID)).not.toBeInTheDocument();
80+
});
81+
82+
it("doesn't render insights panel when there no misconfiguration findings that matches the host name", () => {
83+
const { queryByTestId } = render(
84+
<HostDetailsPanel
85+
name="elastic"
86+
isRiskScoreExist={false}
87+
scopeId={'scopeId'}
88+
isMisconfigurationFindingsIndexExist={true}
89+
isMisconfigurationFindingsForThisQueryExist={false}
90+
/>,
91+
{
92+
wrapper: TestProviders,
93+
}
94+
);
95+
expect(queryByTestId(INSIGHTS_TAB_TEST_ID)).not.toBeInTheDocument();
96+
});
97+
98+
it('render insights panel when there are misconfiguration findings index and misconfiguration findings that matches the host name', () => {
99+
const { queryByTestId } = render(
100+
<HostDetailsPanel
101+
name="elastic"
102+
isRiskScoreExist={false}
103+
scopeId={'scopeId'}
104+
isMisconfigurationFindingsIndexExist={true}
105+
isMisconfigurationFindingsForThisQueryExist={true}
106+
/>,
107+
{
108+
wrapper: TestProviders,
109+
}
110+
);
111+
expect(queryByTestId(INSIGHTS_TAB_TEST_ID)).toBeInTheDocument();
112+
});
62113
});

x-pack/plugins/security_solution/public/flyout/entity_details/host_details_left/index.tsx

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import React, { useMemo, useState } from 'react';
99
import type { FlyoutPanelProps } from '@kbn/expandable-flyout';
10-
import { useMisconfigurationPreview } from '@kbn/cloud-security-posture/src/hooks/use_misconfiguration_preview';
11-
import { buildEntityFlyoutPreviewQuery } from '@kbn/cloud-security-posture-common';
1210
import {
1311
getRiskInputTab,
1412
getInsightsInputTab,
@@ -24,7 +22,8 @@ export interface HostDetailsPanelProps extends Record<string, unknown> {
2422
isRiskScoreExist: boolean;
2523
name: string;
2624
scopeId: string;
27-
isMisconfigurationFindingsExist?: boolean;
25+
isMisconfigurationFindingsIndexExist?: boolean;
26+
isMisconfigurationFindingsForThisQueryExist?: boolean;
2827
path?: {
2928
tab?: EntityDetailsLeftPanelTab;
3029
};
@@ -40,26 +39,15 @@ export const HostDetailsPanel = ({
4039
isRiskScoreExist,
4140
scopeId,
4241
path,
43-
isMisconfigurationFindingsExist,
42+
isMisconfigurationFindingsIndexExist,
43+
isMisconfigurationFindingsForThisQueryExist,
4444
}: HostDetailsPanelProps) => {
4545
const [selectedTabId, setSelectedTabId] = useState(
4646
path?.tab === EntityDetailsLeftPanelTab.CSP_INSIGHTS
4747
? EntityDetailsLeftPanelTab.CSP_INSIGHTS
4848
: EntityDetailsLeftPanelTab.RISK_INPUTS
4949
);
5050

51-
const { data } = useMisconfigurationPreview({
52-
query: buildEntityFlyoutPreviewQuery('host.name', name),
53-
sort: [],
54-
enabled: true,
55-
pageSize: 1,
56-
});
57-
58-
const passedFindings = data?.count.passed || 0;
59-
const failedFindings = data?.count.failed || 0;
60-
61-
const hasMisconfigurationFindings = passedFindings > 0 || failedFindings > 0;
62-
6351
const [tabs] = useMemo(() => {
6452
const isRiskScoreTabAvailable = isRiskScoreExist && name;
6553
const riskScoreTab = isRiskScoreTabAvailable
@@ -68,16 +56,16 @@ export const HostDetailsPanel = ({
6856

6957
// Determine if the Insights tab should be included
7058
const insightsTab =
71-
isMisconfigurationFindingsExist && hasMisconfigurationFindings
59+
isMisconfigurationFindingsIndexExist && isMisconfigurationFindingsForThisQueryExist
7260
? [getInsightsInputTab({ name })]
7361
: [];
7462
return [[...riskScoreTab, ...insightsTab], EntityDetailsLeftPanelTab.RISK_INPUTS, () => {}];
7563
}, [
7664
isRiskScoreExist,
7765
name,
7866
scopeId,
79-
isMisconfigurationFindingsExist,
80-
hasMisconfigurationFindings,
67+
isMisconfigurationFindingsIndexExist,
68+
isMisconfigurationFindingsForThisQueryExist,
8169
]);
8270

8371
return (

x-pack/plugins/security_solution/public/flyout/entity_details/host_right/index.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const HostPanel = ({
9595
{ onSuccess: refetchRiskScore }
9696
);
9797

98-
const hasMisconfigurationFindings =
98+
const hasMisconfigurationFindingsIndex =
9999
useCspSetupStatusApi().data?.hasMisconfigurationsFindings || false;
100100

101101
const { data } = useMisconfigurationPreview({
@@ -133,11 +133,20 @@ export const HostPanel = ({
133133
scopeId,
134134
isRiskScoreExist,
135135
path: tab ? { tab } : undefined,
136-
isMisconfigurationFindingsExist: hasMisconfigurationFindings,
136+
isMisconfigurationFindingsIndexExist: hasMisconfigurationFindingsIndex,
137+
isMisconfigurationFindingsForThisQueryExist: hasMisconfigurationFindingsForThisQuery,
137138
},
138139
});
139140
},
140-
[telemetry, openLeftPanel, hostName, scopeId, isRiskScoreExist, hasMisconfigurationFindings]
141+
[
142+
telemetry,
143+
openLeftPanel,
144+
hostName,
145+
scopeId,
146+
isRiskScoreExist,
147+
hasMisconfigurationFindingsIndex,
148+
hasMisconfigurationFindingsForThisQuery,
149+
]
141150
);
142151

143152
const openDefaultPanel = useCallback(
@@ -179,7 +188,7 @@ export const HostPanel = ({
179188
flyoutIsExpandable={
180189
!isPreviewMode &&
181190
(isRiskScoreExist ||
182-
(hasMisconfigurationFindings && hasMisconfigurationFindingsForThisQuery))
191+
(hasMisconfigurationFindingsIndex && hasMisconfigurationFindingsForThisQuery))
183192
}
184193
expandDetails={openDefaultPanel}
185194
/>

0 commit comments

Comments
 (0)