mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Uptime] Add locator to aid other plugins in linking properly to Uptime (#123004)
* Implement locator for Uptime Overview page. * Give more descriptive name to locator ID const. * Lazy load locator init code to reduce bundle size.
This commit is contained in:
parent
600abd7535
commit
af78c358d5
7 changed files with 100 additions and 28 deletions
|
@ -24,3 +24,7 @@ export const observabilityFeatureId = 'observability';
|
|||
|
||||
// Used by Cases to install routes
|
||||
export const casesPath = '/cases';
|
||||
|
||||
// Name of a locator created by the uptime plugin. Intended for use
|
||||
// by other plugins as well, so defined here to prevent cross-references.
|
||||
export const uptimeOverviewLocatorID = 'uptime-overview-locator';
|
||||
|
|
|
@ -24,6 +24,7 @@ export type {
|
|||
ObservabilityPublicPluginsStart,
|
||||
};
|
||||
export { enableInspectEsQueries } from '../common/ui_settings_keys';
|
||||
export { uptimeOverviewLocatorID } from '../common';
|
||||
|
||||
export interface ConfigSchema {
|
||||
unsafe: {
|
||||
|
|
|
@ -1,43 +1,27 @@
|
|||
{
|
||||
"configPath": [
|
||||
"xpack",
|
||||
"uptime"
|
||||
],
|
||||
"configPath": ["xpack", "uptime"],
|
||||
"id": "uptime",
|
||||
"kibanaVersion": "kibana",
|
||||
"optionalPlugins": [
|
||||
"cloud",
|
||||
"data",
|
||||
"fleet",
|
||||
"home",
|
||||
"ml"
|
||||
],
|
||||
"optionalPlugins": ["cloud", "data", "fleet", "home", "ml"],
|
||||
"requiredPlugins": [
|
||||
"alerting",
|
||||
"embeddable",
|
||||
"encryptedSavedObjects",
|
||||
"inspector",
|
||||
"features",
|
||||
"inspector",
|
||||
"licensing",
|
||||
"observability",
|
||||
"ruleRegistry",
|
||||
"security",
|
||||
"share",
|
||||
"taskManager",
|
||||
"triggersActionsUi",
|
||||
"usageCollection",
|
||||
"taskManager"
|
||||
"usageCollection"
|
||||
],
|
||||
"server": true,
|
||||
"ui": true,
|
||||
"version": "8.0.0",
|
||||
"requiredBundles": [
|
||||
"observability",
|
||||
"kibanaReact",
|
||||
"kibanaUtils",
|
||||
"home",
|
||||
"data",
|
||||
"ml",
|
||||
"fleet"
|
||||
],
|
||||
"requiredBundles": ["data", "fleet", "home", "kibanaReact", "kibanaUtils", "ml", "observability"],
|
||||
"owner": {
|
||||
"name": "Uptime",
|
||||
"githubTeam": "uptime"
|
||||
|
|
41
x-pack/plugins/uptime/public/apps/locators/overview.test.ts
Normal file
41
x-pack/plugins/uptime/public/apps/locators/overview.test.ts
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { OVERVIEW_ROUTE } from '../../../common/constants';
|
||||
import { uptimeOverviewNavigatorParams } from './overview';
|
||||
|
||||
describe('uptimeOverviewNavigatorParams', () => {
|
||||
it('supplies the correct app name', async () => {
|
||||
const location = await uptimeOverviewNavigatorParams.getLocation({});
|
||||
expect(location.app).toEqual('uptime');
|
||||
});
|
||||
|
||||
it('creates the expected path when no params specified', async () => {
|
||||
const location = await uptimeOverviewNavigatorParams.getLocation({});
|
||||
expect(location.path).toEqual(OVERVIEW_ROUTE);
|
||||
});
|
||||
|
||||
it('creates a path with expected search when ip is specified', async () => {
|
||||
const location = await uptimeOverviewNavigatorParams.getLocation({ ip: '127.0.0.1' });
|
||||
expect(location.path).toEqual(`${OVERVIEW_ROUTE}?search=monitor.ip: "127.0.0.1"`);
|
||||
});
|
||||
|
||||
it('creates a path with expected search when hostname is specified', async () => {
|
||||
const location = await uptimeOverviewNavigatorParams.getLocation({ hostname: 'elastic.co' });
|
||||
expect(location.path).toEqual(`${OVERVIEW_ROUTE}?search=url.domain: "elastic.co"`);
|
||||
});
|
||||
|
||||
it('creates a path with expected search when multiple keys are specified', async () => {
|
||||
const location = await uptimeOverviewNavigatorParams.getLocation({
|
||||
hostname: 'elastic.co',
|
||||
ip: '127.0.0.1',
|
||||
});
|
||||
expect(location.path).toEqual(
|
||||
`${OVERVIEW_ROUTE}?search=monitor.ip: "127.0.0.1" OR url.domain: "elastic.co"`
|
||||
);
|
||||
});
|
||||
});
|
34
x-pack/plugins/uptime/public/apps/locators/overview.ts
Normal file
34
x-pack/plugins/uptime/public/apps/locators/overview.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import { uptimeOverviewLocatorID } from '../../../../observability/public';
|
||||
import { OVERVIEW_ROUTE } from '../../../common/constants';
|
||||
|
||||
const formatSearchKey = (key: string, value: string) => `${key}: "${value}"`;
|
||||
|
||||
async function navigate({ ip, hostname }: { ip?: string; hostname?: string }) {
|
||||
const searchParams: string[] = [];
|
||||
|
||||
if (ip) searchParams.push(formatSearchKey('monitor.ip', ip));
|
||||
if (hostname) searchParams.push(formatSearchKey('url.domain', hostname));
|
||||
|
||||
const searchString = searchParams.join(' OR ');
|
||||
|
||||
const path =
|
||||
searchParams.length === 0 ? OVERVIEW_ROUTE : OVERVIEW_ROUTE + `?search=${searchString}`;
|
||||
|
||||
return {
|
||||
app: 'uptime',
|
||||
path,
|
||||
state: {},
|
||||
};
|
||||
}
|
||||
|
||||
export const uptimeOverviewNavigatorParams = {
|
||||
id: uptimeOverviewLocatorID,
|
||||
getLocation: navigate,
|
||||
};
|
|
@ -4,6 +4,7 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
|
||||
import {
|
||||
CoreSetup,
|
||||
CoreStart,
|
||||
|
@ -14,6 +15,7 @@ import {
|
|||
import { from } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { SharePluginSetup, SharePluginStart } from '../../../../../src/plugins/share/public';
|
||||
import { DEFAULT_APP_CATEGORIES } from '../../../../../src/core/public';
|
||||
|
||||
import {
|
||||
|
@ -29,6 +31,7 @@ import {
|
|||
DataPublicPluginSetup,
|
||||
DataPublicPluginStart,
|
||||
} from '../../../../../src/plugins/data/public';
|
||||
|
||||
import { alertTypeInitializers, legacyAlertTypeInitializers } from '../lib/alert_types';
|
||||
import { FleetStart } from '../../../fleet/public';
|
||||
import {
|
||||
|
@ -47,19 +50,21 @@ import { Start as InspectorPluginStart } from '../../../../../src/plugins/inspec
|
|||
import { UptimeUiConfig } from '../../common/config';
|
||||
|
||||
export interface ClientPluginsSetup {
|
||||
data: DataPublicPluginSetup;
|
||||
home?: HomePublicPluginSetup;
|
||||
data: DataPublicPluginSetup;
|
||||
observability: ObservabilityPublicSetup;
|
||||
share: SharePluginSetup;
|
||||
triggersActionsUi: TriggersAndActionsUIPublicPluginSetup;
|
||||
}
|
||||
|
||||
export interface ClientPluginsStart {
|
||||
embeddable: EmbeddableStart;
|
||||
data: DataPublicPluginStart;
|
||||
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
|
||||
fleet?: FleetStart;
|
||||
observability: ObservabilityPublicStart;
|
||||
data: DataPublicPluginStart;
|
||||
inspector: InspectorPluginStart;
|
||||
embeddable: EmbeddableStart;
|
||||
observability: ObservabilityPublicStart;
|
||||
share: SharePluginStart;
|
||||
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
|
||||
}
|
||||
|
||||
export interface UptimePluginServices extends Partial<CoreStart> {
|
||||
|
|
|
@ -18,6 +18,7 @@ import {
|
|||
import { UptimeApp, UptimeAppProps } from './uptime_app';
|
||||
import { ClientPluginsSetup, ClientPluginsStart } from './plugin';
|
||||
import { UptimeUiConfig } from '../../common/config';
|
||||
import { uptimeOverviewNavigatorParams } from './locators/overview';
|
||||
|
||||
export function renderApp(
|
||||
core: CoreStart,
|
||||
|
@ -41,6 +42,8 @@ export function renderApp(
|
|||
|
||||
const canSave = (capabilities.uptime.save ?? false) as boolean;
|
||||
|
||||
plugins.share.url.locators.create(uptimeOverviewNavigatorParams);
|
||||
|
||||
const props: UptimeAppProps = {
|
||||
plugins,
|
||||
canSave,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue