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

Fixed Alert details does not update page title and breadcrumb #74214

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 @@ -22,7 +22,7 @@ import {

import { i18n } from '@kbn/i18n';
import { Section, routeToConnectors, routeToAlerts } from './constants';
import { getCurrentBreadcrumb } from './lib/breadcrumb';
import { getAlertingSectionBreadcrumb } from './lib/breadcrumb';
import { getCurrentDocTitle } from './lib/doc_title';
import { useAppDependencies } from './app_context';
import { hasShowActionsCapability } from './lib/capabilities';
Expand Down Expand Up @@ -75,7 +75,7 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<

// Set breadcrumb and page title
useEffect(() => {
setBreadcrumbs([getCurrentBreadcrumb(section || 'home')]);
setBreadcrumbs([getAlertingSectionBreadcrumb(section || 'home')]);
chrome.docTitle.change(getCurrentDocTitle(section || 'home'));
}, [section, chrome, setBreadcrumbs]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { getCurrentBreadcrumb } from './breadcrumb';
import { getAlertingSectionBreadcrumb, getAlertDetailsBreadcrumb } from './breadcrumb';
import { i18n } from '@kbn/i18n';
import { routeToConnectors, routeToAlerts, routeToHome } from '../constants';

describe('getCurrentBreadcrumb', () => {
describe('getAlertingSectionBreadcrumb', () => {
test('if change calls return proper breadcrumb title ', async () => {
expect(getCurrentBreadcrumb('connectors')).toMatchObject({
expect(getAlertingSectionBreadcrumb('connectors')).toMatchObject({
text: i18n.translate('xpack.triggersActionsUI.connectors.breadcrumbTitle', {
defaultMessage: 'Connectors',
}),
href: `${routeToConnectors}`,
});
expect(getCurrentBreadcrumb('alerts')).toMatchObject({
expect(getAlertingSectionBreadcrumb('alerts')).toMatchObject({
text: i18n.translate('xpack.triggersActionsUI.alerts.breadcrumbTitle', {
defaultMessage: 'Alerts',
}),
href: `${routeToAlerts}`,
});
expect(getCurrentBreadcrumb('home')).toMatchObject({
expect(getAlertingSectionBreadcrumb('home')).toMatchObject({
text: i18n.translate('xpack.triggersActionsUI.home.breadcrumbTitle', {
defaultMessage: 'Alerts and Actions',
}),
href: `${routeToHome}`,
});
});
});

describe('getAlertDetailsBreadcrumb', () => {
test('if select an alert should return proper breadcrumb title with alert name ', async () => {
expect(getAlertDetailsBreadcrumb('testId', 'testName')).toMatchObject({
text: i18n.translate('xpack.triggersActionsUI.alertDetails.breadcrumbTitle', {
defaultMessage: 'testName',
}),
href: '/alert/testId',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

import { i18n } from '@kbn/i18n';
import { routeToHome, routeToConnectors, routeToAlerts } from '../constants';
import { routeToHome, routeToConnectors, routeToAlerts, routeToAlertDetails } from '../constants';

export const getCurrentBreadcrumb = (type: string): { text: string; href: string } => {
export const getAlertingSectionBreadcrumb = (type: string): { text: string; href: string } => {
// Home and sections
switch (type) {
case 'connectors':
Expand All @@ -33,3 +33,13 @@ export const getCurrentBreadcrumb = (type: string): { text: string; href: string
};
}
};

export const getAlertDetailsBreadcrumb = (
id: string,
name: string
): { text: string; href: string } => {
return {
text: name,
href: `${routeToAlertDetails.replace(':alertId', id)}`,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, Fragment } from 'react';
import React, { useState, Fragment, useEffect } from 'react';
import { keyBy } from 'lodash';
import { useHistory } from 'react-router-dom';
import {
Expand All @@ -29,6 +29,8 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { useAppDependencies } from '../../../app_context';
import { hasAllPrivilege, hasExecuteActionsCapability } from '../../../lib/capabilities';
import { getAlertingSectionBreadcrumb, getAlertDetailsBreadcrumb } from '../../../lib/breadcrumb';
import { getCurrentDocTitle } from '../../../lib/doc_title';
import { Alert, AlertType, ActionType } from '../../../../types';
import {
ComponentOpts as BulkOperationsComponentOpts,
Expand Down Expand Up @@ -69,8 +71,20 @@ export const AlertDetails: React.FunctionComponent<AlertDetailsProps> = ({
docLinks,
charts,
dataPlugin,
setBreadcrumbs,
chrome,
} = useAppDependencies();

// Set breadcrumb and page title
useEffect(() => {
setBreadcrumbs([
getAlertingSectionBreadcrumb('alerts'),
getAlertDetailsBreadcrumb(alert.id, alert.name),
]);
chrome.docTitle.change(getCurrentDocTitle('alerts'));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const canExecuteActions = hasExecuteActionsCapability(capabilities);
const canSaveAlert =
hasAllPrivilege(alert, alertType) &&
Expand Down