Skip to content

Commit

Permalink
[Response Ops] [Alerting] Rules and Connectors: Current page in bread…
Browse files Browse the repository at this point in the history
…crumbs shows as link (#141838)

* Updating breadcrumb function for alerting

* Remove href
  • Loading branch information
doakalexi authored Sep 29, 2022
1 parent e678b78 commit 7c9875c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,46 @@
*/

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':
return {
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)}`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -117,10 +117,7 @@ export const RuleDetails: React.FunctionComponent<RuleDetailsProps> = ({

// 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
}, []);
Expand Down

0 comments on commit 7c9875c

Please sign in to comment.