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

[Response Ops] [Alerting] Rules and Connectors: Current page in breadcrumbs shows as link #141838

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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