Skip to content

Commit

Permalink
set navlinks in new platform (#66766) (#67029)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored May 20, 2020
1 parent 7a7c9f9 commit e251463
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/plugins/kibana_legacy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { Observable } from 'rxjs';
import { ConfigSchema } from '../config';
import { getDashboardConfig } from './dashboard_config';
import { setStoredNavLinks } from './set_stored_navlinks';

interface ForwardDefinition {
legacyAppId: string;
Expand Down Expand Up @@ -121,7 +122,10 @@ export class KibanaLegacyPlugin {
};
}

public start({ application }: CoreStart) {
public start(core: CoreStart) {
// Set stored nav links for new platform apps. This is a workaround only necessary as long as
// these apps are part of the legacy platform.
setStoredNavLinks(core);
return {
/**
* @deprecated
Expand All @@ -134,7 +138,9 @@ export class KibanaLegacyPlugin {
*/
getForwards: () => this.forwards,
config: this.initializerContext.config.get(),
dashboardConfig: getDashboardConfig(!application.capabilities.dashboard.showWriteControls),
dashboardConfig: getDashboardConfig(
!core.application.capabilities.dashboard.showWriteControls
),
};
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/plugins/kibana_legacy/public/set_stored_navlinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { CoreStart } from 'kibana/public';

export function setStoredNavLinks(core: CoreStart) {
const baseUrl = core.http.basePath.prepend('/app/kibana');
const links = [
{ navLinkId: 'kibana:discover', storageKey: `lastUrl:${core.http.basePath.get()}:discover` },
{ navLinkId: 'kibana:dashboard', storageKey: `lastUrl:${core.http.basePath.get()}:dashboard` },
{ navLinkId: 'kibana:visualize', storageKey: `lastUrl:${core.http.basePath.get()}:visualize` },
];

links.forEach(({ navLinkId, storageKey }) => {
const storedSubUrl = sessionStorage.getItem(storageKey);
if (storedSubUrl) {
core.chrome.navLinks.update(navLinkId, {
url: baseUrl + storedSubUrl,
});
}
});
}

0 comments on commit e251463

Please sign in to comment.