Skip to content

Commit

Permalink
[7.x] Move Nav APIs to new platform (#34490) (#36453)
Browse files Browse the repository at this point in the history
This moves the core Nav APIs from `ui/chrome` into the `ChromeService` in the new platform.

- `ChromeStart` now exposes a sub-service for reading and making limited updates to navlinks. These are powered by apps registered with the `ApplicationService` and filtered by UI Capabilities before being exposed by the `ChromeService`.
- The `header-global-nav` directive now consumes navlinks from the new platform.
- The `lastSubUrl` feature utilized by legacy apps has been refactored and will remain in `ui/chrome`. This feature utilizes the limited fields that `ChromeService` exposes to updates by outside code.

This change is the main blocker to moving the Chrome UI to the new platform. This will be necessary to enable the new platform to control top-level routing.
  • Loading branch information
joshdover authored May 10, 2019
1 parent b19c5ef commit ff2c2c4
Show file tree
Hide file tree
Showing 58 changed files with 1,168 additions and 431 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [active](./kibana-plugin-public.chromenavlink.active.md)

## ChromeNavLink.active property

Indicates whether or not this app is currently on the screen.

NOTE: remove this when ApplicationService is implemented and managing apps.

<b>Signature:</b>

```typescript
readonly active?: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [baseUrl](./kibana-plugin-public.chromenavlink.baseurl.md)

## ChromeNavLink.baseUrl property

The base route used to open the root of an application.

<b>Signature:</b>

```typescript
readonly baseUrl: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [disabled](./kibana-plugin-public.chromenavlink.disabled.md)

## ChromeNavLink.disabled property

Disables a link from being clickable.

NOTE: this is only used by the ML and Graph plugins currently. They use this field to disable the nav link when the license is expired.

<b>Signature:</b>

```typescript
readonly disabled?: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [euiIconType](./kibana-plugin-public.chromenavlink.euiicontype.md)

## ChromeNavLink.euiIconType property

A EUI iconType that will be used for the app's icon. This icon takes precendence over the `icon` property.

<b>Signature:</b>

```typescript
readonly euiIconType?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [hidden](./kibana-plugin-public.chromenavlink.hidden.md)

## ChromeNavLink.hidden property

Hides a link from the navigation.

NOTE: remove this when ApplicationService is implemented. Instead, plugins should only register an Application if needed.

<b>Signature:</b>

```typescript
readonly hidden?: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [icon](./kibana-plugin-public.chromenavlink.icon.md)

## ChromeNavLink.icon property

A URL to an image file used as an icon. Used as a fallback if `euiIconType` is not provided.

<b>Signature:</b>

```typescript
readonly icon?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [id](./kibana-plugin-public.chromenavlink.id.md)

## ChromeNavLink.id property

A unique identifier for looking up links.

<b>Signature:</b>

```typescript
readonly id: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [linkToLastSubUrl](./kibana-plugin-public.chromenavlink.linktolastsuburl.md)

## ChromeNavLink.linkToLastSubUrl property

Whether or not the subUrl feature should be enabled.

NOTE: only read by legacy platform.

<b>Signature:</b>

```typescript
readonly linkToLastSubUrl?: boolean;
```
31 changes: 31 additions & 0 deletions docs/development/core/public/kibana-plugin-public.chromenavlink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md)

## ChromeNavLink interface


<b>Signature:</b>

```typescript
export interface ChromeNavLink
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [active](./kibana-plugin-public.chromenavlink.active.md) | <code>boolean</code> | Indicates whether or not this app is currently on the screen.<!-- -->NOTE: remove this when ApplicationService is implemented and managing apps. |
| [baseUrl](./kibana-plugin-public.chromenavlink.baseurl.md) | <code>string</code> | The base route used to open the root of an application. |
| [disabled](./kibana-plugin-public.chromenavlink.disabled.md) | <code>boolean</code> | Disables a link from being clickable.<!-- -->NOTE: this is only used by the ML and Graph plugins currently. They use this field to disable the nav link when the license is expired. |
| [euiIconType](./kibana-plugin-public.chromenavlink.euiicontype.md) | <code>string</code> | A EUI iconType that will be used for the app's icon. This icon takes precendence over the <code>icon</code> property. |
| [hidden](./kibana-plugin-public.chromenavlink.hidden.md) | <code>boolean</code> | Hides a link from the navigation.<!-- -->NOTE: remove this when ApplicationService is implemented. Instead, plugins should only register an Application if needed. |
| [icon](./kibana-plugin-public.chromenavlink.icon.md) | <code>string</code> | A URL to an image file used as an icon. Used as a fallback if <code>euiIconType</code> is not provided. |
| [id](./kibana-plugin-public.chromenavlink.id.md) | <code>string</code> | A unique identifier for looking up links. |
| [linkToLastSubUrl](./kibana-plugin-public.chromenavlink.linktolastsuburl.md) | <code>boolean</code> | Whether or not the subUrl feature should be enabled.<!-- -->NOTE: only read by legacy platform. |
| [order](./kibana-plugin-public.chromenavlink.order.md) | <code>number</code> | An ordinal used to sort nav links relative to one another for display. |
| [subUrlBase](./kibana-plugin-public.chromenavlink.suburlbase.md) | <code>string</code> | A url base that legacy apps can set to match deep URLs to an applcation.<!-- -->NOTE: this should be removed once legacy apps are gone. |
| [title](./kibana-plugin-public.chromenavlink.title.md) | <code>string</code> | The title of the application. |
| [tooltip](./kibana-plugin-public.chromenavlink.tooltip.md) | <code>string</code> | A tooltip shown when hovering over an app link. |
| [url](./kibana-plugin-public.chromenavlink.url.md) | <code>string</code> | A url that legacy apps can set to deep link into their applications.<!-- -->NOTE: Currently used by the "lastSubUrl" feature legacy/ui/chrome. This should be removed once the ApplicationService is implemented and mounting apps. At that time, each app can handle opening to the previous location when they are mounted. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [order](./kibana-plugin-public.chromenavlink.order.md)

## ChromeNavLink.order property

An ordinal used to sort nav links relative to one another for display.

<b>Signature:</b>

```typescript
readonly order: number;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [subUrlBase](./kibana-plugin-public.chromenavlink.suburlbase.md)

## ChromeNavLink.subUrlBase property

A url base that legacy apps can set to match deep URLs to an applcation.

NOTE: this should be removed once legacy apps are gone.

<b>Signature:</b>

```typescript
readonly subUrlBase?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [title](./kibana-plugin-public.chromenavlink.title.md)

## ChromeNavLink.title property

The title of the application.

<b>Signature:</b>

```typescript
readonly title: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [tooltip](./kibana-plugin-public.chromenavlink.tooltip.md)

## ChromeNavLink.tooltip property

A tooltip shown when hovering over an app link.

<b>Signature:</b>

```typescript
readonly tooltip?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [url](./kibana-plugin-public.chromenavlink.url.md)

## ChromeNavLink.url property

A url that legacy apps can set to deep link into their applications.

NOTE: Currently used by the "lastSubUrl" feature legacy/ui/chrome. This should be removed once the ApplicationService is implemented and mounting apps. At that time, each app can handle opening to the previous location when they are mounted.

<b>Signature:</b>

```typescript
readonly url?: string;
```
12 changes: 12 additions & 0 deletions docs/development/core/public/kibana-plugin-public.chromestart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeStart](./kibana-plugin-public.chromestart.md)

