Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper and utilities around EuiThemeProvider #117368

Merged
merged 35 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b103d39
draft implementation
pgayvallet Nov 3, 2021
72eeac4
refactor and do not use COLOR_MODES_STANDARD
pgayvallet Nov 4, 2021
4ea2628
plug CoreThemeProvider to rendering service
pgayvallet Nov 4, 2021
a6351ee
plug CoreThemeProvider to toast service
pgayvallet Nov 4, 2021
9a235b9
plug CoreThemeProvider to overlay service
pgayvallet Nov 4, 2021
941ccb3
adapt tests
pgayvallet Nov 4, 2021
c324a6c
adapt application tests
pgayvallet Nov 4, 2021
77c8068
adapt core apps
pgayvallet Nov 4, 2021
0333d1f
fix tests and snapshots
pgayvallet Nov 4, 2021
2613db9
fix types
pgayvallet Nov 4, 2021
b20bb4a
fix setup mock
pgayvallet Nov 4, 2021
74ee533
fix more types
pgayvallet Nov 4, 2021
17044c5
add theme support to `toMountPoint`
pgayvallet Nov 5, 2021
2b67354
add theme start to public API
pgayvallet Nov 5, 2021
26bf7c8
fix integration test
pgayvallet Nov 5, 2021
31fe82e
Merge remote-tracking branch 'upstream/main' into kbn-108972-kibana-t…
pgayvallet Nov 8, 2021
9dc6c50
self-review, first batch
pgayvallet Nov 8, 2021
be04814
self-review, second batch
pgayvallet Nov 8, 2021
d4aec89
add tests for core theme provider
pgayvallet Nov 8, 2021
25dae34
add theme service tests
pgayvallet Nov 8, 2021
322e357
add more tests
pgayvallet Nov 8, 2021
e422e70
add test for to_mount_point
pgayvallet Nov 8, 2021
a6a360f
Merge remote-tracking branch 'upstream/main' into kbn-108972-kibana-t…
pgayvallet Nov 8, 2021
89713bf
update generated doc
pgayvallet Nov 8, 2021
9861131
fix type in story file
pgayvallet Nov 8, 2021
0225446
fix type in fleet story context
pgayvallet Nov 8, 2021
27c0665
Merge branch 'main' into kbn-108972-kibana-theme-provider
kibanamachine Nov 8, 2021
22719be
Merge branch 'main' into kbn-108972-kibana-theme-provider
kibanamachine Nov 9, 2021
6762b3d
use proper theme$ for devtool's mount
pgayvallet Nov 9, 2021
04d1d5f
Merge remote-tracking branch 'upstream/main' into kbn-108972-kibana-t…
pgayvallet Nov 11, 2021
2a948ed
Merge remote-tracking branch 'upstream/main' into kbn-108972-kibana-t…
pgayvallet Nov 16, 2021
3fd5e28
update generated doc
pgayvallet Nov 16, 2021
ba879be
review comments
pgayvallet Nov 16, 2021
3a23426
introduce CoreContextProvider
pgayvallet Nov 16, 2021
f620cff
Merge remote-tracking branch 'upstream/main' into kbn-108972-kibana-t…
pgayvallet Nov 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface AppMountParameters<HistoryLocationState = unknown>
| [history](./kibana-plugin-core-public.appmountparameters.history.md) | ScopedHistory&lt;HistoryLocationState&gt; | A scoped history instance for your application. Should be used to wire up your applications Router. |
| [onAppLeave](./kibana-plugin-core-public.appmountparameters.onappleave.md) | (handler: AppLeaveHandler) =&gt; void | A function that can be used to register a handler that will be called when the user is leaving the current application, allowing to prompt a confirmation message before actually changing the page.<!-- -->This will be called either when the user goes to another application, or when trying to close the tab or manually changing the url. |
| [setHeaderActionMenu](./kibana-plugin-core-public.appmountparameters.setheaderactionmenu.md) | (menuMount: MountPoint \| undefined) =&gt; void | A function that can be used to set the mount point used to populate the application action container in the chrome header.<!-- -->Calling the handler multiple time will erase the current content of the action menu with the mount from the latest call. Calling the handler with <code>undefined</code> will unmount the current mount point. Calling the handler after the application has been unmounted will have no effect. |
| [theme$](./kibana-plugin-core-public.appmountparameters.theme_.md) | Observable&lt;CoreTheme&gt; | An observable emitting [Core's theme](./kibana-plugin-core-public.coretheme.md)<!-- -->. Should be used when mounting the application to include theme information. |

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

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) &gt; [theme$](./kibana-plugin-core-public.appmountparameters.theme_.md)

