Skip to content

Commit

Permalink
[es-management] implement k7Breadcrumbs (#26711)
Browse files Browse the repository at this point in the history
* [es-manaagement] implement k7Breadcrumbs

* fix i18n ids
  • Loading branch information
Spencer authored and chrisronline committed Dec 12, 2018
1 parent 02cd345 commit 2078beb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
10 changes: 10 additions & 0 deletions x-pack/plugins/index_management/public/register_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { HashRouter } from 'react-router-dom';
import { i18n } from '@kbn/i18n';
import { I18nProvider } from '@kbn/i18n/react';
import { setHttpClient } from './services/api';

import { App } from './app';
import { BASE_PATH } from '../common/constants/base_path';

import routes from 'ui/routes';
import { MANAGEMENT_BREADCRUMB } from 'ui/management';

import template from './main.html';
import { manageAngularLifecycle } from './lib/manage_angular_lifecycle';
Expand All @@ -35,6 +37,14 @@ const renderReact = async (elem) => {

routes.when(`${BASE_PATH}:view?/:id?`, {
template: template,
k7Breadcrumbs: () => [
MANAGEMENT_BREADCRUMB,
{
text: i18n.translate('xpack.idxMgmt.breadcrumb', {
defaultMessage: 'Index management'
}),
}
],
controllerAs: 'indexManagement',
controller: class IndexManagementController {
constructor($scope, $route, $http) {
Expand Down
32 changes: 32 additions & 0 deletions x-pack/plugins/license_management/public/breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import { MANAGEMENT_BREADCRUMB } from 'ui/management';
import { BASE_PATH } from '../common/constants';

export function getDashboardBreadcrumbs() {
return [
MANAGEMENT_BREADCRUMB,
{
text: i18n.translate('xpack.licenseMgmt.dashboard.breadcrumb', {
defaultMessage: 'License management'
}),
href: `#${BASE_PATH}home`
}
];
}

export function getUploadBreadcrumbs() {
return [
...getDashboardBreadcrumbs(),
{
text: i18n.translate('xpack.licenseMgmt.upload.breadcrumb', {
defaultMessage: 'Upload'
})
}
];
}
13 changes: 12 additions & 1 deletion x-pack/plugins/license_management/public/register_route.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Provider } from 'react-redux';
import { HashRouter } from 'react-router-dom';
import { setTelemetryOptInService, setTelemetryEnabled, setHttpClient, TelemetryOptInProvider } from './lib/telemetry';
import { I18nProvider } from '@kbn/i18n/react';

import chrome from 'ui/chrome';

import App from './app';
import { BASE_PATH } from "../common/constants/base_path";
Expand All @@ -20,6 +20,7 @@ import { XPackInfoProvider as xpackInfoProvider } from 'plugins/xpack_main/servi

import template from './main.html';
import { licenseManagementStore } from './store';
import { getDashboardBreadcrumbs, getUploadBreadcrumbs } from './breadcrumbs';

const renderReact = (elem, store) => {
render(
Expand All @@ -44,6 +45,8 @@ const manageAngularLifecycle = ($scope, $route, elem) => {
const currentRoute = $route.current;
// if templates are the same we are on the same route
if (lastRoute.$$route.template === currentRoute.$$route.template) {
// update the breadcrumbs by re-running the k7Breadcrumbs function
chrome.breadcrumbs.set(currentRoute.$$route.k7Breadcrumbs($route));
// this prevents angular from destroying scope
$route.current = lastRoute;
}
Expand All @@ -65,6 +68,14 @@ const initializeTelemetry = ($injector) => {
routes
.when(`${BASE_PATH}:view?`, {
template: template,
k7Breadcrumbs($route) {
switch ($route.current.params.view) {
case 'upload_license':
return getUploadBreadcrumbs();
default:
return getDashboardBreadcrumbs();
}
},
controllerAs: 'licenseManagement',
controller: class LicenseManagementController {

Expand Down

0 comments on commit 2078beb

Please sign in to comment.