## ChromeStart type


<b>Signature:</b>

```typescript
export declare type ChromeStart = ReturnType<ChromeService['start']>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [CoreStart](./kibana-plugin-public.corestart.md) &gt; [chrome](./kibana-plugin-public.corestart.chrome.md)

## CoreStart.chrome property

[ChromeStart](./kibana-plugin-public.chromestart.md)

<b>Signature:</b>

```typescript
chrome: ChromeStart;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CoreStart
| --- | --- | --- |
| [application](./kibana-plugin-public.corestart.application.md) | <code>ApplicationStart</code> | [ApplicationStart](./kibana-plugin-public.applicationstart.md) |
| [basePath](./kibana-plugin-public.corestart.basepath.md) | <code>BasePathStart</code> | [BasePathStart](./kibana-plugin-public.basepathstart.md) |
| [chrome](./kibana-plugin-public.corestart.chrome.md) | <code>ChromeStart</code> | [ChromeStart](./kibana-plugin-public.chromestart.md) |
| [i18n](./kibana-plugin-public.corestart.i18n.md) | <code>I18nStart</code> | [I18nStart](./kibana-plugin-public.i18nstart.md) |
| [injectedMetadata](./kibana-plugin-public.corestart.injectedmetadata.md) | <code>InjectedMetadataStart</code> | [InjectedMetadataStart](./kibana-plugin-public.injectedmetadatastart.md) |
| [notifications](./kibana-plugin-public.corestart.notifications.md) | <code>NotificationsStart</code> | [NotificationsStart](./kibana-plugin-public.notificationsstart.md) |
Expand Down
2 changes: 2 additions & 0 deletions docs/development/core/public/kibana-plugin-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
| [ChromeBadge](./kibana-plugin-public.chromebadge.md) | |
| [ChromeBrand](./kibana-plugin-public.chromebrand.md) | |
| [ChromeBreadcrumb](./kibana-plugin-public.chromebreadcrumb.md) | |
| [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) | |
| [CoreSetup](./kibana-plugin-public.coresetup.md) | Core services exposed to the start lifecycle |
| [CoreStart](./kibana-plugin-public.corestart.md) | |
| [FatalErrorsSetup](./kibana-plugin-public.fatalerrorssetup.md) | FatalErrors stop the Kibana Public Core and displays a fatal error screen with details about the Kibana build and the error. |
Expand All @@ -43,6 +44,7 @@
| [BasePathStart](./kibana-plugin-public.basepathstart.md) | Provides access to the 'server.basePath' configuration option in kibana.yml |
| [ChromeHelpExtension](./kibana-plugin-public.chromehelpextension.md) | |
| [ChromeSetup](./kibana-plugin-public.chromesetup.md) | |
| [ChromeStart](./kibana-plugin-public.chromestart.md) | |
| [HttpSetup](./kibana-plugin-public.httpsetup.md) | |
| [I18nStart](./kibana-plugin-public.i18nstart.md) | |
| [InjectedMetadataStart](./kibana-plugin-public.injectedmetadatastart.md) | |
Expand Down
4 changes: 2 additions & 2 deletions src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export interface App extends BaseApp {
/** @internal */
export interface LegacyApp extends BaseApp {
appUrl: string;

url?: string;
subUrlBase?: string;
linkToLastSubUrl?: boolean;
}

/** @internal */
Expand Down
18 changes: 18 additions & 0 deletions src/core/public/chrome/chrome_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
ChromeBreadcrumb,
ChromeService,
ChromeSetup,
ChromeStart,
} from './chrome_service';