## AppMountParameters.theme$ property

An observable emitting [Core's theme](./kibana-plugin-core-public.coretheme.md)<!-- -->. Should be used when mounting the application to include theme information.

<b>Signature:</b>

```typescript
theme$: Observable<CoreTheme>;
```

## Example

When mounting a react application:

```ts
// application.tsx
import React from 'react';
import ReactDOM from 'react-dom';

import { AppMountParameters } from 'src/core/public';
import { wrapWithTheme } from 'src/plugins/kibana_react';
import { MyApp } from './app';

export renderApp = ({ element, theme$ }: AppMountParameters) => {
ReactDOM.render(wrapWithTheme(<MyApp/>, theme$), element);
return () => ReactDOM.unmountComponentAtNode(element);
}
```

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
| [http](./kibana-plugin-core-public.coresetup.http.md) | HttpSetup | [HttpSetup](./kibana-plugin-core-public.httpsetup.md) |
| [injectedMetadata](./kibana-plugin-core-public.coresetup.injectedmetadata.md) | { getInjectedVar: (name: string, defaultValue?: any) =&gt; unknown; } | exposed temporarily until https://github.com/elastic/kibana/issues/41990 done use \*only\* to retrieve config values. There is no way to set injected values in the new platform. |
| [notifications](./kibana-plugin-core-public.coresetup.notifications.md) | NotificationsSetup | [NotificationsSetup](./kibana-plugin-core-public.notificationssetup.md) |
| [theme](./kibana-plugin-core-public.coresetup.theme.md) | ThemeServiceSetup | [ThemeServiceSetup](./kibana-plugin-core-public.themeservicesetup.md) |
| [uiSettings](./kibana-plugin-core-public.coresetup.uisettings.md) | IUiSettingsClient | [IUiSettingsClient](./kibana-plugin-core-public.iuisettingsclient.md) |

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.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [CoreSetup](./kibana-plugin-core-public.coresetup.md) &gt; [theme](./kibana-plugin-core-public.coresetup.theme.md)

## CoreSetup.theme property

[ThemeServiceSetup](./kibana-plugin-core-public.themeservicesetup.md)

<b>Signature:</b>

```typescript
theme: ThemeServiceSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ export interface CoreStart
| [notifications](./kibana-plugin-core-public.corestart.notifications.md) | NotificationsStart | [NotificationsStart](./kibana-plugin-core-public.notificationsstart.md) |
| [overlays](./kibana-plugin-core-public.corestart.overlays.md) | OverlayStart | [OverlayStart](./kibana-plugin-core-public.overlaystart.md) |
| [savedObjects](./kibana-plugin-core-public.corestart.savedobjects.md) | SavedObjectsStart | [SavedObjectsStart](./kibana-plugin-core-public.savedobjectsstart.md) |
| [theme](./kibana-plugin-core-public.corestart.theme.md) | ThemeServiceStart | [ThemeServiceStart](./kibana-plugin-core-public.themeservicestart.md) |
| [uiSettings](./kibana-plugin-core-public.corestart.uisettings.md) | IUiSettingsClient | [IUiSettingsClient](./kibana-plugin-core-public.iuisettingsclient.md) |

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.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [CoreStart](./kibana-plugin-core-public.corestart.md) &gt; [theme](./kibana-plugin-core-public.corestart.theme.md)

## CoreStart.theme property

[ThemeServiceStart](./kibana-plugin-core-public.themeservicestart.md)

<b>Signature:</b>

```typescript
theme: ThemeServiceStart;
```
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.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [CoreTheme](./kibana-plugin-core-public.coretheme.md) &gt; [darkMode](./kibana-plugin-core-public.coretheme.darkmode.md)

## CoreTheme.darkMode property

is dark mode enabled or not

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [CoreTheme](./kibana-plugin-core-public.coretheme.md)

## CoreTheme interface

Contains all the required information to apply Kibana's theme at the various levels it can be used.

<b>Signature:</b>

```typescript
export interface CoreTheme
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [darkMode](./kibana-plugin-core-public.coretheme.darkmode.md) | boolean | is dark mode enabled or not |

3 changes: 3 additions & 0 deletions docs/development/core/public/kibana-plugin-core-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ChromeUserBanner](./kibana-plugin-core-public.chromeuserbanner.md) | |
| [CoreSetup](./kibana-plugin-core-public.coresetup.md) | Core services exposed to the <code>Plugin</code> setup lifecycle |
| [CoreStart](./kibana-plugin-core-public.corestart.md) | Core services exposed to the <code>Plugin</code> start lifecycle |
| [CoreTheme](./kibana-plugin-core-public.coretheme.md) | Contains all the required information to apply Kibana's theme at the various levels it can be used. |
| [DeprecationsServiceStart](./kibana-plugin-core-public.deprecationsservicestart.md) | DeprecationsService provides methods to fetch domain deprecation details from the Kibana server. |
| [DocLinksStart](./kibana-plugin-core-public.doclinksstart.md) | |
| [ErrorToastOptions](./kibana-plugin-core-public.errortoastoptions.md) | Options available for [IToasts](./kibana-plugin-core-public.itoasts.md) error APIs. |
Expand Down Expand Up @@ -131,6 +132,8 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SavedObjectsResolveResponse](./kibana-plugin-core-public.savedobjectsresolveresponse.md) | |
| [SavedObjectsStart](./kibana-plugin-core-public.savedobjectsstart.md) | |
| [SavedObjectsUpdateOptions](./kibana-plugin-core-public.savedobjectsupdateoptions.md) | |
| [ThemeServiceSetup](./kibana-plugin-core-public.themeservicesetup.md) | |
| [ThemeServiceStart](./kibana-plugin-core-public.themeservicestart.md) | |
| [ToastOptions](./kibana-plugin-core-public.toastoptions.md) | Options available for [IToasts](./kibana-plugin-core-public.itoasts.md) APIs. |
| [UiSettingsParams](./kibana-plugin-core-public.uisettingsparams.md) | UiSettings parameters defined by the plugins. |
| [UiSettingsState](./kibana-plugin-core-public.uisettingsstate.md) | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ThemeServiceSetup](./kibana-plugin-core-public.themeservicesetup.md)

