Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Entity Analytics] Use docLinks service for documentation links #172172

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/kbn-doc-links/src/get_doc_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,9 @@ export const getDocLinks = ({ kibanaBranch }: GetDocLinkOptions): DocLinks => {
createEsqlRuleType: `${SECURITY_SOLUTION_DOCS}rules-ui-create.html#create-esql-rule`,
entityAnalytics: {
riskScorePrerequisites: `${SECURITY_SOLUTION_DOCS}ers-requirements.html`,
hostRiskScore: 'host-risk-score.html',
hop-dev marked this conversation as resolved.
Show resolved Hide resolved
userRiskScore: 'user-risk-score.html',
entityRiskScoring: 'advanced-entity-analytics-overview.html#entity-risk-scoring',
},
},
query: {
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ export interface DocLinks {
readonly createEsqlRuleType: string;
readonly entityAnalytics: {
readonly riskScorePrerequisites: string;
readonly hostRiskScore: string;
readonly userRiskScore: string;
readonly entityRiskScoring: string;
};
};
readonly query: {
Expand Down
7 changes: 0 additions & 7 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,6 @@ export enum BulkActionsDryRunErrCode {
ESQL_INDEX_PATTERN = 'ESQL_INDEX_PATTERN',
}

export const RISKY_HOSTS_DOC_LINK =
'https://www.elastic.co/guide/en/security/current/host-risk-score.html';
export const RISKY_USERS_DOC_LINK =
'https://www.elastic.co/guide/en/security/current/user-risk-score.html';
export const RISKY_ENTITY_SCORE_DOC_LINK =
'https://www.elastic.co/guide/en/security/current/advanced-entity-analytics-overview.html#entity-risk-scoring';

export const MAX_NUMBER_OF_NEW_TERMS_FIELDS = 3;

export const BULK_ADD_TO_TIMELINE_LIMIT = 2000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
import { EuiLink } from '@elastic/eui';
import React, { useMemo } from 'react';
import { RiskScoreEntity } from '../../../../../common/search_strategy';
import {
RISKY_HOSTS_DOC_LINK,
RISKY_USERS_DOC_LINK,
RISKY_ENTITY_SCORE_DOC_LINK,
} from '../../../../../common/constants';
import { LEARN_MORE } from '../../../../overview/components/entity_analytics/risk_score/translations';
import { useKibana } from '../../../../common/lib/kibana';

const useLearnMoreLinkForEntity = (riskScoreEntity?: RiskScoreEntity) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily a suggestion, more of a question:

Do you think there would be value in adding a test case for this, now that we're using more dynamic links instead of them just being hardcoded? I assume it would involve mocking the docLinks service, so not sure how much value we'd get, but thought I'd ask!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did debate testing it, but I concluded the tests would be too tied to the implementation to give much value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

const { docLinks } = useKibana().services;
const entityAnalyticsLinks = docLinks.links.securitySolution.entityAnalytics;
return useMemo(() => {
if (!riskScoreEntity) {
return entityAnalyticsLinks.entityRiskScoring;
}
if (riskScoreEntity === RiskScoreEntity.user) {
return entityAnalyticsLinks.userRiskScore;
}
return entityAnalyticsLinks.hostRiskScore;
}, [riskScoreEntity, entityAnalyticsLinks]);
};

const RiskScoreDocLinkComponent = ({
riskScoreEntity,
Expand All @@ -22,18 +32,10 @@ const RiskScoreDocLinkComponent = ({
riskScoreEntity?: RiskScoreEntity;
title?: string | React.ReactNode;
}) => {
const docLink = useMemo(() => {
if (!riskScoreEntity) {
return RISKY_ENTITY_SCORE_DOC_LINK;
}
if (riskScoreEntity === RiskScoreEntity.user) {
return RISKY_USERS_DOC_LINK;
}
return RISKY_HOSTS_DOC_LINK;
}, [riskScoreEntity]);
const learnMoreLink = useLearnMoreLinkForEntity(riskScoreEntity);

return (
<EuiLink target="_blank" rel="noopener nofollow noreferrer" href={docLink}>
<EuiLink target="_blank" rel="noopener nofollow noreferrer" href={learnMoreLink}>
{title ? title : LEARN_MORE(riskScoreEntity)}
</EuiLink>
);
Expand Down