Skip to content

Commit

Permalink
Locator for console app (#110116)
Browse files Browse the repository at this point in the history
Add a locator for the console and use it in home and overview.

Fix a bug where the dev tools and management links were not showing on the analytics overview page:

Since the locator's getUrl method is async, pass in the URLs as props into the right side items instead of passing in basePath and hard-coding them.

Add RedirectAppLinks to inspector plugin so we don't have to have an onClick handler for the console link.

Fixes #110076.
  • Loading branch information
smith authored Aug 30, 2021
1 parent 22e5565 commit f875a5b
Show file tree
Hide file tree
Showing 30 changed files with 435 additions and 141 deletions.
2 changes: 1 addition & 1 deletion src/plugins/console/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Stack Management",
"githubTeam": "kibana-stack-management"
},
"requiredPlugins": ["devTools"],
"requiredPlugins": ["devTools", "share"],
"optionalPlugins": ["usageCollection", "home"],
"requiredBundles": ["esUiShared", "kibanaReact", "kibanaUtils", "home"]
}
2 changes: 2 additions & 0 deletions src/plugins/console/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import './index.scss';

import { ConsoleUIPlugin } from './plugin';

export type { ConsoleUILocatorParams } from './plugin';

export { ConsoleUIPlugin as Plugin };

export function plugin() {
Expand Down
20 changes: 19 additions & 1 deletion src/plugins/console/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
*/

import { i18n } from '@kbn/i18n';
import { SerializableRecord } from '@kbn/utility-types';
import { Plugin, CoreSetup } from 'src/core/public';

import { FeatureCatalogueCategory } from '../../home/public';
import { AppSetupUIPluginDependencies } from './types';

export interface ConsoleUILocatorParams extends SerializableRecord {
loadFrom?: string;
}

export class ConsoleUIPlugin implements Plugin<void, void, AppSetupUIPluginDependencies> {
public setup(
{ notifications, getStartServices, http }: CoreSetup,
{ devTools, home, usageCollection }: AppSetupUIPluginDependencies
{ devTools, home, share, usageCollection }: AppSetupUIPluginDependencies
) {
if (home) {
home.featureCatalogue.register({
Expand Down Expand Up @@ -60,6 +65,19 @@ export class ConsoleUIPlugin implements Plugin<void, void, AppSetupUIPluginDepen
});
},
});

const locator = share.url.locators.create<ConsoleUILocatorParams>({
id: 'CONSOLE_APP_LOCATOR',
getLocation: async ({ loadFrom }) => {
return {
app: 'dev_tools',
path: `#/console${loadFrom ? `?load_from=${loadFrom}` : ''}`,
state: { loadFrom },
};
},
});

return { locator };
}

public start() {}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/console/public/types/plugin_dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import { HomePublicPluginSetup } from '../../../home/public';
import { DevToolsSetup } from '../../../dev_tools/public';
import { UsageCollectionSetup } from '../../../usage_collection/public';
import { SharePluginSetup } from '../../../share/public';