const createSetupContractMock = () => {
Expand Down Expand Up @@ -53,17 +54,34 @@ const createSetupContractMock = () => {
return setupContract;
};

const createStartContractMock = (): jest.Mocked<ChromeStart> => ({
navLinks: {
getNavLinks$: jest.fn(),
clear: jest.fn(),
has: jest.fn(),
get: jest.fn(),
getAll: jest.fn(),
showOnly: jest.fn(),
update: jest.fn(),
enableForcedAppSwitcherNavigation: jest.fn(),
getForceAppSwitcherNavigation$: jest.fn(),
},
});

type ChromeServiceContract = PublicMethodsOf<ChromeService>;
const createMock = () => {
const mocked: jest.Mocked<ChromeServiceContract> = {
setup: jest.fn(),
start: jest.fn(),
stop: jest.fn(),
};
mocked.setup.mockReturnValue(createSetupContractMock());
mocked.start.mockReturnValue(createStartContractMock());
return mocked;
};

export const chromeServiceMock = {
create: createMock,
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
};
20 changes: 19 additions & 1 deletion src/core/public/chrome/chrome_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import { map, takeUntil } from 'rxjs/operators';
import { IconType } from '@elastic/eui';
import { InjectedMetadataSetup } from '../injected_metadata';
import { NotificationsSetup } from '../notifications';
import { NavLinksService } from './nav_links/nav_links_service';
import { ApplicationStart } from '../application';
import { BasePathStart } from '../base_path';

const IS_COLLAPSED_KEY = 'core.chrome.isCollapsed';

Expand Down Expand Up @@ -65,10 +68,16 @@ interface SetupDeps {
notifications: NotificationsSetup;
}

interface StartDeps {
application: ApplicationStart;
basePath: BasePathStart;
}

/** @internal */
export class ChromeService {
private readonly stop$ = new Rx.ReplaySubject(1);
private readonly browserSupportsCsp: boolean;
private readonly navLinks = new NavLinksService();

public constructor({ browserSupportsCsp }: ConstructorParams) {
this.browserSupportsCsp = browserSupportsCsp;
Expand Down Expand Up @@ -183,7 +192,6 @@ export class ChromeService {
map(set => [...set]),
takeUntil(this.stop$)
),

/**
* Get an observable of the current badge
*/
Expand Down Expand Up @@ -222,10 +230,20 @@ export class ChromeService {
};
}

public start({ application, basePath }: StartDeps) {
return {
navLinks: this.navLinks.start({ application, basePath }),
};
}

public stop() {
this.navLinks.stop();
this.stop$.next();
}
}

/** @public */
export type ChromeSetup = ReturnType<ChromeService['setup']>;

/** @public */
export type ChromeStart = ReturnType<ChromeService['start']>;
2 changes: 2 additions & 0 deletions src/core/public/chrome/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export {
ChromeBreadcrumb,
ChromeService,
ChromeSetup,
ChromeStart,
ChromeBrand,
ChromeHelpExtension,
} from './chrome_service';
export { ChromeNavLink } from './nav_links';
Loading

0 comments on commit ff2c2c4

Please sign in to comment.