## ThemeServiceSetup interface


<b>Signature:</b>

```typescript
export interface ThemeServiceSetup
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [theme$](./kibana-plugin-core-public.themeservicesetup.theme_.md) | Observable&lt;CoreTheme&gt; | |

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

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ThemeServiceSetup](./kibana-plugin-core-public.themeservicesetup.md) &gt; [theme$](./kibana-plugin-core-public.themeservicesetup.theme_.md)

## ThemeServiceSetup.theme$ property

<b>Signature:</b>

```typescript
theme$: Observable<CoreTheme>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ThemeServiceStart](./kibana-plugin-core-public.themeservicestart.md)

## ThemeServiceStart interface


<b>Signature:</b>

```typescript
export interface ThemeServiceStart
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [theme$](./kibana-plugin-core-public.themeservicestart.theme_.md) | Observable&lt;CoreTheme&gt; | |

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

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [ThemeServiceStart](./kibana-plugin-core-public.themeservicestart.md) &gt; [theme$](./kibana-plugin-core-public.themeservicestart.theme_.md)

## ThemeServiceStart.theme$ property

<b>Signature:</b>

```typescript
theme$: Observable<CoreTheme>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Collect gathers event loop delays metrics from nodejs perf\_hooks.monitorEventLoopDelay the histogram calculations start from the last time `reset` was called or this EventLoopDelaysMonitor instance was created.