export interface AppSetupUIPluginDependencies {
home?: HomePublicPluginSetup;
devTools: DevToolsSetup;
share: SharePluginSetup;
usageCollection?: UsageCollectionSetup;
}
3 changes: 2 additions & 1 deletion src/plugins/console/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{ "path": "../home/tsconfig.json" },
{ "path": "../kibana_react/tsconfig.json" },
{ "path": "../kibana_utils/tsconfig.json" },
{ "path": "../usage_collection/tsconfig.json" },
{ "path": "../share/tsconfig.json" },
{ "path": "../usage_collection/tsconfig.json" }
]
}
6 changes: 2 additions & 4 deletions src/plugins/home/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"version": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["data", "urlForwarding"],
"requiredPlugins": ["data", "share", "urlForwarding"],
"optionalPlugins": ["usageCollection", "telemetry"],
"requiredBundles": [
"kibanaReact"
]
"requiredBundles": ["kibanaReact"]
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jest.mock('../app_navigation_handler', () => {

jest.mock('../../kibana_services', () => ({
getServices: () => ({
share: { url: { locators: { get: () => ({ useUrl: () => '' }) } } },
trackUiMetric: jest.fn(),
}),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ interface Props {
}

export const ManageData: FC<Props> = ({ addBasePath, application, features }) => {
if (features.length) {
const { trackUiMetric } = getServices();
const { share, trackUiMetric } = getServices();
const consoleHref = share.url.locators.get('CONSOLE_APP_LOCATOR')?.useUrl({});
const managementHref = share.url.locators
.get('MANAGEMENT_APP_LOCATOR')
?.useUrl({ sectionId: '' });

if (features.length) {
const {
management: isManagementEnabled,
dev_tools: isDevToolsEnabled,
Expand Down Expand Up @@ -67,7 +71,7 @@ export const ManageData: FC<Props> = ({ addBasePath, application, features }) =>
className="kbnOverviewPageHeader__actionButton"
flush="both"
iconType="wrench"
href={addBasePath('/app/dev_tools#/console')}
href={consoleHref}
>
<FormattedMessage
id="home.manageData.devToolsButtonLabel"
Expand All @@ -86,7 +90,7 @@ export const ManageData: FC<Props> = ({ addBasePath, application, features }) =>
className="kbnOverviewPageHeader__actionButton"
flush="both"
iconType="gear"
href={addBasePath('/app/management')}
href={managementHref}
>
<FormattedMessage
id="home.manageData.stackManagementButtonLabel"
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/home/public/application/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import { AddDataService } from '../services/add_data';
import { FeatureCatalogueRegistry } from '../services/feature_catalogue';
import { EnvironmentService } from '../services/environment';
import { ConfigSchema } from '../../config';
import { SharePluginSetup } from '../../../share/public';

export interface HomeKibanaServices {
indexPatternService: any;
kibanaVersion: string;
share: SharePluginSetup;
chrome: ChromeStart;
application: ApplicationStart;
uiSettings: IUiSettingsClient;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/home/public/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { registryMock, environmentMock, tutorialMock } from './plugin.test.mocks
import { HomePublicPlugin } from './plugin';
import { coreMock } from '../../../core/public/mocks';
import { urlForwardingPluginMock } from '../../url_forwarding/public/mocks';
import { SharePluginSetup } from '../../share/public';

const mockInitializerContext = coreMock.createPluginInitializerContext();
const mockShare = {} as SharePluginSetup;

describe('HomePublicPlugin', () => {
beforeEach(() => {
Expand All @@ -26,6 +28,7 @@ describe('HomePublicPlugin', () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
Expand All @@ -45,6 +48,7 @@ describe('HomePublicPlugin', () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
Expand All @@ -56,6 +60,7 @@ describe('HomePublicPlugin', () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: {} as SharePluginSetup,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
Expand All @@ -67,6 +72,7 @@ describe('HomePublicPlugin', () => {
const setup = await new HomePublicPlugin(mockInitializerContext).setup(
coreMock.createSetup() as any,
{
share: mockShare,
urlForwarding: urlForwardingPluginMock.createSetupContract(),
}
);
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { UsageCollectionSetup } from '../../usage_collection/public';
import { UrlForwardingSetup, UrlForwardingStart } from '../../url_forwarding/public';
import { AppNavLinkStatus } from '../../../core/public';
import { PLUGIN_ID, HOME_APP_BASE_PATH } from '../common/constants';
import { SharePluginSetup } from '../../share/public';

export interface HomePluginStartDependencies {
data: DataPublicPluginStart;
Expand All @@ -43,6 +44,7 @@ export interface HomePluginStartDependencies {
}

export interface HomePluginSetupDependencies {
share: SharePluginSetup;
usageCollection?: UsageCollectionSetup;
urlForwarding: UrlForwardingSetup;
}
Expand All @@ -64,7 +66,7 @@ export class HomePublicPlugin

public setup(
core: CoreSetup<HomePluginStartDependencies>,
{ urlForwarding, usageCollection }: HomePluginSetupDependencies
{ share, urlForwarding, usageCollection }: HomePluginSetupDependencies
): HomePublicPluginSetup {
core.application.register({
id: PLUGIN_ID,
Expand All @@ -79,6 +81,7 @@ export class HomePublicPlugin
{ telemetry, data, urlForwarding: urlForwardingStart },
] = await core.getStartServices();
setServices({
share,
trackUiMetric,
kibanaVersion: this.initializerContext.env.packageInfo.version,
http: coreStart.http,
Expand Down
10 changes: 3 additions & 7 deletions src/plugins/home/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@
"declarationMap": true,
"isolatedModules": true
},
"include": [
"common/**/*",
"public/**/*",
"server/**/*",
"config.ts",
],
"include": ["common/**/*", "public/**/*", "server/**/*", "config.ts"],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../data/tsconfig.json" },
{ "path": "../kibana_react/tsconfig.json" },
{ "path": "../share/tsconfig.json" },
{ "path": "../url_forwarding/tsconfig.json" },
{ "path": "../usage_collection/tsconfig.json" },
{ "path": "../telemetry/tsconfig.json" },
{ "path": "../telemetry/tsconfig.json" }
]
}
3 changes: 2 additions & 1 deletion src/plugins/inspector/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"githubTeam": "kibana-app-services"
},
"extraPublicDirs": ["common", "common/adapters/request"],
"requiredBundles": ["kibanaReact"]
"requiredBundles": ["kibanaReact"],
"requiredPlugins": ["share"]
}
4 changes: 3 additions & 1 deletion src/plugins/inspector/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Setup as PluginSetup, Start as PluginStart } from '.';
import { InspectorViewRegistry } from './view_registry';
import { plugin as pluginInitializer } from '.';
import { coreMock } from '../../../core/public/mocks';
import type { SharePluginStart } from '../../share/public';

export type Setup = jest.Mocked<PluginSetup>;
export type Start = jest.Mocked<PluginStart>;
Expand Down Expand Up @@ -48,14 +49,15 @@ const createPlugin = async () => {
const coreStart = coreMock.createStart();
const plugin = pluginInitializer(pluginInitializerContext);
const setup = await plugin.setup(coreSetup);
const share = {} as SharePluginStart;

return {
pluginInitializerContext,
coreSetup,
coreStart,
plugin,
setup,
doStart: async () => await plugin.start(coreStart),
doStart: async () => await plugin.start(coreStart, { share }),
};
};

Expand Down
8 changes: 7 additions & 1 deletion src/plugins/inspector/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ import { i18n } from '@kbn/i18n';
import * as React from 'react';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '../../../core/public';
import { toMountPoint } from '../../kibana_react/public';
import { SharePluginStart } from '../../share/public';
import { InspectorViewRegistry } from './view_registry';
import { InspectorOptions, InspectorSession } from './types';
import { InspectorPanel } from './ui/inspector_panel';
import { Adapters } from '../common';

import { getRequestsViewDescription } from './views';

export interface InspectorPluginStartDeps {
share: SharePluginStart;
}

export interface Setup {
registerView: InspectorViewRegistry['register'];

Expand Down Expand Up @@ -70,7 +75,7 @@ export class InspectorPublicPlugin implements Plugin<Setup, Start> {
};
}

public start(core: CoreStart) {
public start(core: CoreStart, startDeps: InspectorPluginStartDeps) {
const isAvailable: Start['isAvailable'] = (adapters) =>
this.views!.getVisible(adapters).length > 0;

Expand Down Expand Up @@ -99,6 +104,7 @@ export class InspectorPublicPlugin implements Plugin<Setup, Start> {
application: core.application,
http: core.http,
uiSettings: core.uiSettings,
share: startDeps.share,
}}
/>
),
Expand Down
Loading

0 comments on commit f875a5b

Please sign in to comment.