Skip to content

Commit

Permalink
Provide uiSettings service in NP (elastic#48413)
Browse files Browse the repository at this point in the history
* provide ui settins client via context

* update mocks

* update types and expose setDefaults to plugins

* move ui settings routes to NP

* add typings fro test kbn server

* move integration test & improve typings

* hide client private methods, update tests

* add unit tests for get_upgradable_config

* inline writeErrors into createOrUpgradeConfig to simplify testing

* regen docs

* add functional tests for ui_settings service

* unify test suites

* add types for sipertest in core_plugin tests

* tsify core_plugins tests

* add test for empty saved config

* update renovate

* rename get/setDefaults to reguster

* regen docs

* regen docs

* Update src/core/MIGRATION.md

Co-Authored-By: Josh Dover <[email protected]>
  • Loading branch information
mshustov and joshdover committed Oct 28, 2019
1 parent 51c3ba5 commit 27294cb
Show file tree
Hide file tree
Showing 96 changed files with 1,229 additions and 631 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## IAnonymousPaths.isAnonymous() method

Determines whether the provided path doesn't require authentication
Determines whether the provided path doesn't require authentication. `path` should include the current basePath.

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export interface IAnonymousPaths

| Method | Description |
| --- | --- |
| [isAnonymous(path)](./kibana-plugin-public.ianonymouspaths.isanonymous.md) | Determines whether the provided path doesn't require authentication |
| [register(path)](./kibana-plugin-public.ianonymouspaths.register.md) | Register <code>path</code> as not requiring authentication |
| [isAnonymous(path)](./kibana-plugin-public.ianonymouspaths.isanonymous.md) | Determines whether the provided path doesn't require authentication. <code>path</code> should include the current basePath. |
| [register(path)](./kibana-plugin-public.ianonymouspaths.register.md) | Register <code>path</code> as not requiring authentication. <code>path</code> should not include the current basePath. |

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

## IAnonymousPaths.register() method

Register `path` as not requiring authentication
Register `path` as not requiring authentication. `path` should not include the current basePath.

<b>Signature:</b>

Expand Down
2 changes: 1 addition & 1 deletion docs/development/core/public/kibana-plugin-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [ToastInputFields](./kibana-plugin-public.toastinputfields.md) | Allowed fields for [ToastInput](./kibana-plugin-public.toastinput.md)<!-- -->. |
| [ToastsSetup](./kibana-plugin-public.toastssetup.md) | [IToasts](./kibana-plugin-public.itoasts.md) |
| [ToastsStart](./kibana-plugin-public.toastsstart.md) | [IToasts](./kibana-plugin-public.itoasts.md) |
| [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md) | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) |
| [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md) | Client-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) |

Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Gets the metadata about all uiSettings, including the type, default value, and u
<b>Signature:</b>

```typescript
getAll(): UiSettingsState;
getAll(): Record<string, UiSettingsParams & UserProvidedValues<any>>;
```
<b>Returns:</b>

`UiSettingsState`
`Record<string, UiSettingsParams & UserProvidedValues<any>>`

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

## UiSettingsClientContract type

[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md)
Client-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md)

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface CoreSetup
| [context](./kibana-plugin-server.coresetup.context.md) | <code>ContextSetup</code> | [ContextSetup](./kibana-plugin-server.contextsetup.md) |
| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | <code>ElasticsearchServiceSetup</code> | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) |
| [http](./kibana-plugin-server.coresetup.http.md) | <code>HttpServiceSetup</code> | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) |
| [uiSettings](./kibana-plugin-server.coresetup.uisettings.md) | <code>UiSettingsServiceSetup</code> | [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.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-server](./kibana-plugin-server.md) &gt; [CoreSetup](./kibana-plugin-server.coresetup.md) &gt; [uiSettings](./kibana-plugin-server.coresetup.uisettings.md)

## CoreSetup.uiSettings property

[UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md)

<b>Signature:</b>

```typescript
uiSettings: UiSettingsServiceSetup;
```

