From 4b6b1c3effaf9918f8332a21af42409092fd8ed5 Mon Sep 17 00:00:00 2001 From: Charlotte Alexandra Wilson Date: Fri, 8 Nov 2024 16:33:50 +0000 Subject: [PATCH] Make all risk score decimal places consistent (#198450) ## Summary This PR updates risk scores to use formatter to 2DP instead of basic Math.round for consistency and accuracy. ![image](https://github.com/user-attachments/assets/ede600ef-acd3-463b-8f0f-8f527271836e) ![image](https://github.com/user-attachments/assets/a49f2a01-e05a-4077-8397-cff18da7cfa5) ![image](https://github.com/user-attachments/assets/599d3bcb-118f-4e32-94e6-ff4aa0a60fa8) With reverted alert score, showing user and host risk scores still have formatting: ![image](https://github.com/user-attachments/assets/94cb4d9e-a468-4cb7-b162-74762b134436) --- .../components/entity_analytics_risk_score/columns.tsx | 3 ++- .../entity_store/hooks/use_entities_list_columns.tsx | 3 ++- .../components/host_risk_score_table/columns.tsx | 3 ++- .../components/user_risk_score_table/columns.tsx | 3 ++- .../cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx index e6ac30f15c5b0..9459953b6d1d0 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_analytics_risk_score/columns.tsx @@ -30,6 +30,7 @@ import { SecurityCellActionType, } from '../../../common/components/cell_actions'; import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date'; +import { formatRiskScore } from '../../common'; type HostRiskScoreColumns = Array>; @@ -128,7 +129,7 @@ export const getRiskScoreColumns = ( if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx index e603c95b6604a..1da79d3d2cd0e 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/hooks/use_entities_list_columns.tsx @@ -21,6 +21,7 @@ import { type CriticalityLevels } from '../../../../../common/constants'; import { ENTITIES_LIST_TABLE_ID } from '../constants'; import { isUserEntity, sourceFieldToText } from '../helpers'; import { CRITICALITY_LEVEL_TITLE } from '../../asset_criticality/translations'; +import { formatRiskScore } from '../../../common'; export type EntitiesListColumns = [ Columns, @@ -149,7 +150,7 @@ export const useEntitiesListColumns = (): EntitiesListColumns => { if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx index e1509a03a9a90..ac85589736336 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/host_risk_score_table/columns.tsx @@ -23,6 +23,7 @@ import { RiskScoreLevel } from '../severity/common'; import { ENTITY_RISK_LEVEL } from '../risk_score/translations'; import { CELL_ACTIONS_TELEMETRY } from '../risk_score/constants'; import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date'; +import { formatRiskScore } from '../../common'; export const getHostRiskScoreColumns = ({ dispatchSeverityUpdate, @@ -82,7 +83,7 @@ export const getHostRiskScoreColumns = ({ if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx index 49eaf7b3cc26b..0cb7960ecabba 100644 --- a/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx +++ b/x-pack/plugins/security_solution/public/entity_analytics/components/user_risk_score_table/columns.tsx @@ -24,6 +24,7 @@ import { UsersTableType } from '../../../explore/users/store/model'; import { ENTITY_RISK_LEVEL } from '../risk_score/translations'; import { CELL_ACTIONS_TELEMETRY } from '../risk_score/constants'; import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date'; +import { formatRiskScore } from '../../common'; export const getUserRiskScoreColumns = ({ dispatchSeverityUpdate, @@ -85,7 +86,7 @@ export const getUserRiskScoreColumns = ({ if (riskScore != null) { return ( - {Math.round(riskScore)} + {formatRiskScore(riskScore)} ); } diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts index 2f1b4d4e9eb91..3123bd30cb450 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics/hosts/host_risk_tab.cy.ts @@ -46,7 +46,7 @@ describe('risk tab', { tags: ['@ess'] }, () => { kqlSearch('host.name: "siem-kibana" {enter}'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(4).should('have.text', 'siem-kibana'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(5).should('have.text', 'Mar 10, 2021 @ 14:51:05.766'); - cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '21'); + cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '21.00'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(7).should('have.text', 'Low'); }); @@ -93,7 +93,7 @@ describe('risk tab', { tags: ['@ess'] }, () => { kqlSearch('host.name: "siem-kibana" {enter}'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(4).should('have.text', 'siem-kibana'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(5).should('have.text', 'Mar 10, 2021 @ 14:51:05.766'); - cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '90'); + cy.get(HOST_BY_RISK_TABLE_CELL).eq(6).should('have.text', '90.00'); cy.get(HOST_BY_RISK_TABLE_CELL).eq(7).should('have.text', 'Critical'); });