Returns metrics in milliseconds.

<b>Signature:</b>

```typescript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export declare class EventLoopDelaysMonitor

| Method | Modifiers | Description |
| --- | --- | --- |
| [collect()](./kibana-plugin-core-server.eventloopdelaysmonitor.collect.md) | | Collect gathers event loop delays metrics from nodejs perf\_hooks.monitorEventLoopDelay the histogram calculations start from the last time <code>reset</code> was called or this EventLoopDelaysMonitor instance was created. |
| [collect()](./kibana-plugin-core-server.eventloopdelaysmonitor.collect.md) | | Collect gathers event loop delays metrics from nodejs perf\_hooks.monitorEventLoopDelay the histogram calculations start from the last time <code>reset</code> was called or this EventLoopDelaysMonitor instance was created.<!-- -->Returns metrics in milliseconds. |
| [reset()](./kibana-plugin-core-server.eventloopdelaysmonitor.reset.md) | | Resets the collected histogram data. |
| [stop()](./kibana-plugin-core-server.eventloopdelaysmonitor.stop.md) | | Disables updating the interval timer for collecting new data points. |

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## IntervalHistogram interface

an IntervalHistogram object that samples and reports the event loop delay over time. The delays will be reported in nanoseconds.
an IntervalHistogram object that samples and reports the event loop delay over time. The delays will be reported in milliseconds.

<b>Signature:</b>

Expand Down
2 changes: 1 addition & 1 deletion docs/development/core/server/kibana-plugin-core-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [IExternalUrlPolicy](./kibana-plugin-core-server.iexternalurlpolicy.md) | A policy describing whether access to an external destination is allowed. |
| [IKibanaResponse](./kibana-plugin-core-server.ikibanaresponse.md) | A response data object, expected to returned as a result of [RequestHandler](./kibana-plugin-core-server.requesthandler.md) execution |
| [IKibanaSocket](./kibana-plugin-core-server.ikibanasocket.md) | A tiny abstraction for TCP socket. |
| [IntervalHistogram](./kibana-plugin-core-server.intervalhistogram.md) | an IntervalHistogram object that samples and reports the event loop delay over time. The delays will be reported in nanoseconds. |
| [IntervalHistogram](./kibana-plugin-core-server.intervalhistogram.md) | an IntervalHistogram object that samples and reports the event loop delay over time. The delays will be reported in milliseconds. |
| [IRenderOptions](./kibana-plugin-core-server.irenderoptions.md) | |
| [IRouter](./kibana-plugin-core-server.irouter.md) | Registers route handlers for specified resource path and method. See [RouteConfig](./kibana-plugin-core-server.routeconfig.md) and [RequestHandler](./kibana-plugin-core-server.requesthandler.md) for more information about arguments to route registrations. |
| [ISavedObjectsPointInTimeFinder](./kibana-plugin-core-server.isavedobjectspointintimefinder.md) | |
Expand Down

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

17 changes: 17 additions & 0 deletions src/core/public/application/application_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import { BehaviorSubject, Subject } from 'rxjs';

import type { MountPoint } from '../types';
import { capabilitiesServiceMock } from './capabilities/capabilities_service.mock';
import { themeServiceMock } from '../theme/theme_service.mock';
import { scopedHistoryMock } from './scoped_history.mock';
import {
ApplicationSetup,
InternalApplicationStart,
ApplicationStart,
InternalApplicationSetup,
PublicAppInfo,
AppMountParameters,
} from './types';
import { ApplicationServiceContract } from './test_types';

Expand Down Expand Up @@ -81,6 +84,19 @@ const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart
};
};

const createAppMountParametersMock = (parts: Partial<AppMountParameters>) => {
const mock: AppMountParameters = {
element: document.createElement('div'),
history: scopedHistoryMock.create(),
appBasePath: '/app',
onAppLeave: jest.fn(),
setHeaderActionMenu: jest.fn(),
theme$: themeServiceMock.createTheme$(),
...parts,
};
return mock;
};

const createMock = (): jest.Mocked<ApplicationServiceContract> => ({
setup: jest.fn().mockReturnValue(createInternalSetupContractMock()),
start: jest.fn().mockReturnValue(createInternalStartContractMock()),
Expand All @@ -93,4 +109,5 @@ export const applicationServiceMock = {
createStartContract: createStartContractMock,
createInternalSetupContract: createInternalSetupContractMock,
createInternalStartContract: createInternalStartContractMock,
createAppMountParameters: createAppMountParametersMock,
};
19 changes: 16 additions & 3 deletions src/core/public/application/application_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { mount, shallow } from 'enzyme';

import { httpServiceMock } from '../http/http_service.mock';
import { overlayServiceMock } from '../overlays/overlay_service.mock';
import { themeServiceMock } from '../theme/theme_service.mock';
import { MockLifecycle } from './test_types';
import { ApplicationService } from './application_service';
import { App, AppDeepLink, AppNavLinkStatus, AppStatus, AppUpdater, PublicAppInfo } from './types';
Expand All @@ -44,7 +45,11 @@ describe('#setup()', () => {
http,
redirectTo: jest.fn(),
};
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
startDeps = {
http,
overlays: overlayServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
};
service = new ApplicationService();
});

Expand Down Expand Up @@ -454,7 +459,11 @@ describe('#start()', () => {
http,
redirectTo: jest.fn(),
};
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
startDeps = {
http,
overlays: overlayServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
};
service = new ApplicationService();
});

Expand Down Expand Up @@ -1124,7 +1133,11 @@ describe('#stop()', () => {
setupDeps = {
http,
};
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
startDeps = {
http,
overlays: overlayServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
};
service = new ApplicationService();
});

Expand Down
5 changes: 4 additions & 1 deletion src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { MountPoint } from '../types';
import { HttpSetup, HttpStart } from '../http';
import { OverlayStart } from '../overlays';
import { PluginOpaqueId } from '../plugins';
import type { ThemeServiceStart } from '../theme';
import { AppRouter } from './ui';
import { Capabilities, CapabilitiesService } from './capabilities';
import {
Expand Down Expand Up @@ -44,6 +45,7 @@ interface SetupDeps {

interface StartDeps {
http: HttpStart;
theme: ThemeServiceStart;
overlays: OverlayStart;
}

Expand Down Expand Up @@ -191,7 +193,7 @@ export class ApplicationService {
};
}

public async start({ http, overlays }: StartDeps): Promise<InternalApplicationStart> {
public async start({ http, overlays, theme }: StartDeps): Promise<InternalApplicationStart> {
if (!this.redirectTo) {
throw new Error('ApplicationService#setup() must be invoked before start.');
}
Expand Down Expand Up @@ -314,6 +316,7 @@ export class ApplicationService {
return (
<AppRouter
history={this.history}
theme$={theme.theme$}
mounters={availableMounters}
appStatuses$={applicationStatuses$}
setAppLeaveHandler={this.setAppLeaveHandler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ApplicationService } from '../application_service';
import { httpServiceMock } from '../../http/http_service.mock';
import { MockLifecycle } from '../test_types';
import { overlayServiceMock } from '../../overlays/overlay_service.mock';
import { themeServiceMock } from '../../theme/theme_service.mock';
import { AppMountParameters } from '../types';
import { Observable } from 'rxjs';
import { MountPoint } from 'kibana/public';
Expand Down Expand Up @@ -43,7 +44,11 @@ describe('ApplicationService', () => {
http,
history: history as any,
};
startDeps = { http, overlays: overlayServiceMock.createStartContract() };
startDeps = {
http,
overlays: overlayServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
};
service = new ApplicationService();
});

Expand Down
Loading