This file was deleted.

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-server](./kibana-plugin-server.md) &gt; [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) &gt; [getRegistered](./kibana-plugin-server.iuisettingsclient.getregistered.md)

## IUiSettingsClient.getRegistered property

Returns registered uiSettings values [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md)

<b>Signature:</b>

```typescript
getRegistered: () => Readonly<Record<string, UiSettingsParams>>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ Retrieves a set of all uiSettings values set by the user.
<b>Signature:</b>

```typescript
getUserProvided: <T extends SavedObjectAttribute = any>() => Promise<Record<string, {
userValue?: T;
isOverridden?: boolean;
}>>;
getUserProvided: <T extends SavedObjectAttribute = any>() => Promise<Record<string, UserProvidedValues<T>>>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## IUiSettingsClient interface

Service that provides access to the UiSettings stored in elasticsearch.
Server-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI.

<b>Signature:</b>

Expand All @@ -18,8 +18,8 @@ export interface IUiSettingsClient
| --- | --- | --- |
| [get](./kibana-plugin-server.iuisettingsclient.get.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;(key: string) =&gt; Promise&lt;T&gt;</code> | Retrieves uiSettings values set by the user with fallbacks to default values if not specified. |
| [getAll](./kibana-plugin-server.iuisettingsclient.getall.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;() =&gt; Promise&lt;Record&lt;string, T&gt;&gt;</code> | Retrieves a set of all uiSettings values set by the user with fallbacks to default values if not specified. |
| [getDefaults](./kibana-plugin-server.iuisettingsclient.getdefaults.md) | <code>() =&gt; Record&lt;string, UiSettingsParams&gt;</code> | Returns uiSettings default values [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) |
| [getUserProvided](./kibana-plugin-server.iuisettingsclient.getuserprovided.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;() =&gt; Promise&lt;Record&lt;string, {</code><br/><code> userValue?: T;</code><br/><code> isOverridden?: boolean;</code><br/><code> }&gt;&gt;</code> | Retrieves a set of all uiSettings values set by the user. |
| [getRegistered](./kibana-plugin-server.iuisettingsclient.getregistered.md) | <code>() =&gt; Readonly&lt;Record&lt;string, UiSettingsParams&gt;&gt;</code> | Returns registered uiSettings values [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) |
| [getUserProvided](./kibana-plugin-server.iuisettingsclient.getuserprovided.md) | <code>&lt;T extends SavedObjectAttribute = any&gt;() =&gt; Promise&lt;Record&lt;string, UserProvidedValues&lt;T&gt;&gt;&gt;</code> | Retrieves a set of all uiSettings values set by the user. |
| [isOverridden](./kibana-plugin-server.iuisettingsclient.isoverridden.md) | <code>(key: string) =&gt; boolean</code> | Shows whether the uiSettings value set by the user. |
| [remove](./kibana-plugin-server.iuisettingsclient.remove.md) | <code>(key: string) =&gt; Promise&lt;void&gt;</code> | Removes uiSettings value by key. |
| [removeMany](./kibana-plugin-server.iuisettingsclient.removemany.md) | <code>(keys: string[]) =&gt; Promise&lt;void&gt;</code> | Removes multiple uiSettings values by keys. |
Expand Down
4 changes: 3 additions & 1 deletion docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [IKibanaSocket](./kibana-plugin-server.ikibanasocket.md) | A tiny abstraction for TCP socket. |
| [IndexSettingsDeprecationInfo](./kibana-plugin-server.indexsettingsdeprecationinfo.md) | |
| [IRouter](./kibana-plugin-server.irouter.md) | Registers route handlers for specified resource path and method. See [RouteConfig](./kibana-plugin-server.routeconfig.md) and [RequestHandler](./kibana-plugin-server.requesthandler.md) for more information about arguments to route registrations. |
| [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) | Service that provides access to the UiSettings stored in elasticsearch. |
| [IUiSettingsClient](./kibana-plugin-server.iuisettingsclient.md) | Server-side client that provides access to the advanced settings stored in elasticsearch. The settings provide control over the behavior of the Kibana application. For example, a user can specify how to display numeric or date fields. Users can adjust the settings via Management UI. |
| [KibanaRequestRoute](./kibana-plugin-server.kibanarequestroute.md) | Request specific route information exposed to a handler. |
| [LegacyRequest](./kibana-plugin-server.legacyrequest.md) | |
| [LegacyServiceSetupDeps](./kibana-plugin-server.legacyservicesetupdeps.md) | |
Expand Down Expand Up @@ -118,6 +118,8 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [SessionStorageCookieOptions](./kibana-plugin-server.sessionstoragecookieoptions.md) | Configuration used to create HTTP session storage based on top of cookie mechanism. |
| [SessionStorageFactory](./kibana-plugin-server.sessionstoragefactory.md) | SessionStorage factory to bind one to an incoming request |
| [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) | UiSettings parameters defined by the plugins. |
| [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) | |
| [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md) | Describes the values explicitly set by user. |

## Variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ core: {
dataClient: IScopedClusterClient;
adminClient: IScopedClusterClient;
};
uiSettings: {
client: IUiSettingsClient;
};
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export interface RequestHandlerContext

| Property | Type | Description |
| --- | --- | --- |
| [core](./kibana-plugin-server.requesthandlercontext.core.md) | <code>{</code><br/><code> savedObjects: {</code><br/><code> client: SavedObjectsClientContract;</code><br/><code> };</code><br/><code> elasticsearch: {</code><br/><code> dataClient: IScopedClusterClient;</code><br/><code> adminClient: IScopedClusterClient;</code><br/><code> };</code><br/><code> }</code> | |
| [core](./kibana-plugin-server.requesthandlercontext.core.md) | <code>{</code><br/><code> savedObjects: {</code><br/><code> client: SavedObjectsClientContract;</code><br/><code> };</code><br/><code> elasticsearch: {</code><br/><code> dataClient: IScopedClusterClient;</code><br/><code> adminClient: IScopedClusterClient;</code><br/><code> };</code><br/><code> uiSettings: {</code><br/><code> client: IUiSettingsClient;</code><br/><code> };</code><br/><code> }</code> | |

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ used to group the configured setting in the UI
<b>Signature:</b>

```typescript
category: string[];
category?: string[];
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ description provided to a user in UI
<b>Signature:</b>

```typescript
description: string;
description?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface UiSettingsParams
| [description](./kibana-plugin-server.uisettingsparams.description.md) | <code>string</code> | description provided to a user in UI |
| [name](./kibana-plugin-server.uisettingsparams.name.md) | <code>string</code> | title in the UI |
| [optionLabels](./kibana-plugin-server.uisettingsparams.optionlabels.md) | <code>Record&lt;string, string&gt;</code> | text labels for 'select' type UI element |
| [options](./kibana-plugin-server.uisettingsparams.options.md) | <code>string[]</code> | a range of valid values |
| [options](./kibana-plugin-server.uisettingsparams.options.md) | <code>string[]</code> | array of permitted values for this setting |
| [readonly](./kibana-plugin-server.uisettingsparams.readonly.md) | <code>boolean</code> | a flag indicating that value cannot be changed |
| [requiresPageReload](./kibana-plugin-server.uisettingsparams.requirespagereload.md) | <code>boolean</code> | a flag indicating whether new value applying requires page reloading |
| [type](./kibana-plugin-server.uisettingsparams.type.md) | <code>UiSettingsType</code> | defines a type of UI element [UiSettingsType](./kibana-plugin-server.uisettingstype.md) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ title in the UI
<b>Signature:</b>

```typescript
name: string;
name?: string;
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## UiSettingsParams.options property

a range of valid values
array of permitted values for this setting

<b>Signature:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ default value to fall back to if a user doesn't provide any
<b>Signature:</b>

```typescript
value: SavedObjectAttribute;
value?: SavedObjectAttribute;
```
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-server](./kibana-plugin-server.md) &gt; [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md)

## UiSettingsServiceSetup interface


<b>Signature:</b>

```typescript
export interface UiSettingsServiceSetup
```

## Methods

| Method | Description |
| --- | --- |
| [register(settings)](./kibana-plugin-server.uisettingsservicesetup.register.md) | Sets settings with default values for the uiSettings. |

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UiSettingsServiceSetup](./kibana-plugin-server.uisettingsservicesetup.md) &gt; [register](./kibana-plugin-server.uisettingsservicesetup.register.md)

## UiSettingsServiceSetup.register() method

Sets settings with default values for the uiSettings.

<b>Signature:</b>

```typescript
register(settings: Record<string, UiSettingsParams>): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| settings | <code>Record&lt;string, UiSettingsParams&gt;</code> | |

<b>Returns:</b>

`void`

## Example

setup(core: CoreSetup)<!-- -->{ core.uiSettings.register(\[{ foo: { name: i18n.translate('my foo settings'), value: true, description: 'add some awesomeness', }<!-- -->, }<!-- -->\]); }

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-server](./kibana-plugin-server.md) &gt; [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md) &gt; [isOverridden](./kibana-plugin-server.userprovidedvalues.isoverridden.md)

## UserProvidedValues.isOverridden property

<b>Signature:</b>

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

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md)

