Skip to content

Commit

Permalink
[Entity Analytics] Use docLinks service for documentation links (#172172
Browse files Browse the repository at this point in the history
)

## Summary

Using the docLinks service means documentation links will always point
to the correct version of the docs for the current Kibana version, not
just the latest docs.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
hop-dev and kibanamachine authored Dec 2, 2023
1 parent 7ad94e9 commit f08f40a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
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: `${SECURITY_SOLUTION_DOCS}host-risk-score.html`,
userRiskScore: `${SECURITY_SOLUTION_DOCS}user-risk-score.html`,
entityRiskScoring: `${SECURITY_SOLUTION_DOCS}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 @@ -455,13 +455,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) => {
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

0 comments on commit f08f40a

Please sign in to comment.