diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.test.ts index 26a69093ae48d..cbe226ce68aa8 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.test.ts @@ -5,40 +5,47 @@ * 2.0. */ -import { getAlertingSectionBreadcrumb, getRuleDetailsBreadcrumb } from './breadcrumb'; +import { getAlertingSectionBreadcrumb } from './breadcrumb'; import { i18n } from '@kbn/i18n'; import { routeToConnectors, routeToRules, routeToHome } from '../constants'; describe('getAlertingSectionBreadcrumb', () => { test('if change calls return proper breadcrumb title ', async () => { - expect(getAlertingSectionBreadcrumb('connectors')).toMatchObject({ + expect(getAlertingSectionBreadcrumb('connectors', true)).toMatchObject({ text: i18n.translate('xpack.triggersActionsUI.connectors.breadcrumbTitle', { defaultMessage: 'Connectors', }), href: `${routeToConnectors}`, }); - expect(getAlertingSectionBreadcrumb('rules')).toMatchObject({ + expect(getAlertingSectionBreadcrumb('rules', true)).toMatchObject({ text: i18n.translate('xpack.triggersActionsUI.rules.breadcrumbTitle', { defaultMessage: 'Rules', }), href: `${routeToRules}`, }); - expect(getAlertingSectionBreadcrumb('home')).toMatchObject({ + expect(getAlertingSectionBreadcrumb('home', true)).toMatchObject({ text: i18n.translate('xpack.triggersActionsUI.home.breadcrumbTitle', { defaultMessage: 'Rules and Connectors', }), href: `${routeToHome}`, }); }); -}); - -describe('getRuleDetailsBreadcrumb', () => { - test('if select an alert should return proper breadcrumb title with alert name ', async () => { - expect(getRuleDetailsBreadcrumb('testId', 'testName')).toMatchObject({ - text: i18n.translate('xpack.triggersActionsUI.alertDetails.breadcrumbTitle', { - defaultMessage: 'testName', + test('if boolean is passed in returns proper breadcrumb href ', async () => { + expect(getAlertingSectionBreadcrumb('connectors', true)).toMatchObject({ + text: i18n.translate('xpack.triggersActionsUI.connectors.breadcrumbTitle', { + defaultMessage: 'Connectors', + }), + href: `${routeToConnectors}`, + }); + expect(getAlertingSectionBreadcrumb('rules', false)).toMatchObject({ + text: i18n.translate('xpack.triggersActionsUI.rules.breadcrumbTitle', { + defaultMessage: 'Rules', + }), + }); + expect(getAlertingSectionBreadcrumb('home', false)).toMatchObject({ + text: i18n.translate('xpack.triggersActionsUI.home.breadcrumbTitle', { + defaultMessage: 'Rules and Connectors', }), - href: '/rule/testId', }); }); }); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.ts index d26cdbcb3d174..46a15b12bb733 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/breadcrumb.ts @@ -6,9 +6,12 @@ */ import { i18n } from '@kbn/i18n'; -import { routeToHome, routeToConnectors, routeToRules, routeToRuleDetails } from '../constants'; +import { routeToHome, routeToConnectors, routeToRules } from '../constants'; -export const getAlertingSectionBreadcrumb = (type: string): { text: string; href: string } => { +export const getAlertingSectionBreadcrumb = ( + type: string, + returnHref: boolean = false +): { text: string; href?: string } => { // Home and sections switch (type) { case 'connectors': @@ -16,31 +19,33 @@ export const getAlertingSectionBreadcrumb = (type: string): { text: string; href text: i18n.translate('xpack.triggersActionsUI.connectors.breadcrumbTitle', { defaultMessage: 'Connectors', }), - href: `${routeToConnectors}`, + ...(returnHref + ? { + href: `${routeToConnectors}`, + } + : {}), }; case 'rules': return { text: i18n.translate('xpack.triggersActionsUI.rules.breadcrumbTitle', { defaultMessage: 'Rules', }), - href: `${routeToRules}`, + ...(returnHref + ? { + href: `${routeToRules}`, + } + : {}), }; default: return { text: i18n.translate('xpack.triggersActionsUI.home.breadcrumbTitle', { defaultMessage: 'Rules and Connectors', }), - href: `${routeToHome}`, + ...(returnHref + ? { + href: `${routeToHome}`, + } + : {}), }; } }; - -export const getRuleDetailsBreadcrumb = ( - id: string, - name: string -): { text: string; href: string } => { - return { - text: name, - href: `${routeToRuleDetails.replace(':ruleId', id)}`, - }; -}; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/rule_details.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/rule_details.tsx index c17bc40086666..38357d7c56057 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/rule_details.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rule_details/components/rule_details.tsx @@ -36,7 +36,7 @@ import { hasExecuteActionsCapability, hasManageApiKeysCapability, } from '../../../lib/capabilities'; -import { getAlertingSectionBreadcrumb, getRuleDetailsBreadcrumb } from '../../../lib/breadcrumb'; +import { getAlertingSectionBreadcrumb } from '../../../lib/breadcrumb'; import { getCurrentDocTitle } from '../../../lib/doc_title'; import { Rule, @@ -117,10 +117,7 @@ export const RuleDetails: React.FunctionComponent = ({ // Set breadcrumb and page title useEffect(() => { - setBreadcrumbs([ - getAlertingSectionBreadcrumb('rules'), - getRuleDetailsBreadcrumb(rule.id, rule.name), - ]); + setBreadcrumbs([getAlertingSectionBreadcrumb('rules', true), { text: rule.name }]); chrome.docTitle.change(getCurrentDocTitle('rules')); // eslint-disable-next-line react-hooks/exhaustive-deps }, []);