## UserProvidedValues interface

Describes the values explicitly set by user.

<b>Signature:</b>

```typescript
export interface UserProvidedValues<T extends SavedObjectAttribute = any>
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [isOverridden](./kibana-plugin-server.userprovidedvalues.isoverridden.md) | <code>boolean</code> | |
| [userValue](./kibana-plugin-server.userprovidedvalues.uservalue.md) | <code>T</code> | |

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-server](./kibana-plugin-server.md) &gt; [UserProvidedValues](./kibana-plugin-server.userprovidedvalues.md) &gt; [userValue](./kibana-plugin-server.userprovidedvalues.uservalue.md)

## UserProvidedValues.userValue property

<b>Signature:</b>

```typescript
userValue?: T;
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@
"@types/strip-ansi": "^3.0.0",
"@types/styled-components": "^3.0.2",
"@types/supertest": "^2.0.5",
"@types/supertest-as-promised": "^2.0.38",
"@types/type-detect": "^4.0.1",
"@types/uuid": "^3.4.4",
"@types/vinyl-fs": "^2.4.11",
Expand Down
8 changes: 8 additions & 0 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,14 @@
'@types/supertest',
],
},
{
groupSlug: 'supertest-as-promised',
groupName: 'supertest-as-promised related packages',
packageNames: [
'supertest-as-promised',
'@types/supertest-as-promised',
],
},
{
groupSlug: 'type-detect',
groupName: 'type-detect related packages',
Expand Down
16 changes: 10 additions & 6 deletions src/core/public/injected_metadata/injected_metadata_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@

import { get } from 'lodash';
import { DiscoveredPlugin, PluginName } from '../../server';
import { EnvironmentMode, PackageInfo } from '../../server/types';
import { UiSettingsState } from '../ui_settings';
import {
EnvironmentMode,
PackageInfo,
UiSettingsParams,
UserProvidedValues,
} from '../../server/types';
import { deepFreeze } from '../../utils/';
import { Capabilities } from '..';

Expand Down Expand Up @@ -69,8 +73,8 @@ export interface InjectedMetadataParams {
serverName: string;
devMode: boolean;
uiSettings: {
defaults: UiSettingsState;
user?: UiSettingsState;
defaults: Record<string, UiSettingsParams>;
user?: Record<string, UserProvidedValues>;
};
};
};
Expand Down Expand Up @@ -179,8 +183,8 @@ export interface InjectedMetadataSetup {
serverName: string;
devMode: boolean;
uiSettings: {
defaults: UiSettingsState;
user?: UiSettingsState | undefined;
defaults: Record<string, UiSettingsParams>;
user?: Record<string, UserProvidedValues> | undefined;
};
};
getInjectedVar: (name: string, defaultValue?: any) => unknown;
Expand Down
Loading

0 comments on commit 27294cb

Please sign in to comment.