From 0f8533730c4d777669e590f9bc8796f394e55d68 Mon Sep 17 00:00:00 2001 From: Mikhail Shustov Date: Thu, 28 Nov 2019 22:53:02 +0100 Subject: [PATCH] Unify uiSettingsClient contracts (#51167) * introduce IUiSettingsClient on the client * switch uiSettings service to IUiSettingsClient * update uiSettings service tests * all plugins should use IUiSettingsClient * stop is not public methods anymore * remove savedobject attribute type references * regen docs * remove all references to UiSettingsClient class * regen docs * add migration example for uiSettings * update consumer types and tests * address comments --- ...bana-plugin-public.appmountcontext.core.md | 2 +- .../kibana-plugin-public.appmountcontext.md | 2 +- .../kibana-plugin-public.contextsetup.md | 2 +- .../public/kibana-plugin-public.coresetup.md | 2 +- ...bana-plugin-public.coresetup.uisettings.md | 4 +- .../public/kibana-plugin-public.corestart.md | 2 +- ...bana-plugin-public.corestart.uisettings.md | 4 +- ...ana-plugin-public.iuisettingsclient.get.md | 13 + ...na-plugin-public.iuisettingsclient.get_.md | 13 + ...-plugin-public.iuisettingsclient.getall.md | 13 + ...ugin-public.iuisettingsclient.getsaved_.md | 17 ++ ...gin-public.iuisettingsclient.getupdate_.md | 17 ++ ...lic.iuisettingsclient.getupdateerrors_.md} | 10 +- ...lugin-public.iuisettingsclient.iscustom.md | 13 + ...gin-public.iuisettingsclient.isdeclared.md | 13 + ...ugin-public.iuisettingsclient.isdefault.md | 13 + ...n-public.iuisettingsclient.isoverridden.md | 13 + .../kibana-plugin-public.iuisettingsclient.md | 32 +++ ....iuisettingsclient.overridelocaldefault.md | 13 + ...plugin-public.iuisettingsclient.remove.md} | 17 +- ...ana-plugin-public.iuisettingsclient.set.md | 13 + .../core/public/kibana-plugin-public.md | 3 +- ...a-plugin-public.toastsapi._constructor_.md | 4 +- ...n-public.uisettingsclient._constructor_.md | 20 -- ...bana-plugin-public.uisettingsclient.get.md | 25 -- ...ana-plugin-public.uisettingsclient.get_.md | 25 -- ...a-plugin-public.uisettingsclient.getall.md | 17 -- ...lugin-public.uisettingsclient.getsaved_.md | 25 -- ...ugin-public.uisettingsclient.getupdate_.md | 25 -- ...plugin-public.uisettingsclient.iscustom.md | 24 -- ...ugin-public.uisettingsclient.isdeclared.md | 24 -- ...lugin-public.uisettingsclient.isdefault.md | 24 -- ...in-public.uisettingsclient.isoverridden.md | 24 -- .../kibana-plugin-public.uisettingsclient.md | 38 --- ...c.uisettingsclient.overridelocaldefault.md | 25 -- ...bana-plugin-public.uisettingsclient.set.md | 25 -- ...ana-plugin-public.uisettingsclient.stop.md | 17 -- ...-plugin-public.uisettingsclientcontract.md | 13 - .../kibana-plugin-server.contextsetup.md | 2 +- ...ana-plugin-server.iuisettingsclient.get.md | 2 +- ...-plugin-server.iuisettingsclient.getall.md | 2 +- ...erver.iuisettingsclient.getuserprovided.md | 2 +- .../kibana-plugin-server.iuisettingsclient.md | 10 +- ...ana-plugin-server.iuisettingsclient.set.md | 2 +- ...plugin-server.iuisettingsclient.setmany.md | 2 +- ...kibana-plugin-server.userprovidedvalues.md | 2 +- src/core/MIGRATION.md | 32 +++ src/core/public/application/types.ts | 6 +- src/core/public/context/context_service.ts | 2 +- src/core/public/index.ts | 13 +- .../integrations/integrations_service.ts | 4 +- .../integrations/moment/moment_service.ts | 4 +- .../integrations/styles/styles_service.ts | 4 +- .../notifications/notifications_service.ts | 4 +- .../notifications/toasts/toasts_api.tsx | 6 +- .../notifications/toasts/toasts_service.tsx | 4 +- .../overlays/banners/banners_service.tsx | 4 +- .../overlays/banners/user_banner_service.tsx | 4 +- src/core/public/overlays/overlay_service.ts | 4 +- src/core/public/public.api.md | 64 ++--- .../ui_settings_client.test.ts.snap | 18 +- .../ui_settings_service.test.ts.snap | 117 -------- src/core/public/ui_settings/index.ts | 4 +- src/core/public/ui_settings/types.ts | 103 +++++++ .../ui_settings/ui_settings_client.test.ts | 251 +++++++++--------- .../public/ui_settings/ui_settings_client.ts | 142 +++------- .../ui_settings/ui_settings_service.mock.ts | 6 +- .../ui_settings_service.test.mocks.ts | 57 ---- .../ui_settings/ui_settings_service.test.ts | 55 +--- .../public/ui_settings/ui_settings_service.ts | 14 +- src/core/server/context/context_service.ts | 2 +- src/core/server/server.api.md | 12 +- .../create_or_upgrade_saved_config.ts | 6 +- src/core/server/ui_settings/types.ts | 14 +- .../server/ui_settings/ui_settings_client.ts | 28 +- .../server/ui_settings/ui_settings_service.ts | 4 +- .../index_patterns/index_patterns.test.ts | 8 +- .../index_patterns/index_patterns.ts | 6 +- .../index_patterns/index_patterns_service.ts | 4 +- .../query_string_input.test.tsx.snap | 6 - .../components/fetch_index_patterns.ts | 4 +- .../kibana/public/dashboard/application.ts | 4 +- .../kibana/public/home/kibana_services.ts | 4 +- .../core_plugins/region_map/public/plugin.ts | 4 +- .../core_plugins/tile_map/public/plugin.ts | 4 +- .../core_plugins/timelion/public/plugin.ts | 4 +- .../contexts/query_input_bar_context.ts | 4 +- .../vis_type_timeseries/public/plugin.ts | 4 +- .../vis_type_timeseries/public/services.ts | 6 +- .../vis_type_vega/public/plugin.ts | 4 +- .../public/np_ready/public/services.ts | 6 +- .../agg_types/buckets/date_range.test.ts | 2 +- .../agg_types/buckets/histogram.test.ts | 2 +- .../public/courier/fetch/fetch_soon.test.ts | 4 +- .../courier/fetch/get_search_params.test.ts | 4 +- .../public/courier/fetch/get_search_params.ts | 12 +- src/legacy/ui/public/courier/fetch/types.ts | 4 +- .../default_search_strategy.test.ts | 4 +- .../ui/public/test_harness/test_harness.js | 9 +- .../es_query/get_es_query_config.test.ts | 4 +- .../field_formats_provider/field_formats.ts | 6 +- .../field_formats_service.ts | 4 +- .../query/filter_manager/filter_manager.ts | 6 +- .../data/public/query/lib/get_query_log.ts | 4 +- .../query/timefilter/timefilter_service.ts | 4 +- .../value_suggestions.test.ts | 6 +- .../suggestions_provider/value_suggestions.ts | 4 +- .../data/public/ui/filter_bar/filter_item.tsx | 4 +- .../language_switcher.test.tsx.snap | 2 - .../views/data/components/data_table.tsx | 4 +- .../views/data/components/data_view.test.tsx | 4 +- .../views/data/components/data_view.tsx | 4 +- .../inspector/public/views/data/index.tsx | 4 +- .../table_list_view/table_list_view.tsx | 4 +- src/test_utils/public/stub_field_formats.ts | 4 +- .../legacy/plugins/graph/public/render_app.ts | 4 +- .../dimension_panel/dimension_panel.test.tsx | 8 +- .../dimension_panel/dimension_panel.tsx | 8 +- .../definitions/date_histogram.test.tsx | 8 +- .../operations/definitions/index.ts | 8 +- .../operations/definitions/terms.test.tsx | 8 +- .../public/xy_visualization_plugin/plugin.tsx | 4 +- .../transform/public/app/lib/kibana/common.ts | 4 +- 123 files changed, 739 insertions(+), 1092 deletions(-) create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.get.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.get_.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.getall.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.getsaved_.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdate_.md rename docs/development/core/public/{kibana-plugin-public.uisettingsclient.getupdateerrors_.md => kibana-plugin-public.iuisettingsclient.getupdateerrors_.md} (50%) create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.iscustom.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdeclared.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdefault.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.isoverridden.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.md create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.overridelocaldefault.md rename docs/development/core/public/{kibana-plugin-public.uisettingsclient.remove.md => kibana-plugin-public.iuisettingsclient.remove.md} (51%) create mode 100644 docs/development/core/public/kibana-plugin-public.iuisettingsclient.set.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient._constructor_.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.get.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.get_.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.getall.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.getsaved_.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdate_.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.iscustom.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.isdeclared.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.isdefault.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.isoverridden.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.overridelocaldefault.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.set.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclient.stop.md delete mode 100644 docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md delete mode 100644 src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap delete mode 100644 src/core/public/ui_settings/ui_settings_service.test.mocks.ts diff --git a/docs/development/core/public/kibana-plugin-public.appmountcontext.core.md b/docs/development/core/public/kibana-plugin-public.appmountcontext.core.md index f4dee0f29af34..960d610b589b8 100644 --- a/docs/development/core/public/kibana-plugin-public.appmountcontext.core.md +++ b/docs/development/core/public/kibana-plugin-public.appmountcontext.core.md @@ -17,7 +17,7 @@ core: { i18n: I18nStart; notifications: NotificationsStart; overlays: OverlayStart; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; injectedMetadata: { getInjectedVar: (name: string, defaultValue?: any) => unknown; }; diff --git a/docs/development/core/public/kibana-plugin-public.appmountcontext.md b/docs/development/core/public/kibana-plugin-public.appmountcontext.md index 97d143d518f60..e12121e0e3ebb 100644 --- a/docs/development/core/public/kibana-plugin-public.appmountcontext.md +++ b/docs/development/core/public/kibana-plugin-public.appmountcontext.md @@ -16,5 +16,5 @@ export interface AppMountContext | Property | Type | Description | | --- | --- | --- | -| [core](./kibana-plugin-public.appmountcontext.core.md) | {
application: Pick<ApplicationStart, 'capabilities' | 'navigateToApp'>;
chrome: ChromeStart;
docLinks: DocLinksStart;
http: HttpStart;
i18n: I18nStart;
notifications: NotificationsStart;
overlays: OverlayStart;
uiSettings: UiSettingsClientContract;
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
} | Core service APIs available to mounted applications. | +| [core](./kibana-plugin-public.appmountcontext.core.md) | {
application: Pick<ApplicationStart, 'capabilities' | 'navigateToApp'>;
chrome: ChromeStart;
docLinks: DocLinksStart;
http: HttpStart;
i18n: I18nStart;
notifications: NotificationsStart;
overlays: OverlayStart;
uiSettings: IUiSettingsClient;
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
} | Core service APIs available to mounted applications. | diff --git a/docs/development/core/public/kibana-plugin-public.contextsetup.md b/docs/development/core/public/kibana-plugin-public.contextsetup.md index 2b67c7cdaf0e1..a006fa7205ca6 100644 --- a/docs/development/core/public/kibana-plugin-public.contextsetup.md +++ b/docs/development/core/public/kibana-plugin-public.contextsetup.md @@ -85,7 +85,7 @@ Say we're creating a plugin for rendering visualizations that allows new renderi export interface VizRenderContext { core: { i18n: I18nStart; - uiSettings: UISettingsClientContract; + uiSettings: IUiSettingsClient; } [contextName: string]: unknown; } diff --git a/docs/development/core/public/kibana-plugin-public.coresetup.md b/docs/development/core/public/kibana-plugin-public.coresetup.md index f9335425fed4c..8314bde7b95f0 100644 --- a/docs/development/core/public/kibana-plugin-public.coresetup.md +++ b/docs/development/core/public/kibana-plugin-public.coresetup.md @@ -22,5 +22,5 @@ export interface CoreSetup | [http](./kibana-plugin-public.coresetup.http.md) | HttpSetup | [HttpSetup](./kibana-plugin-public.httpsetup.md) | | [injectedMetadata](./kibana-plugin-public.coresetup.injectedmetadata.md) | {
getInjectedVar: (name: string, defaultValue?: any) => 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. Use the legacy platform API instead. | | [notifications](./kibana-plugin-public.coresetup.notifications.md) | NotificationsSetup | [NotificationsSetup](./kibana-plugin-public.notificationssetup.md) | -| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | UiSettingsClientContract | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | +| [uiSettings](./kibana-plugin-public.coresetup.uisettings.md) | IUiSettingsClient | [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md b/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md index 78a13fccd23ed..bf9ec12e3eea2 100644 --- a/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md +++ b/docs/development/core/public/kibana-plugin-public.coresetup.uisettings.md @@ -4,10 +4,10 @@ ## CoreSetup.uiSettings property -[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) +[IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) Signature: ```typescript -uiSettings: UiSettingsClientContract; +uiSettings: IUiSettingsClient; ``` diff --git a/docs/development/core/public/kibana-plugin-public.corestart.md b/docs/development/core/public/kibana-plugin-public.corestart.md index 47eba78bf43e4..e561ee313f100 100644 --- a/docs/development/core/public/kibana-plugin-public.corestart.md +++ b/docs/development/core/public/kibana-plugin-public.corestart.md @@ -25,5 +25,5 @@ export interface CoreStart | [notifications](./kibana-plugin-public.corestart.notifications.md) | NotificationsStart | [NotificationsStart](./kibana-plugin-public.notificationsstart.md) | | [overlays](./kibana-plugin-public.corestart.overlays.md) | OverlayStart | [OverlayStart](./kibana-plugin-public.overlaystart.md) | | [savedObjects](./kibana-plugin-public.corestart.savedobjects.md) | SavedObjectsStart | [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) | -| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | UiSettingsClientContract | [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | +| [uiSettings](./kibana-plugin-public.corestart.uisettings.md) | IUiSettingsClient | [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) | diff --git a/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md b/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md index 1751135e01981..2ee405591dc08 100644 --- a/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md +++ b/docs/development/core/public/kibana-plugin-public.corestart.uisettings.md @@ -4,10 +4,10 @@ ## CoreStart.uiSettings property -[UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) +[IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) Signature: ```typescript -uiSettings: UiSettingsClientContract; +uiSettings: IUiSettingsClient; ``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.get.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.get.md new file mode 100644 index 0000000000000..8d14a10951a92 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.get.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [get](./kibana-plugin-public.iuisettingsclient.get.md) + +## IUiSettingsClient.get property + +Gets the value for a specific uiSetting. If this setting has no user-defined value then the `defaultOverride` parameter is returned (and parsed if setting is of type "json" or "number). If the parameter is not defined and the key is not registered by any plugin then an error is thrown, otherwise reads the default value defined by a plugin. + +Signature: + +```typescript +get: (key: string, defaultOverride?: T) => T; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.get_.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.get_.md new file mode 100644 index 0000000000000..b7680b769f303 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.get_.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [get$](./kibana-plugin-public.iuisettingsclient.get_.md) + +## IUiSettingsClient.get$ property + +Gets an observable of the current value for a config key, and all updates to that config key in the future. Providing a `defaultOverride` argument behaves the same as it does in \#get() + +Signature: + +```typescript +get$: (key: string, defaultOverride?: T) => Observable; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getall.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getall.md new file mode 100644 index 0000000000000..b767a8ff603c8 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getall.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [getAll](./kibana-plugin-public.iuisettingsclient.getall.md) + +## IUiSettingsClient.getAll property + +Gets the metadata about all uiSettings, including the type, default value, and user value for each key. + +Signature: + +```typescript +getAll: () => Readonly>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getsaved_.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getsaved_.md new file mode 100644 index 0000000000000..a4ddb9abcba97 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getsaved_.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [getSaved$](./kibana-plugin-public.iuisettingsclient.getsaved_.md) + +## IUiSettingsClient.getSaved$ property + +Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. + +Signature: + +```typescript +getSaved$: () => Observable<{ + key: string; + newValue: T; + oldValue: T; + }>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdate_.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdate_.md new file mode 100644 index 0000000000000..cec5bc096cf02 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdate_.md @@ -0,0 +1,17 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [getUpdate$](./kibana-plugin-public.iuisettingsclient.getupdate_.md) + +## IUiSettingsClient.getUpdate$ property + +Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. + +Signature: + +```typescript +getUpdate$: () => Observable<{ + key: string; + newValue: T; + oldValue: T; + }>; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdateerrors_.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdateerrors_.md similarity index 50% rename from docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdateerrors_.md rename to docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdateerrors_.md index ada2a56ac8db6..2fbcaac03e2bb 100644 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdateerrors_.md +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.getupdateerrors_.md @@ -1,17 +1,13 @@ -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [getUpdateErrors$](./kibana-plugin-public.uisettingsclient.getupdateerrors_.md) +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [getUpdateErrors$](./kibana-plugin-public.iuisettingsclient.getupdateerrors_.md) -## UiSettingsClient.getUpdateErrors$() method +## IUiSettingsClient.getUpdateErrors$ property Returns an Observable that notifies subscribers of each error while trying to update the settings, containing the actual Error class. Signature: ```typescript -getUpdateErrors$(): Rx.Observable; +getUpdateErrors$: () => Observable; ``` -Returns: - -`Rx.Observable` - diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.iscustom.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.iscustom.md new file mode 100644 index 0000000000000..30de59c066ee3 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.iscustom.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [isCustom](./kibana-plugin-public.iuisettingsclient.iscustom.md) + +## IUiSettingsClient.isCustom property + +Returns true if the setting wasn't registered by any plugin, but was either added directly via `set()`, or is an unknown setting found in the uiSettings saved object + +Signature: + +```typescript +isCustom: (key: string) => boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdeclared.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdeclared.md new file mode 100644 index 0000000000000..1ffcb61967e8a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdeclared.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [isDeclared](./kibana-plugin-public.iuisettingsclient.isdeclared.md) + +## IUiSettingsClient.isDeclared property + +Returns true if the key is a "known" uiSetting, meaning it is either registered by any plugin or was previously added as a custom setting via the `set()` method. + +Signature: + +```typescript +isDeclared: (key: string) => boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdefault.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdefault.md new file mode 100644 index 0000000000000..d61367c9841d4 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isdefault.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [isDefault](./kibana-plugin-public.iuisettingsclient.isdefault.md) + +## IUiSettingsClient.isDefault property + +Returns true if the setting has no user-defined value or is unknown + +Signature: + +```typescript +isDefault: (key: string) => boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isoverridden.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isoverridden.md new file mode 100644 index 0000000000000..5749e1db1fe43 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.isoverridden.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [isOverridden](./kibana-plugin-public.iuisettingsclient.isoverridden.md) + +## IUiSettingsClient.isOverridden property + +Shows whether the uiSettings value set by the user. + +Signature: + +```typescript +isOverridden: (key: string) => boolean; +``` diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.md new file mode 100644 index 0000000000000..4183a30806d9a --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.md @@ -0,0 +1,32 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) + +## IUiSettingsClient interface + +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. [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) + +Signature: + +```typescript +export interface IUiSettingsClient +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [get](./kibana-plugin-public.iuisettingsclient.get.md) | <T = any>(key: string, defaultOverride?: T) => T | Gets the value for a specific uiSetting. If this setting has no user-defined value then the defaultOverride parameter is returned (and parsed if setting is of type "json" or "number). If the parameter is not defined and the key is not registered by any plugin then an error is thrown, otherwise reads the default value defined by a plugin. | +| [get$](./kibana-plugin-public.iuisettingsclient.get_.md) | <T = any>(key: string, defaultOverride?: T) => Observable<T> | Gets an observable of the current value for a config key, and all updates to that config key in the future. Providing a defaultOverride argument behaves the same as it does in \#get() | +| [getAll](./kibana-plugin-public.iuisettingsclient.getall.md) | () => Readonly<Record<string, UiSettingsParams & UserProvidedValues>> | Gets the metadata about all uiSettings, including the type, default value, and user value for each key. | +| [getSaved$](./kibana-plugin-public.iuisettingsclient.getsaved_.md) | <T = any>() => Observable<{
key: string;
newValue: T;
oldValue: T;
}> | Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. | +| [getUpdate$](./kibana-plugin-public.iuisettingsclient.getupdate_.md) | <T = any>() => Observable<{
key: string;
newValue: T;
oldValue: T;
}> | Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. | +| [getUpdateErrors$](./kibana-plugin-public.iuisettingsclient.getupdateerrors_.md) | () => Observable<Error> | Returns an Observable that notifies subscribers of each error while trying to update the settings, containing the actual Error class. | +| [isCustom](./kibana-plugin-public.iuisettingsclient.iscustom.md) | (key: string) => boolean | Returns true if the setting wasn't registered by any plugin, but was either added directly via set(), or is an unknown setting found in the uiSettings saved object | +| [isDeclared](./kibana-plugin-public.iuisettingsclient.isdeclared.md) | (key: string) => boolean | Returns true if the key is a "known" uiSetting, meaning it is either registered by any plugin or was previously added as a custom setting via the set() method. | +| [isDefault](./kibana-plugin-public.iuisettingsclient.isdefault.md) | (key: string) => boolean | Returns true if the setting has no user-defined value or is unknown | +| [isOverridden](./kibana-plugin-public.iuisettingsclient.isoverridden.md) | (key: string) => boolean | Shows whether the uiSettings value set by the user. | +| [overrideLocalDefault](./kibana-plugin-public.iuisettingsclient.overridelocaldefault.md) | (key: string, newDefault: any) => void | Overrides the default value for a setting in this specific browser tab. If the page is reloaded the default override is lost. | +| [remove](./kibana-plugin-public.iuisettingsclient.remove.md) | (key: string) => Promise<boolean> | Removes the user-defined value for a setting, causing it to revert to the default. This method behaves the same as calling set(key, null), including the synchronization, custom setting, and error behavior of that method. | +| [set](./kibana-plugin-public.iuisettingsclient.set.md) | (key: string, value: any) => Promise<boolean> | Sets the value for a uiSetting. If the setting is not registered by any plugin it will be stored as a custom setting. The new value will be synchronously available via the get() method and sent to the server in the background. If the request to the server fails then a updateErrors$ will be notified and the setting will be reverted to its value before set() was called. | + diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.overridelocaldefault.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.overridelocaldefault.md new file mode 100644 index 0000000000000..d7e7c01876654 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.overridelocaldefault.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [overrideLocalDefault](./kibana-plugin-public.iuisettingsclient.overridelocaldefault.md) + +## IUiSettingsClient.overrideLocalDefault property + +Overrides the default value for a setting in this specific browser tab. If the page is reloaded the default override is lost. + +Signature: + +```typescript +overrideLocalDefault: (key: string, newDefault: any) => void; +``` diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.remove.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.remove.md similarity index 51% rename from docs/development/core/public/kibana-plugin-public.uisettingsclient.remove.md rename to docs/development/core/public/kibana-plugin-public.iuisettingsclient.remove.md index 3d07e75449639..c2171e5c883f8 100644 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.remove.md +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.remove.md @@ -1,24 +1,13 @@ -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [remove](./kibana-plugin-public.uisettingsclient.remove.md) +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [remove](./kibana-plugin-public.iuisettingsclient.remove.md) -## UiSettingsClient.remove() method +## IUiSettingsClient.remove property Removes the user-defined value for a setting, causing it to revert to the default. This method behaves the same as calling `set(key, null)`, including the synchronization, custom setting, and error behavior of that method. Signature: ```typescript -remove(key: string): Promise; +remove: (key: string) => Promise; ``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | - -Returns: - -`Promise` - diff --git a/docs/development/core/public/kibana-plugin-public.iuisettingsclient.set.md b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.set.md new file mode 100644 index 0000000000000..d9e62eec4cf08 --- /dev/null +++ b/docs/development/core/public/kibana-plugin-public.iuisettingsclient.set.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) > [set](./kibana-plugin-public.iuisettingsclient.set.md) + +## IUiSettingsClient.set property + +Sets the value for a uiSetting. If the setting is not registered by any plugin it will be stored as a custom setting. The new value will be synchronously available via the `get()` method and sent to the server in the background. If the request to the server fails then a updateErrors$ will be notified and the setting will be reverted to its value before `set()` was called. + +Signature: + +```typescript +set: (key: string, value: any) => Promise; +``` diff --git a/docs/development/core/public/kibana-plugin-public.md b/docs/development/core/public/kibana-plugin-public.md index 22794ca945540..f527c92d070de 100644 --- a/docs/development/core/public/kibana-plugin-public.md +++ b/docs/development/core/public/kibana-plugin-public.md @@ -17,7 +17,6 @@ The plugin integrates with the core system via lifecycle events: `setup` | [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md) | Saved Objects is Kibana's data persisentence mechanism allowing plugins to use Elasticsearch for storing plugin state. The client-side SavedObjectsClient is a thin convenience library around the SavedObjects HTTP API for interacting with Saved Objects. | | [SimpleSavedObject](./kibana-plugin-public.simplesavedobject.md) | This class is a very simple wrapper for SavedObjects loaded from the server with the [SavedObjectsClient](./kibana-plugin-public.savedobjectsclient.md).It provides basic functionality for creating/saving/deleting saved objects, but doesn't include any type-specific implementations. | | [ToastsApi](./kibana-plugin-public.toastsapi.md) | Methods for adding and removing global toast messages. | -| [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) | | ## Interfaces @@ -65,6 +64,7 @@ The plugin integrates with the core system via lifecycle events: `setup` | [IHttpFetchError](./kibana-plugin-public.ihttpfetcherror.md) | | | [IHttpInterceptController](./kibana-plugin-public.ihttpinterceptcontroller.md) | Used to halt a request Promise chain in a [HttpInterceptor](./kibana-plugin-public.httpinterceptor.md). | | [InterceptedHttpResponse](./kibana-plugin-public.interceptedhttpresponse.md) | | +| [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.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. [IUiSettingsClient](./kibana-plugin-public.iuisettingsclient.md) | | [LegacyCoreSetup](./kibana-plugin-public.legacycoresetup.md) | Setup interface exposed to the legacy platform via the ui/new_platform module. | | [LegacyCoreStart](./kibana-plugin-public.legacycorestart.md) | Start interface exposed to the legacy platform via the ui/new_platform module. | | [LegacyNavLink](./kibana-plugin-public.legacynavlink.md) | | @@ -126,6 +126,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) | 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) | | [UnmountCallback](./kibana-plugin-public.unmountcallback.md) | A function that will unmount the element previously mounted by the associated [MountPoint](./kibana-plugin-public.mountpoint.md) | diff --git a/docs/development/core/public/kibana-plugin-public.toastsapi._constructor_.md b/docs/development/core/public/kibana-plugin-public.toastsapi._constructor_.md index 31a16403a41a1..2b5ce41de8ece 100644 --- a/docs/development/core/public/kibana-plugin-public.toastsapi._constructor_.md +++ b/docs/development/core/public/kibana-plugin-public.toastsapi._constructor_.md @@ -10,7 +10,7 @@ Constructs a new instance of the `ToastsApi` class ```typescript constructor(deps: { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; }); ``` @@ -18,5 +18,5 @@ constructor(deps: { | Parameter | Type | Description | | --- | --- | --- | -| deps | {
uiSettings: UiSettingsClientContract;
} | | +| deps | {
uiSettings: IUiSettingsClient;
} | | diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient._constructor_.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient._constructor_.md deleted file mode 100644 index a7698fe61e162..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient._constructor_.md +++ /dev/null @@ -1,20 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [(constructor)](./kibana-plugin-public.uisettingsclient._constructor_.md) - -## UiSettingsClient.(constructor) - -Constructs a new instance of the `UiSettingsClient` class - -Signature: - -```typescript -constructor(params: UiSettingsClientParams); -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| params | UiSettingsClientParams | | - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.get.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.get.md deleted file mode 100644 index 03fa38575b6b8..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.get.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [get](./kibana-plugin-public.uisettingsclient.get.md) - -## UiSettingsClient.get() method - -Gets the value for a specific uiSetting. If this setting has no user-defined value then the `defaultOverride` parameter is returned (and parsed if setting is of type "json" or "number). If the parameter is not defined and the key is not defined by a uiSettingDefaults then an error is thrown, otherwise the default is read from the uiSettingDefaults. - -Signature: - -```typescript -get(key: string, defaultOverride?: any): any; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | -| defaultOverride | any | | - -Returns: - -`any` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.get_.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.get_.md deleted file mode 100644 index 6a515a8f514a2..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.get_.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [get$](./kibana-plugin-public.uisettingsclient.get_.md) - -## UiSettingsClient.get$() method - -Gets an observable of the current value for a config key, and all updates to that config key in the future. Providing a `defaultOverride` argument behaves the same as it does in \#get() - -Signature: - -```typescript -get$(key: string, defaultOverride?: any): Rx.Observable; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | -| defaultOverride | any | | - -Returns: - -`Rx.Observable` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getall.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.getall.md deleted file mode 100644 index 06daf8e8151cd..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getall.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [getAll](./kibana-plugin-public.uisettingsclient.getall.md) - -## UiSettingsClient.getAll() method - -Gets the metadata about all uiSettings, including the type, default value, and user value for each key. - -Signature: - -```typescript -getAll(): Record>; -``` -Returns: - -`Record>` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getsaved_.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.getsaved_.md deleted file mode 100644 index 9e46b286c4009..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getsaved_.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [getSaved$](./kibana-plugin-public.uisettingsclient.getsaved_.md) - -## UiSettingsClient.getSaved$() method - -Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. - -Signature: - -```typescript -getSaved$(): Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>; -``` -Returns: - -`Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdate_.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdate_.md deleted file mode 100644 index b9cab6e87a996..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.getupdate_.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [getUpdate$](./kibana-plugin-public.uisettingsclient.getupdate_.md) - -## UiSettingsClient.getUpdate$() method - -Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. - -Signature: - -```typescript -getUpdate$(): Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>; -``` -Returns: - -`Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.iscustom.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.iscustom.md deleted file mode 100644 index 8855e39d7e8f3..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.iscustom.md +++ /dev/null @@ -1,24 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [isCustom](./kibana-plugin-public.uisettingsclient.iscustom.md) - -## UiSettingsClient.isCustom() method - -Returns true if the setting is not a part of the uiSettingDefaults, but was either added directly via `set()`, or is an unknown setting found in the uiSettings saved object - -Signature: - -```typescript -isCustom(key: string): boolean; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | - -Returns: - -`boolean` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.isdeclared.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.isdeclared.md deleted file mode 100644 index 61b9d3a11a1af..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.isdeclared.md +++ /dev/null @@ -1,24 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [isDeclared](./kibana-plugin-public.uisettingsclient.isdeclared.md) - -## UiSettingsClient.isDeclared() method - -Returns true if the key is a "known" uiSetting, meaning it is either defined in the uiSettingDefaults or was previously added as a custom setting via the `set()` method. - -Signature: - -```typescript -isDeclared(key: string): boolean; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | - -Returns: - -`boolean` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.isdefault.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.isdefault.md deleted file mode 100644 index 09a04f99e8285..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.isdefault.md +++ /dev/null @@ -1,24 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [isDefault](./kibana-plugin-public.uisettingsclient.isdefault.md) - -## UiSettingsClient.isDefault() method - -Returns true if the setting has no user-defined value or is unknown - -Signature: - -```typescript -isDefault(key: string): boolean; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | - -Returns: - -`boolean` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.isoverridden.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.isoverridden.md deleted file mode 100644 index 5311ffbf40d95..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.isoverridden.md +++ /dev/null @@ -1,24 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [isOverridden](./kibana-plugin-public.uisettingsclient.isoverridden.md) - -## UiSettingsClient.isOverridden() method - -Returns true if a settings value is overridden by the server. When a setting is overridden its value can not be changed via `set()` or `remove()`. - -Signature: - -```typescript -isOverridden(key: string): boolean; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | - -Returns: - -`boolean` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.md deleted file mode 100644 index 642e6db144f09..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.md +++ /dev/null @@ -1,38 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) - -## UiSettingsClient class - - -Signature: - -```typescript -export declare class UiSettingsClient -``` - -## Constructors - -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)(params)](./kibana-plugin-public.uisettingsclient._constructor_.md) | | Constructs a new instance of the UiSettingsClient class | - -## Methods - -| Method | Modifiers | Description | -| --- | --- | --- | -| [get(key, defaultOverride)](./kibana-plugin-public.uisettingsclient.get.md) | | Gets the value for a specific uiSetting. If this setting has no user-defined value then the defaultOverride parameter is returned (and parsed if setting is of type "json" or "number). If the parameter is not defined and the key is not defined by a uiSettingDefaults then an error is thrown, otherwise the default is read from the uiSettingDefaults. | -| [get$(key, defaultOverride)](./kibana-plugin-public.uisettingsclient.get_.md) | | Gets an observable of the current value for a config key, and all updates to that config key in the future. Providing a defaultOverride argument behaves the same as it does in \#get() | -| [getAll()](./kibana-plugin-public.uisettingsclient.getall.md) | | Gets the metadata about all uiSettings, including the type, default value, and user value for each key. | -| [getSaved$()](./kibana-plugin-public.uisettingsclient.getsaved_.md) | | Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. | -| [getUpdate$()](./kibana-plugin-public.uisettingsclient.getupdate_.md) | | Returns an Observable that notifies subscribers of each update to the uiSettings, including the key, newValue, and oldValue of the setting that changed. | -| [getUpdateErrors$()](./kibana-plugin-public.uisettingsclient.getupdateerrors_.md) | | Returns an Observable that notifies subscribers of each error while trying to update the settings, containing the actual Error class. | -| [isCustom(key)](./kibana-plugin-public.uisettingsclient.iscustom.md) | | Returns true if the setting is not a part of the uiSettingDefaults, but was either added directly via set(), or is an unknown setting found in the uiSettings saved object | -| [isDeclared(key)](./kibana-plugin-public.uisettingsclient.isdeclared.md) | | Returns true if the key is a "known" uiSetting, meaning it is either defined in the uiSettingDefaults or was previously added as a custom setting via the set() method. | -| [isDefault(key)](./kibana-plugin-public.uisettingsclient.isdefault.md) | | Returns true if the setting has no user-defined value or is unknown | -| [isOverridden(key)](./kibana-plugin-public.uisettingsclient.isoverridden.md) | | Returns true if a settings value is overridden by the server. When a setting is overridden its value can not be changed via set() or remove(). | -| [overrideLocalDefault(key, newDefault)](./kibana-plugin-public.uisettingsclient.overridelocaldefault.md) | | Overrides the default value for a setting in this specific browser tab. If the page is reloaded the default override is lost. | -| [remove(key)](./kibana-plugin-public.uisettingsclient.remove.md) | | Removes the user-defined value for a setting, causing it to revert to the default. This method behaves the same as calling set(key, null), including the synchronization, custom setting, and error behavior of that method. | -| [set(key, val)](./kibana-plugin-public.uisettingsclient.set.md) | | Sets the value for a uiSetting. If the setting is not defined in the uiSettingDefaults it will be stored as a custom setting. The new value will be synchronously available via the get() method and sent to the server in the background. If the request to the server fails then a toast notification will be displayed and the setting will be reverted it its value before set() was called. | -| [stop()](./kibana-plugin-public.uisettingsclient.stop.md) | | Prepares the uiSettingsClient to be discarded, completing any update$ observables that have been created. | - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.overridelocaldefault.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.overridelocaldefault.md deleted file mode 100644 index b94fe72fff102..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.overridelocaldefault.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [overrideLocalDefault](./kibana-plugin-public.uisettingsclient.overridelocaldefault.md) - -## UiSettingsClient.overrideLocalDefault() method - -Overrides the default value for a setting in this specific browser tab. If the page is reloaded the default override is lost. - -Signature: - -```typescript -overrideLocalDefault(key: string, newDefault: any): void; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | -| newDefault | any | | - -Returns: - -`void` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.set.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.set.md deleted file mode 100644 index ad1d97b8fe9b3..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.set.md +++ /dev/null @@ -1,25 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [set](./kibana-plugin-public.uisettingsclient.set.md) - -## UiSettingsClient.set() method - -Sets the value for a uiSetting. If the setting is not defined in the uiSettingDefaults it will be stored as a custom setting. The new value will be synchronously available via the `get()` method and sent to the server in the background. If the request to the server fails then a toast notification will be displayed and the setting will be reverted it its value before `set()` was called. - -Signature: - -```typescript -set(key: string, val: any): Promise; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| key | string | | -| val | any | | - -Returns: - -`Promise` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclient.stop.md b/docs/development/core/public/kibana-plugin-public.uisettingsclient.stop.md deleted file mode 100644 index 215a94544d2d0..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclient.stop.md +++ /dev/null @@ -1,17 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClient](./kibana-plugin-public.uisettingsclient.md) > [stop](./kibana-plugin-public.uisettingsclient.stop.md) - -## UiSettingsClient.stop() method - -Prepares the uiSettingsClient to be discarded, completing any update$ observables that have been created. - -Signature: - -```typescript -stop(): void; -``` -Returns: - -`void` - diff --git a/docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md b/docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md deleted file mode 100644 index 7173386d88265..0000000000000 --- a/docs/development/core/public/kibana-plugin-public.uisettingsclientcontract.md +++ /dev/null @@ -1,13 +0,0 @@ - - -[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [UiSettingsClientContract](./kibana-plugin-public.uisettingsclientcontract.md) - -## UiSettingsClientContract type - -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) - -Signature: - -```typescript -export declare type UiSettingsClientContract = PublicMethodsOf; -``` diff --git a/docs/development/core/server/kibana-plugin-server.contextsetup.md b/docs/development/core/server/kibana-plugin-server.contextsetup.md index 67504faf0534a..1f285efe92b68 100644 --- a/docs/development/core/server/kibana-plugin-server.contextsetup.md +++ b/docs/development/core/server/kibana-plugin-server.contextsetup.md @@ -85,7 +85,7 @@ Say we're creating a plugin for rendering visualizations that allows new renderi export interface VizRenderContext { core: { i18n: I18nStart; - uiSettings: UISettingsClientContract; + uiSettings: IUiSettingsClient; } [contextName: string]: unknown; } diff --git a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.get.md b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.get.md index 0ec3ac45c6cb5..a73061f457a4b 100644 --- a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.get.md +++ b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.get.md @@ -9,5 +9,5 @@ Retrieves uiSettings values set by the user with fallbacks to default values if Signature: ```typescript -get: (key: string) => Promise; +get: (key: string) => Promise; ``` diff --git a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getall.md b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getall.md index d6765a5e5407e..600116b86d1c0 100644 --- a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getall.md +++ b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getall.md @@ -9,5 +9,5 @@ Retrieves a set of all uiSettings values set by the user with fallbacks to defau Signature: ```typescript -getAll: () => Promise>; +getAll: () => Promise>; ``` diff --git a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getuserprovided.md b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getuserprovided.md index 134039cfa91f3..94b7575519cee 100644 --- a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getuserprovided.md +++ b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.getuserprovided.md @@ -9,5 +9,5 @@ Retrieves a set of all uiSettings values set by the user. Signature: ```typescript -getUserProvided: () => Promise>>; +getUserProvided: () => Promise>>; ``` diff --git a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.md b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.md index a4697ddbbb85e..c254321e02291 100644 --- a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.md +++ b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.md @@ -16,13 +16,13 @@ export interface IUiSettingsClient | Property | Type | Description | | --- | --- | --- | -| [get](./kibana-plugin-server.iuisettingsclient.get.md) | <T extends SavedObjectAttribute = any>(key: string) => Promise<T> | Retrieves uiSettings values set by the user with fallbacks to default values if not specified. | -| [getAll](./kibana-plugin-server.iuisettingsclient.getall.md) | <T extends SavedObjectAttribute = any>() => Promise<Record<string, T>> | Retrieves a set of all uiSettings values set by the user with fallbacks to default values if not specified. | +| [get](./kibana-plugin-server.iuisettingsclient.get.md) | <T = any>(key: string) => Promise<T> | Retrieves uiSettings values set by the user with fallbacks to default values if not specified. | +| [getAll](./kibana-plugin-server.iuisettingsclient.getall.md) | <T = any>() => Promise<Record<string, T>> | Retrieves a set of all uiSettings values set by the user with fallbacks to default values if not specified. | | [getRegistered](./kibana-plugin-server.iuisettingsclient.getregistered.md) | () => Readonly<Record<string, UiSettingsParams>> | Returns registered uiSettings values [UiSettingsParams](./kibana-plugin-server.uisettingsparams.md) | -| [getUserProvided](./kibana-plugin-server.iuisettingsclient.getuserprovided.md) | <T extends SavedObjectAttribute = any>() => Promise<Record<string, UserProvidedValues<T>>> | Retrieves a set of all uiSettings values set by the user. | +| [getUserProvided](./kibana-plugin-server.iuisettingsclient.getuserprovided.md) | <T = any>() => Promise<Record<string, UserProvidedValues<T>>> | Retrieves a set of all uiSettings values set by the user. | | [isOverridden](./kibana-plugin-server.iuisettingsclient.isoverridden.md) | (key: string) => boolean | Shows whether the uiSettings value set by the user. | | [remove](./kibana-plugin-server.iuisettingsclient.remove.md) | (key: string) => Promise<void> | Removes uiSettings value by key. | | [removeMany](./kibana-plugin-server.iuisettingsclient.removemany.md) | (keys: string[]) => Promise<void> | Removes multiple uiSettings values by keys. | -| [set](./kibana-plugin-server.iuisettingsclient.set.md) | <T extends SavedObjectAttribute = any>(key: string, value: T) => Promise<void> | Writes uiSettings value and marks it as set by the user. | -| [setMany](./kibana-plugin-server.iuisettingsclient.setmany.md) | <T extends SavedObjectAttribute = any>(changes: Record<string, T>) => Promise<void> | Writes multiple uiSettings values and marks them as set by the user. | +| [set](./kibana-plugin-server.iuisettingsclient.set.md) | (key: string, value: any) => Promise<void> | Writes uiSettings value and marks it as set by the user. | +| [setMany](./kibana-plugin-server.iuisettingsclient.setmany.md) | (changes: Record<string, any>) => Promise<void> | Writes multiple uiSettings values and marks them as set by the user. | diff --git a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.set.md b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.set.md index bc67d05b3f0ee..5d5897a7159ad 100644 --- a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.set.md +++ b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.set.md @@ -9,5 +9,5 @@ Writes uiSettings value and marks it as set by the user. Signature: ```typescript -set: (key: string, value: T) => Promise; +set: (key: string, value: any) => Promise; ``` diff --git a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.setmany.md b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.setmany.md index ec2c24951f0ec..e1d2595d8e1c7 100644 --- a/docs/development/core/server/kibana-plugin-server.iuisettingsclient.setmany.md +++ b/docs/development/core/server/kibana-plugin-server.iuisettingsclient.setmany.md @@ -9,5 +9,5 @@ Writes multiple uiSettings values and marks them as set by the user. Signature: ```typescript -setMany: (changes: Record) => Promise; +setMany: (changes: Record) => Promise; ``` diff --git a/docs/development/core/server/kibana-plugin-server.userprovidedvalues.md b/docs/development/core/server/kibana-plugin-server.userprovidedvalues.md index 7b2114404d7f2..e0f5f7fadd12f 100644 --- a/docs/development/core/server/kibana-plugin-server.userprovidedvalues.md +++ b/docs/development/core/server/kibana-plugin-server.userprovidedvalues.md @@ -9,7 +9,7 @@ Describes the values explicitly set by user. Signature: ```typescript -export interface UserProvidedValues +export interface UserProvidedValues ``` ## Properties diff --git a/src/core/MIGRATION.md b/src/core/MIGRATION.md index e88f1675114bc..7c1489a345e55 100644 --- a/src/core/MIGRATION.md +++ b/src/core/MIGRATION.md @@ -1246,6 +1246,38 @@ This table shows where these uiExports have moved to in the New Platform. In mos | `visTypes` | | | | `visualize` | | | +Examples: + +- **uiSettingDefaults** + +Before: +```js +uiExports: { + uiSettingDefaults: { + 'my-plugin:my-setting': { + name: 'just-work', + value: true, + description: 'make it work', + category: ['my-category'], + }, + } +} +``` +After: +```ts +// src/plugins/my-plugin/server/plugin.ts +setup(core: CoreSetup){ + core.uiSettings.register({ + 'my-plugin:my-setting': { + name: 'just-work', + value: true, + description: 'make it work', + category: ['my-category'], + }, + }) +} +``` + ## How to ### Configure plugin diff --git a/src/core/public/application/types.ts b/src/core/public/application/types.ts index 5be22ea151c32..6313a27b6b821 100644 --- a/src/core/public/application/types.ts +++ b/src/core/public/application/types.ts @@ -28,7 +28,7 @@ import { I18nStart } from '../i18n'; import { NotificationsStart } from '../notifications'; import { OverlayStart } from '../overlays'; import { PluginOpaqueId } from '../plugins'; -import { UiSettingsClientContract } from '../ui_settings'; +import { IUiSettingsClient } from '../ui_settings'; import { RecursiveReadonly } from '../../utils'; /** @public */ @@ -118,8 +118,8 @@ export interface AppMountContext { notifications: NotificationsStart; /** {@link OverlayStart} */ overlays: OverlayStart; - /** {@link UiSettingsClient} */ - uiSettings: UiSettingsClientContract; + /** {@link IUiSettingsClient} */ + uiSettings: IUiSettingsClient; /** * 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 diff --git a/src/core/public/context/context_service.ts b/src/core/public/context/context_service.ts index e39292f87d7b9..7860b486da959 100644 --- a/src/core/public/context/context_service.ts +++ b/src/core/public/context/context_service.ts @@ -47,7 +47,7 @@ export class ContextService { * export interface VizRenderContext { * core: { * i18n: I18nStart; - * uiSettings: UISettingsClientContract; + * uiSettings: IUiSettingsClient; * } * [contextName: string]: unknown; * } diff --git a/src/core/public/index.ts b/src/core/public/index.ts index c723c282a7caa..cfec03427f3e7 100644 --- a/src/core/public/index.ts +++ b/src/core/public/index.ts @@ -62,7 +62,7 @@ import { InjectedMetadataSetup, InjectedMetadataStart, LegacyNavLink } from './i import { NotificationsSetup, NotificationsStart } from './notifications'; import { OverlayStart } from './overlays'; import { Plugin, PluginInitializer, PluginInitializerContext, PluginOpaqueId } from './plugins'; -import { UiSettingsClient, UiSettingsState, UiSettingsClientContract } from './ui_settings'; +import { UiSettingsState, IUiSettingsClient } from './ui_settings'; import { ApplicationSetup, Capabilities, ApplicationStart } from './application'; import { DocLinksStart } from './doc_links'; import { SavedObjectsStart } from './saved_objects'; @@ -157,8 +157,8 @@ export interface CoreSetup { http: HttpSetup; /** {@link NotificationsSetup} */ notifications: NotificationsSetup; - /** {@link UiSettingsClient} */ - uiSettings: UiSettingsClientContract; + /** {@link IUiSettingsClient} */ + uiSettings: IUiSettingsClient; /** * 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 @@ -196,8 +196,8 @@ export interface CoreStart { notifications: NotificationsStart; /** {@link OverlayStart} */ overlays: OverlayStart; - /** {@link UiSettingsClient} */ - uiSettings: UiSettingsClientContract; + /** {@link IUiSettingsClient} */ + uiSettings: IUiSettingsClient; /** * 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 @@ -281,7 +281,6 @@ export { PluginInitializerContext, SavedObjectsStart, PluginOpaqueId, - UiSettingsClient, - UiSettingsClientContract, + IUiSettingsClient, UiSettingsState, }; diff --git a/src/core/public/integrations/integrations_service.ts b/src/core/public/integrations/integrations_service.ts index 5d5c31c2df18c..f85650ced430d 100644 --- a/src/core/public/integrations/integrations_service.ts +++ b/src/core/public/integrations/integrations_service.ts @@ -17,14 +17,14 @@ * under the License. */ -import { UiSettingsClientContract } from '../ui_settings'; +import { IUiSettingsClient } from '../ui_settings'; import { CoreService } from '../../types'; import { MomentService } from './moment'; import { StylesService } from './styles'; interface Deps { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/core/public/integrations/moment/moment_service.ts b/src/core/public/integrations/moment/moment_service.ts index 2714750d9a65e..65f2bdea02933 100644 --- a/src/core/public/integrations/moment/moment_service.ts +++ b/src/core/public/integrations/moment/moment_service.ts @@ -21,11 +21,11 @@ import moment from 'moment-timezone'; import { merge, Subscription } from 'rxjs'; import { tap } from 'rxjs/operators'; -import { UiSettingsClientContract } from '../../ui_settings'; +import { IUiSettingsClient } from '../../ui_settings'; import { CoreService } from '../../../types'; interface StartDeps { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/core/public/integrations/styles/styles_service.ts b/src/core/public/integrations/styles/styles_service.ts index ba8b812fe9988..41fc861d6cb39 100644 --- a/src/core/public/integrations/styles/styles_service.ts +++ b/src/core/public/integrations/styles/styles_service.ts @@ -19,13 +19,13 @@ import { Subscription } from 'rxjs'; -import { UiSettingsClientContract } from '../../ui_settings'; +import { IUiSettingsClient } from '../../ui_settings'; import { CoreService } from '../../../types'; // @ts-ignore import disableAnimationsCss from '!!raw-loader!./disable_animations.css'; interface StartDeps { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/core/public/notifications/notifications_service.ts b/src/core/public/notifications/notifications_service.ts index 2c14f2f650078..82dadf4746567 100644 --- a/src/core/public/notifications/notifications_service.ts +++ b/src/core/public/notifications/notifications_service.ts @@ -22,11 +22,11 @@ import { i18n } from '@kbn/i18n'; import { Subscription } from 'rxjs'; import { I18nStart } from '../i18n'; import { ToastsService, ToastsSetup, ToastsStart } from './toasts'; -import { UiSettingsClientContract } from '../ui_settings'; +import { IUiSettingsClient } from '../ui_settings'; import { OverlayStart } from '../overlays'; interface SetupDeps { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } interface StartDeps { diff --git a/src/core/public/notifications/toasts/toasts_api.tsx b/src/core/public/notifications/toasts/toasts_api.tsx index a21b727b02d73..8b1850ff9508f 100644 --- a/src/core/public/notifications/toasts/toasts_api.tsx +++ b/src/core/public/notifications/toasts/toasts_api.tsx @@ -24,7 +24,7 @@ import * as Rx from 'rxjs'; import { ErrorToast } from './error_toast'; import { MountPoint } from '../../types'; import { mountReactNode } from '../../utils'; -import { UiSettingsClientContract } from '../../ui_settings'; +import { IUiSettingsClient } from '../../ui_settings'; import { OverlayStart } from '../../overlays'; import { I18nStart } from '../../i18n'; @@ -94,12 +94,12 @@ export type IToasts = Pick< export class ToastsApi implements IToasts { private toasts$ = new Rx.BehaviorSubject([]); private idCounter = 0; - private uiSettings: UiSettingsClientContract; + private uiSettings: IUiSettingsClient; private overlays?: OverlayStart; private i18n?: I18nStart; - constructor(deps: { uiSettings: UiSettingsClientContract }) { + constructor(deps: { uiSettings: IUiSettingsClient }) { this.uiSettings = deps.uiSettings; } diff --git a/src/core/public/notifications/toasts/toasts_service.tsx b/src/core/public/notifications/toasts/toasts_service.tsx index 81d23afc4f4d3..619a3fe952abb 100644 --- a/src/core/public/notifications/toasts/toasts_service.tsx +++ b/src/core/public/notifications/toasts/toasts_service.tsx @@ -21,13 +21,13 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { I18nStart } from '../../i18n'; -import { UiSettingsClientContract } from '../../ui_settings'; +import { IUiSettingsClient } from '../../ui_settings'; import { GlobalToastList } from './global_toast_list'; import { ToastsApi, IToasts } from './toasts_api'; import { OverlayStart } from '../../overlays'; interface SetupDeps { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } interface StartDeps { diff --git a/src/core/public/overlays/banners/banners_service.tsx b/src/core/public/overlays/banners/banners_service.tsx index a26a7c71bc61f..ed59ed819b1c2 100644 --- a/src/core/public/overlays/banners/banners_service.tsx +++ b/src/core/public/overlays/banners/banners_service.tsx @@ -23,7 +23,7 @@ import { map } from 'rxjs/operators'; import { PriorityMap } from './priority_map'; import { BannersList } from './banners_list'; -import { UiSettingsClientContract } from '../../ui_settings'; +import { IUiSettingsClient } from '../../ui_settings'; import { I18nStart } from '../../i18n'; import { MountPoint } from '../../types'; import { UserBannerService } from './user_banner_service'; @@ -73,7 +73,7 @@ export interface OverlayBanner { interface StartDeps { i18n: I18nStart; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/core/public/overlays/banners/user_banner_service.tsx b/src/core/public/overlays/banners/user_banner_service.tsx index b258e2127883d..e3f4d9dee5b78 100644 --- a/src/core/public/overlays/banners/user_banner_service.tsx +++ b/src/core/public/overlays/banners/user_banner_service.tsx @@ -27,13 +27,13 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiCallOut, EuiButton } from '@elastic/eui'; import { I18nStart } from '../../i18n'; -import { UiSettingsClientContract } from '../../ui_settings'; +import { IUiSettingsClient } from '../../ui_settings'; import { OverlayBannersStart } from './banners_service'; interface StartDeps { banners: OverlayBannersStart; i18n: I18nStart; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** diff --git a/src/core/public/overlays/overlay_service.ts b/src/core/public/overlays/overlay_service.ts index 82fe753d6f283..f628182e965d8 100644 --- a/src/core/public/overlays/overlay_service.ts +++ b/src/core/public/overlays/overlay_service.ts @@ -18,7 +18,7 @@ */ import { I18nStart } from '../i18n'; -import { UiSettingsClientContract } from '../ui_settings'; +import { IUiSettingsClient } from '../ui_settings'; import { OverlayBannersStart, OverlayBannersService } from './banners'; import { FlyoutService, OverlayFlyoutStart } from './flyout'; import { ModalService, OverlayModalStart } from './modal'; @@ -26,7 +26,7 @@ import { ModalService, OverlayModalStart } from './modal'; interface StartDeps { i18n: I18nStart; targetDomElement: HTMLElement; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index 30a98c9046ff5..bde148f1e1e4a 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -63,7 +63,7 @@ export interface AppMountContext { i18n: I18nStart; notifications: NotificationsStart; overlays: OverlayStart; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; injectedMetadata: { getInjectedVar: (name: string, defaultValue?: any) => unknown; }; @@ -289,7 +289,7 @@ export interface CoreSetup { // (undocumented) notifications: NotificationsSetup; // (undocumented) - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } // @public @@ -315,7 +315,7 @@ export interface CoreStart { // (undocumented) savedObjects: SavedObjectsStart; // (undocumented) - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } // @internal @@ -621,6 +621,31 @@ export interface InterceptedHttpResponse { // @public export type IToasts = Pick; +// @public +export interface IUiSettingsClient { + get$: (key: string, defaultOverride?: T) => Observable; + get: (key: string, defaultOverride?: T) => T; + getAll: () => Readonly>; + getSaved$: () => Observable<{ + key: string; + newValue: T; + oldValue: T; + }>; + getUpdate$: () => Observable<{ + key: string; + newValue: T; + oldValue: T; + }>; + getUpdateErrors$: () => Observable; + isCustom: (key: string) => boolean; + isDeclared: (key: string) => boolean; + isDefault: (key: string) => boolean; + isOverridden: (key: string) => boolean; + overrideLocalDefault: (key: string, newDefault: any) => void; + remove: (key: string) => Promise; + set: (key: string, value: any) => Promise; +} + // @public @deprecated export interface LegacyCoreSetup extends CoreSetup { // Warning: (ae-forgotten-export) The symbol "InjectedMetadataSetup" needs to be exported by the entry point index.d.ts @@ -968,7 +993,7 @@ export type ToastInputFields = Pick; - get(key: string, defaultOverride?: any): any; - getAll(): Record>; - getSaved$(): Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>; - getUpdate$(): Rx.Observable<{ - key: string; - newValue: any; - oldValue: any; - }>; - getUpdateErrors$(): Rx.Observable; - isCustom(key: string): boolean; - isDeclared(key: string): boolean; - isDefault(key: string): boolean; - isOverridden(key: string): boolean; - overrideLocalDefault(key: string, newDefault: any): void; - remove(key: string): Promise; - set(key: string, val: any): Promise; - stop(): void; - } - -// @public -export type UiSettingsClientContract = PublicMethodsOf; - // @public (undocumented) export interface UiSettingsState { // (undocumented) diff --git a/src/core/public/ui_settings/__snapshots__/ui_settings_client.test.ts.snap b/src/core/public/ui_settings/__snapshots__/ui_settings_client.test.ts.snap index e49c546f3550c..cd233704d2f54 100644 --- a/src/core/public/ui_settings/__snapshots__/ui_settings_client.test.ts.snap +++ b/src/core/public/ui_settings/__snapshots__/ui_settings_client.test.ts.snap @@ -1,26 +1,26 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`#get after a get for an unknown property, the property is not persisted 1`] = ` -"Unexpected \`config.get(\\"obscureProperty2\\")\` call on unrecognized configuration setting \\"obscureProperty2\\". -Setting an initial value via \`config.set(\\"obscureProperty2\\", value)\` before attempting to retrieve +"Unexpected \`IUiSettingsClient.get(\\"obscureProperty2\\")\` call on unrecognized configuration setting \\"obscureProperty2\\". +Setting an initial value via \`IUiSettingsClient.set(\\"obscureProperty2\\", value)\` before attempting to retrieve any custom setting value for \\"obscureProperty2\\" may fix this issue. -You can use \`config.get(\\"obscureProperty2\\", defaultValue)\`, which will just return +You can use \`IUiSettingsClient.get(\\"obscureProperty2\\", defaultValue)\`, which will just return \`defaultValue\` when the key is unrecognized." `; -exports[`#get gives access to config values 1`] = `"Browser"`; +exports[`#get gives access to uiSettings values 1`] = `"Browser"`; exports[`#get supports the default value overload 1`] = `"default"`; exports[`#get throws on unknown properties that don't have a value yet. 1`] = ` -"Unexpected \`config.get(\\"throwableProperty\\")\` call on unrecognized configuration setting \\"throwableProperty\\". -Setting an initial value via \`config.set(\\"throwableProperty\\", value)\` before attempting to retrieve +"Unexpected \`IUiSettingsClient.get(\\"throwableProperty\\")\` call on unrecognized configuration setting \\"throwableProperty\\". +Setting an initial value via \`IUiSettingsClient.set(\\"throwableProperty\\", value)\` before attempting to retrieve any custom setting value for \\"throwableProperty\\" may fix this issue. -You can use \`config.get(\\"throwableProperty\\", defaultValue)\`, which will just return +You can use \`IUiSettingsClient.get(\\"throwableProperty\\", defaultValue)\`, which will just return \`defaultValue\` when the key is unrecognized." `; -exports[`#getUpdate$ sends { key, newValue, oldValue } notifications when config changes 1`] = ` +exports[`#getUpdate$ sends { key, newValue, oldValue } notifications when client changes 1`] = ` Array [ Array [ Object { @@ -32,7 +32,7 @@ Array [ ] `; -exports[`#getUpdate$ sends { key, newValue, oldValue } notifications when config changes 2`] = ` +exports[`#getUpdate$ sends { key, newValue, oldValue } notifications when client changes 2`] = ` Array [ Array [ Object { diff --git a/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap b/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap deleted file mode 100644 index 84f9a5ab7c5cd..0000000000000 --- a/src/core/public/ui_settings/__snapshots__/ui_settings_service.test.ts.snap +++ /dev/null @@ -1,117 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`#setup constructs UiSettingsClient and UiSettingsApi: UiSettingsApi args 1`] = ` -[MockFunction MockUiSettingsApi] { - "calls": Array [ - Array [ - Object { - "addLoadingCount": [MockFunction] { - "calls": Array [ - Array [ - Object { - "loadingCountObservable": true, - }, - ], - ], - "results": Array [ - Object { - "type": "return", - "value": undefined, - }, - ], - }, - "anonymousPaths": AnonymousPaths { - "basePath": BasePath { - "basePath": "", - "get": [Function], - "prepend": [Function], - "remove": [Function], - }, - "paths": Set {}, - }, - "basePath": BasePath { - "basePath": "", - "get": [Function], - "prepend": [Function], - "remove": [Function], - }, - "delete": [MockFunction], - "fetch": [MockFunction], - "get": [MockFunction], - "getLoadingCount$": [MockFunction], - "head": [MockFunction], - "intercept": [MockFunction], - "options": [MockFunction], - "patch": [MockFunction], - "post": [MockFunction], - "put": [MockFunction], - "removeAllInterceptors": [MockFunction], - "stop": [MockFunction], - }, - ], - ], - "results": Array [ - Object { - "type": "return", - "value": undefined, - }, - ], -} -`; - -exports[`#setup constructs UiSettingsClient and UiSettingsApi: UiSettingsClient args 1`] = ` -[MockFunction MockUiSettingsClient] { - "calls": Array [ - Array [ - Object { - "api": MockUiSettingsApi { - "getLoadingCount$": [MockFunction] { - "calls": Array [ - Array [], - ], - "results": Array [ - Object { - "type": "return", - "value": Object { - "loadingCountObservable": true, - }, - }, - ], - }, - "stop": [MockFunction], - }, - "defaults": Object { - "legacyInjectedUiSettingDefaults": true, - }, - "initialSettings": Object { - "legacyInjectedUiSettingUserValues": true, - }, - }, - ], - ], - "results": Array [ - Object { - "type": "return", - "value": undefined, - }, - ], -} -`; - -exports[`#setup passes the uiSettings loading count to the loading count api: http.addLoadingCount calls 1`] = ` -[MockFunction] { - "calls": Array [ - Array [ - Object { - "loadingCountObservable": true, - }, - ], - ], - "results": Array [ - Object { - "type": "return", - "value": undefined, - }, - ], -} -`; diff --git a/src/core/public/ui_settings/index.ts b/src/core/public/ui_settings/index.ts index 7f10cfb1539d7..d94f85db31bb6 100644 --- a/src/core/public/ui_settings/index.ts +++ b/src/core/public/ui_settings/index.ts @@ -18,5 +18,5 @@ */ export { UiSettingsService } from './ui_settings_service'; -export { UiSettingsClient, UiSettingsClientContract } from './ui_settings_client'; -export { UiSettingsState } from './types'; +export { UiSettingsClient } from './ui_settings_client'; +export { UiSettingsState, IUiSettingsClient } from './types'; diff --git a/src/core/public/ui_settings/types.ts b/src/core/public/ui_settings/types.ts index 24e87eb04f026..19fd91924f247 100644 --- a/src/core/public/ui_settings/types.ts +++ b/src/core/public/ui_settings/types.ts @@ -17,9 +17,112 @@ * under the License. */ +import { Observable } from 'rxjs'; import { UiSettingsParams, UserProvidedValues } from 'src/core/server/types'; /** @public */ export interface UiSettingsState { [key: string]: UiSettingsParams & UserProvidedValues; } + +/** + * 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. + * {@link IUiSettingsClient} + * + * @public + */ +export interface IUiSettingsClient { + /** + * Gets the value for a specific uiSetting. If this setting has no user-defined value + * then the `defaultOverride` parameter is returned (and parsed if setting is of type + * "json" or "number). If the parameter is not defined and the key is not registered + * by any plugin then an error is thrown, otherwise reads the default value defined by a plugin. + */ + get: (key: string, defaultOverride?: T) => T; + + /** + * Gets an observable of the current value for a config key, and all updates to that config + * key in the future. Providing a `defaultOverride` argument behaves the same as it does in #get() + */ + get$: (key: string, defaultOverride?: T) => Observable; + + /** + * Gets the metadata about all uiSettings, including the type, default value, and user value + * for each key. + */ + getAll: () => Readonly>; + + /** + * Sets the value for a uiSetting. If the setting is not registered by any plugin + * it will be stored as a custom setting. The new value will be synchronously available via + * the `get()` method and sent to the server in the background. If the request to the + * server fails then a updateErrors$ will be notified and the setting will be + * reverted to its value before `set()` was called. + */ + set: (key: string, value: any) => Promise; + + /** + * Overrides the default value for a setting in this specific browser tab. If the page + * is reloaded the default override is lost. + */ + overrideLocalDefault: (key: string, newDefault: any) => void; + + /** + * Removes the user-defined value for a setting, causing it to revert to the default. This + * method behaves the same as calling `set(key, null)`, including the synchronization, custom + * setting, and error behavior of that method. + */ + remove: (key: string) => Promise; + + /** + * Returns true if the key is a "known" uiSetting, meaning it is either registered + * by any plugin or was previously added as a custom setting via the `set()` method. + */ + isDeclared: (key: string) => boolean; + + /** + * Returns true if the setting has no user-defined value or is unknown + */ + isDefault: (key: string) => boolean; + + /** + * Returns true if the setting wasn't registered by any plugin, but was either + * added directly via `set()`, or is an unknown setting found in the uiSettings saved + * object + */ + isCustom: (key: string) => boolean; + + /** + * Shows whether the uiSettings value set by the user. + */ + isOverridden: (key: string) => boolean; + + /** + * Returns an Observable that notifies subscribers of each update to the uiSettings, + * including the key, newValue, and oldValue of the setting that changed. + */ + getUpdate$: () => Observable<{ + key: string; + newValue: T; + oldValue: T; + }>; + + /** + * Returns an Observable that notifies subscribers of each update to the uiSettings, + * including the key, newValue, and oldValue of the setting that changed. + */ + getSaved$: () => Observable<{ + key: string; + newValue: T; + oldValue: T; + }>; + + /** + * Returns an Observable that notifies subscribers of each error while trying to update + * the settings, containing the actual Error class. + */ + getUpdateErrors$: () => Observable; +} diff --git a/src/core/public/ui_settings/ui_settings_client.test.ts b/src/core/public/ui_settings/ui_settings_client.test.ts index c58ba14d0da3e..f394036e3e046 100644 --- a/src/core/public/ui_settings/ui_settings_client.test.ts +++ b/src/core/public/ui_settings/ui_settings_client.test.ts @@ -16,72 +16,79 @@ * specific language governing permissions and limitations * under the License. */ - +import { Subject } from 'rxjs'; import { materialize, take, toArray } from 'rxjs/operators'; import { UiSettingsClient } from './ui_settings_client'; +let done$: Subject; + function setup(options: { defaults?: any; initialSettings?: any } = {}) { const { defaults = { dateFormat: { value: 'Browser' } }, initialSettings = {} } = options; const batchSet = jest.fn(() => ({ settings: {}, })); - - const config = new UiSettingsClient({ + done$ = new Subject(); + const client = new UiSettingsClient({ defaults, initialSettings, api: { batchSet, } as any, + done$, }); - return { config, batchSet }; + return { client, batchSet }; } +afterEach(() => { + done$.complete(); +}); + describe('#get', () => { - it('gives access to config values', () => { - const { config } = setup(); - expect(config.get('dateFormat')).toMatchSnapshot(); + it('gives access to uiSettings values', () => { + const { client } = setup(); + expect(client.get('dateFormat')).toMatchSnapshot(); }); it('supports the default value overload', () => { - const { config } = setup(); + const { client } = setup(); // default values are consumed and returned atomically - expect(config.get('obscureProperty1', 'default')).toMatchSnapshot(); + expect(client.get('obscureProperty1', 'default')).toMatchSnapshot(); }); it('after a get for an unknown property, the property is not persisted', () => { - const { config } = setup(); - config.get('obscureProperty2', 'default'); + const { client } = setup(); + client.get('obscureProperty2', 'default'); // after a get, default values are NOT persisted - expect(() => config.get('obscureProperty2')).toThrowErrorMatchingSnapshot(); + expect(() => client.get('obscureProperty2')).toThrowErrorMatchingSnapshot(); }); it('honors the default parameter for unset options that are exported', () => { - const { config } = setup(); - // if you are hitting this error, then a test is setting this config value globally and not unsetting it! - expect(config.isDefault('dateFormat')).toBe(true); + const { client } = setup(); + // if you are hitting this error, then a test is setting this client value globally and not unsetting it! + expect(client.isDefault('dateFormat')).toBe(true); - const defaultDateFormat = config.get('dateFormat'); + const defaultDateFormat = client.get('dateFormat'); - expect(config.get('dateFormat', 'xyz')).toBe('xyz'); + expect(client.get('dateFormat', 'xyz')).toBe('xyz'); // shouldn't change other usages - expect(config.get('dateFormat')).toBe(defaultDateFormat); - expect(config.get('dataFormat', defaultDateFormat)).toBe(defaultDateFormat); + expect(client.get('dateFormat')).toBe(defaultDateFormat); + expect(client.get('dataFormat', defaultDateFormat)).toBe(defaultDateFormat); }); it("throws on unknown properties that don't have a value yet.", () => { - const { config } = setup(); - expect(() => config.get('throwableProperty')).toThrowErrorMatchingSnapshot(); + const { client } = setup(); + expect(() => client.get('throwableProperty')).toThrowErrorMatchingSnapshot(); }); }); describe('#get$', () => { it('emits the current value when called', async () => { - const { config } = setup(); - const values = await config + const { client } = setup(); + const values = await client .get$('dateFormat') .pipe(take(1), toArray()) .toPromise(); @@ -90,18 +97,18 @@ describe('#get$', () => { }); it('emits an error notification if the key is unknown', async () => { - const { config } = setup(); - const values = await config + const { client } = setup(); + const values = await client .get$('unknown key') .pipe(materialize()) .toPromise(); expect(values).toMatchInlineSnapshot(` Notification { - "error": [Error: Unexpected \`config.get("unknown key")\` call on unrecognized configuration setting "unknown key". -Setting an initial value via \`config.set("unknown key", value)\` before attempting to retrieve + "error": [Error: Unexpected \`IUiSettingsClient.get("unknown key")\` call on unrecognized configuration setting "unknown key". +Setting an initial value via \`IUiSettingsClient.set("unknown key", value)\` before attempting to retrieve any custom setting value for "unknown key" may fix this issue. -You can use \`config.get("unknown key", defaultValue)\`, which will just return +You can use \`IUiSettingsClient.get("unknown key", defaultValue)\`, which will just return \`defaultValue\` when the key is unrecognized.], "hasValue": false, "kind": "E", @@ -111,13 +118,13 @@ You can use \`config.get("unknown key", defaultValue)\`, which will just return }); it('emits the new value when it changes', async () => { - const { config } = setup(); + const { client } = setup(); setTimeout(() => { - config.set('dateFormat', 'new format'); + client.set('dateFormat', 'new format'); }, 10); - const values = await config + const values = await client .get$('dateFormat') .pipe(take(2), toArray()) .toPromise(); @@ -126,17 +133,17 @@ You can use \`config.get("unknown key", defaultValue)\`, which will just return }); it('emits the default override if no value is set, or if the value is removed', async () => { - const { config } = setup(); + const { client } = setup(); setTimeout(() => { - config.set('dateFormat', 'new format'); + client.set('dateFormat', 'new format'); }, 10); setTimeout(() => { - config.remove('dateFormat'); + client.remove('dateFormat'); }, 20); - const values = await config + const values = await client .get$('dateFormat', 'my default') .pipe(take(3), toArray()) .toPromise(); @@ -146,37 +153,37 @@ You can use \`config.get("unknown key", defaultValue)\`, which will just return }); describe('#set', () => { - it('stores a value in the config val set', () => { - const { config } = setup(); - const original = config.get('dateFormat'); - config.set('dateFormat', 'notaformat'); - expect(config.get('dateFormat')).toBe('notaformat'); - config.set('dateFormat', original); + it('stores a value in the client val set', () => { + const { client } = setup(); + const original = client.get('dateFormat'); + client.set('dateFormat', 'notaformat'); + expect(client.get('dateFormat')).toBe('notaformat'); + client.set('dateFormat', original); }); - it('stores a value in a previously unknown config key', () => { - const { config } = setup(); - expect(() => config.set('unrecognizedProperty', 'somevalue')).not.toThrowError(); - expect(config.get('unrecognizedProperty')).toBe('somevalue'); + it('stores a value in a previously unknown client key', () => { + const { client } = setup(); + expect(() => client.set('unrecognizedProperty', 'somevalue')).not.toThrowError(); + expect(client.get('unrecognizedProperty')).toBe('somevalue'); }); it('resolves to true on success', async () => { - const { config } = setup(); - await expect(config.set('foo', 'bar')).resolves.toBe(true); + const { client } = setup(); + await expect(client.set('foo', 'bar')).resolves.toBe(true); }); it('resolves to false on failure', async () => { - const { config, batchSet } = setup(); + const { client, batchSet } = setup(); batchSet.mockImplementation(() => { throw new Error('Error in request'); }); - await expect(config.set('foo', 'bar')).resolves.toBe(false); + await expect(client.set('foo', 'bar')).resolves.toBe(false); }); it('throws an error if key is overridden', async () => { - const { config } = setup({ + const { client } = setup({ initialSettings: { foo: { isOverridden: true, @@ -184,28 +191,28 @@ describe('#set', () => { }, }, }); - await expect(config.set('foo', true)).rejects.toThrowErrorMatchingSnapshot(); + await expect(client.set('foo', true)).rejects.toThrowErrorMatchingSnapshot(); }); }); describe('#remove', () => { it('resolves to true on success', async () => { - const { config } = setup(); - await expect(config.remove('dateFormat')).resolves.toBe(true); + const { client } = setup(); + await expect(client.remove('dateFormat')).resolves.toBe(true); }); it('resolves to false on failure', async () => { - const { config, batchSet } = setup(); + const { client, batchSet } = setup(); batchSet.mockImplementation(() => { throw new Error('Error in request'); }); - await expect(config.remove('dateFormat')).resolves.toBe(false); + await expect(client.remove('dateFormat')).resolves.toBe(false); }); it('throws an error if key is overridden', async () => { - const { config } = setup({ + const { client } = setup({ initialSettings: { bar: { isOverridden: true, @@ -213,81 +220,81 @@ describe('#remove', () => { }, }, }); - await expect(config.remove('bar')).rejects.toThrowErrorMatchingSnapshot(); + await expect(client.remove('bar')).rejects.toThrowErrorMatchingSnapshot(); }); }); describe('#isDeclared', () => { it('returns true if name is know', () => { - const { config } = setup(); - expect(config.isDeclared('dateFormat')).toBe(true); + const { client } = setup(); + expect(client.isDeclared('dateFormat')).toBe(true); }); it('returns false if name is not known', () => { - const { config } = setup(); - expect(config.isDeclared('dateFormat')).toBe(true); + const { client } = setup(); + expect(client.isDeclared('dateFormat')).toBe(true); }); }); describe('#isDefault', () => { it('returns true if value is default', () => { - const { config } = setup(); - expect(config.isDefault('dateFormat')).toBe(true); + const { client } = setup(); + expect(client.isDefault('dateFormat')).toBe(true); }); it('returns false if name is not known', () => { - const { config } = setup(); - config.set('dateFormat', 'foo'); - expect(config.isDefault('dateFormat')).toBe(false); + const { client } = setup(); + client.set('dateFormat', 'foo'); + expect(client.isDefault('dateFormat')).toBe(false); }); }); describe('#isCustom', () => { it('returns false if name is in from defaults', () => { - const { config } = setup(); - expect(config.isCustom('dateFormat')).toBe(false); + const { client } = setup(); + expect(client.isCustom('dateFormat')).toBe(false); }); it('returns false for unknown name', () => { - const { config } = setup(); - expect(config.isCustom('foo')).toBe(false); + const { client } = setup(); + expect(client.isCustom('foo')).toBe(false); }); it('returns true if name is from unknown set()', () => { - const { config } = setup(); - config.set('foo', 'bar'); - expect(config.isCustom('foo')).toBe(true); + const { client } = setup(); + client.set('foo', 'bar'); + expect(client.isCustom('foo')).toBe(true); }); }); describe('#getUpdate$', () => { - it('sends { key, newValue, oldValue } notifications when config changes', () => { + it('sends { key, newValue, oldValue } notifications when client changes', () => { const handler = jest.fn(); - const { config } = setup(); + const { client } = setup(); - config.getUpdate$().subscribe(handler); + client.getUpdate$().subscribe(handler); expect(handler).not.toHaveBeenCalled(); - config.set('foo', 'bar'); + client.set('foo', 'bar'); expect(handler).toHaveBeenCalledTimes(1); expect(handler.mock.calls).toMatchSnapshot(); handler.mockClear(); - config.set('foo', 'baz'); + client.set('foo', 'baz'); expect(handler).toHaveBeenCalledTimes(1); expect(handler.mock.calls).toMatchSnapshot(); }); it('observables complete when client is stopped', () => { const onComplete = jest.fn(); - const { config } = setup(); + const { client } = setup(); - config.getUpdate$().subscribe({ + client.getUpdate$().subscribe({ complete: onComplete, }); expect(onComplete).not.toHaveBeenCalled(); - config.stop(); + done$.complete(); expect(onComplete).toHaveBeenCalled(); }); }); @@ -295,84 +302,84 @@ describe('#getUpdate$', () => { describe('#overrideLocalDefault', () => { describe('key has no user value', () => { it('synchronously modifies the default value returned by get()', () => { - const { config } = setup(); + const { client } = setup(); - expect(config.get('dateFormat')).toMatchSnapshot('get before override'); - config.overrideLocalDefault('dateFormat', 'bar'); - expect(config.get('dateFormat')).toMatchSnapshot('get after override'); + expect(client.get('dateFormat')).toMatchSnapshot('get before override'); + client.overrideLocalDefault('dateFormat', 'bar'); + expect(client.get('dateFormat')).toMatchSnapshot('get after override'); }); it('synchronously modifies the value returned by getAll()', () => { - const { config } = setup(); + const { client } = setup(); - expect(config.getAll()).toMatchSnapshot('getAll before override'); - config.overrideLocalDefault('dateFormat', 'bar'); - expect(config.getAll()).toMatchSnapshot('getAll after override'); + expect(client.getAll()).toMatchSnapshot('getAll before override'); + client.overrideLocalDefault('dateFormat', 'bar'); + expect(client.getAll()).toMatchSnapshot('getAll after override'); }); it('calls subscriber with new and previous value', () => { const handler = jest.fn(); - const { config } = setup(); + const { client } = setup(); - config.getUpdate$().subscribe(handler); - config.overrideLocalDefault('dateFormat', 'bar'); + client.getUpdate$().subscribe(handler); + client.overrideLocalDefault('dateFormat', 'bar'); expect(handler.mock.calls).toMatchSnapshot('single subscriber call'); }); }); describe('key with user value', () => { it('does not modify the return value of get', () => { - const { config } = setup(); + const { client } = setup(); - config.set('dateFormat', 'foo'); - expect(config.get('dateFormat')).toMatchSnapshot('get before override'); - config.overrideLocalDefault('dateFormat', 'bar'); - expect(config.get('dateFormat')).toMatchSnapshot('get after override'); + client.set('dateFormat', 'foo'); + expect(client.get('dateFormat')).toMatchSnapshot('get before override'); + client.overrideLocalDefault('dateFormat', 'bar'); + expect(client.get('dateFormat')).toMatchSnapshot('get after override'); }); it('is included in the return value of getAll', () => { - const { config } = setup(); + const { client } = setup(); - config.set('dateFormat', 'foo'); - expect(config.getAll()).toMatchSnapshot('getAll before override'); - config.overrideLocalDefault('dateFormat', 'bar'); - expect(config.getAll()).toMatchSnapshot('getAll after override'); + client.set('dateFormat', 'foo'); + expect(client.getAll()).toMatchSnapshot('getAll before override'); + client.overrideLocalDefault('dateFormat', 'bar'); + expect(client.getAll()).toMatchSnapshot('getAll after override'); }); it('does not call subscriber', () => { const handler = jest.fn(); - const { config } = setup(); + const { client } = setup(); - config.set('dateFormat', 'foo'); - config.getUpdate$().subscribe(handler); - config.overrideLocalDefault('dateFormat', 'bar'); + client.set('dateFormat', 'foo'); + client.getUpdate$().subscribe(handler); + client.overrideLocalDefault('dateFormat', 'bar'); expect(handler).not.toHaveBeenCalled(); }); it('returns default override when setting removed', () => { - const { config } = setup(); + const { client } = setup(); - config.set('dateFormat', 'foo'); - config.overrideLocalDefault('dateFormat', 'bar'); + client.set('dateFormat', 'foo'); + client.overrideLocalDefault('dateFormat', 'bar'); - expect(config.get('dateFormat')).toMatchSnapshot('get before override'); - expect(config.getAll()).toMatchSnapshot('getAll before override'); + expect(client.get('dateFormat')).toMatchSnapshot('get before override'); + expect(client.getAll()).toMatchSnapshot('getAll before override'); - config.remove('dateFormat'); + client.remove('dateFormat'); - expect(config.get('dateFormat')).toMatchSnapshot('get after override'); - expect(config.getAll()).toMatchSnapshot('getAll after override'); + expect(client.get('dateFormat')).toMatchSnapshot('get after override'); + expect(client.getAll()).toMatchSnapshot('getAll after override'); }); }); describe('#isOverridden()', () => { it('returns false if key is unknown', () => { - const { config } = setup(); - expect(config.isOverridden('foo')).toBe(false); + const { client } = setup(); + expect(client.isOverridden('foo')).toBe(false); }); it('returns false if key is no overridden', () => { - const { config } = setup({ + const { client } = setup({ initialSettings: { foo: { userValue: 1, @@ -383,11 +390,11 @@ describe('#overrideLocalDefault', () => { }, }, }); - expect(config.isOverridden('foo')).toBe(false); + expect(client.isOverridden('foo')).toBe(false); }); it('returns true when key is overridden', () => { - const { config } = setup({ + const { client } = setup({ initialSettings: { foo: { userValue: 1, @@ -398,12 +405,12 @@ describe('#overrideLocalDefault', () => { }, }, }); - expect(config.isOverridden('bar')).toBe(true); + expect(client.isOverridden('bar')).toBe(true); }); it('returns false for object prototype properties', () => { - const { config } = setup(); - expect(config.isOverridden('hasOwnProperty')).toBe(false); + const { client } = setup(); + expect(client.isOverridden('hasOwnProperty')).toBe(false); }); }); }); diff --git a/src/core/public/ui_settings/ui_settings_client.ts b/src/core/public/ui_settings/ui_settings_client.ts index c3190847130d5..f0071ed08435c 100644 --- a/src/core/public/ui_settings/ui_settings_client.ts +++ b/src/core/public/ui_settings/ui_settings_client.ts @@ -18,37 +18,25 @@ */ import { cloneDeep, defaultsDeep } from 'lodash'; -import * as Rx from 'rxjs'; +import { Observable, Subject, concat, defer, of } from 'rxjs'; import { filter, map } from 'rxjs/operators'; import { UiSettingsParams, UserProvidedValues } from 'src/core/server/types'; -import { UiSettingsState } from './types'; +import { IUiSettingsClient, UiSettingsState } from './types'; import { UiSettingsApi } from './ui_settings_api'; -/** @public */ interface UiSettingsClientParams { api: UiSettingsApi; defaults: Record; initialSettings?: UiSettingsState; + done$: Observable; } -/** - * 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. - * {@link UiSettingsClient} - * - * @public - */ -export type UiSettingsClientContract = PublicMethodsOf; - -/** @public */ -export class UiSettingsClient { - private readonly update$ = new Rx.Subject<{ key: string; newValue: any; oldValue: any }>(); - private readonly saved$ = new Rx.Subject<{ key: string; newValue: any; oldValue: any }>(); - private readonly updateErrors$ = new Rx.Subject(); +export class UiSettingsClient implements IUiSettingsClient { + private readonly update$ = new Subject<{ key: string; newValue: any; oldValue: any }>(); + private readonly saved$ = new Subject<{ key: string; newValue: any; oldValue: any }>(); + private readonly updateErrors$ = new Subject(); private readonly api: UiSettingsApi; private readonly defaults: Record; @@ -58,24 +46,21 @@ export class UiSettingsClient { this.api = params.api; this.defaults = cloneDeep(params.defaults); this.cache = defaultsDeep({}, this.defaults, cloneDeep(params.initialSettings)); + + params.done$.subscribe({ + complete: () => { + this.update$.complete(); + this.saved$.complete(); + this.updateErrors$.complete(); + }, + }); } - /** - * Gets the metadata about all uiSettings, including the type, default value, and user value - * for each key. - */ - public getAll() { + getAll() { return cloneDeep(this.cache); } - /** - * Gets the value for a specific uiSetting. If this setting has no user-defined value - * then the `defaultOverride` parameter is returned (and parsed if setting is of type - * "json" or "number). If the parameter is not defined and the key is not defined by a - * uiSettingDefaults then an error is thrown, otherwise the default is read - * from the uiSettingDefaults. - */ - public get(key: string, defaultOverride?: any) { + get(key: string, defaultOverride?: T) { const declared = this.isDeclared(key); if (!declared && defaultOverride !== undefined) { @@ -84,10 +69,10 @@ export class UiSettingsClient { if (!declared) { throw new Error( - `Unexpected \`config.get("${key}")\` call on unrecognized configuration setting "${key}". -Setting an initial value via \`config.set("${key}", value)\` before attempting to retrieve + `Unexpected \`IUiSettingsClient.get("${key}")\` call on unrecognized configuration setting "${key}". +Setting an initial value via \`IUiSettingsClient.set("${key}", value)\` before attempting to retrieve any custom setting value for "${key}" may fix this issue. -You can use \`config.get("${key}", defaultValue)\`, which will just return +You can use \`IUiSettingsClient.get("${key}", defaultValue)\`, which will just return \`defaultValue\` when the key is unrecognized.` ); } @@ -108,13 +93,9 @@ You can use \`config.get("${key}", defaultValue)\`, which will just return return value; } - /** - * Gets an observable of the current value for a config key, and all updates to that config - * key in the future. Providing a `defaultOverride` argument behaves the same as it does in #get() - */ - public get$(key: string, defaultOverride?: any) { - return Rx.concat( - Rx.defer(() => Rx.of(this.get(key, defaultOverride))), + get$(key: string, defaultOverride?: T) { + return concat( + defer(() => of(this.get(key, defaultOverride))), this.update$.pipe( filter(update => update.key === key), map(() => this.get(key, defaultOverride)) @@ -122,63 +103,31 @@ You can use \`config.get("${key}", defaultValue)\`, which will just return ); } - /** - * Sets the value for a uiSetting. If the setting is not defined in the uiSettingDefaults - * it will be stored as a custom setting. The new value will be synchronously available via - * the `get()` method and sent to the server in the background. If the request to the - * server fails then a toast notification will be displayed and the setting will be - * reverted it its value before `set()` was called. - */ - public async set(key: string, val: any) { - return await this.update(key, val); + async set(key: string, value: any) { + return await this.update(key, value); } - /** - * Removes the user-defined value for a setting, causing it to revert to the default. This - * method behaves the same as calling `set(key, null)`, including the synchronization, custom - * setting, and error behavior of that method. - */ - public async remove(key: string) { + async remove(key: string) { return await this.update(key, null); } - /** - * Returns true if the key is a "known" uiSetting, meaning it is either defined in the - * uiSettingDefaults or was previously added as a custom setting via the `set()` method. - */ - public isDeclared(key: string) { + isDeclared(key: string) { return key in this.cache; } - /** - * Returns true if the setting has no user-defined value or is unknown - */ - public isDefault(key: string) { + isDefault(key: string) { return !this.isDeclared(key) || this.cache[key].userValue == null; } - /** - * Returns true if the setting is not a part of the uiSettingDefaults, but was either - * added directly via `set()`, or is an unknown setting found in the uiSettings saved - * object - */ - public isCustom(key: string) { + isCustom(key: string) { return this.isDeclared(key) && !('value' in this.cache[key]); } - /** - * Returns true if a settings value is overridden by the server. When a setting is overridden - * its value can not be changed via `set()` or `remove()`. - */ - public isOverridden(key: string) { + isOverridden(key: string) { return this.isDeclared(key) && Boolean(this.cache[key].isOverridden); } - /** - * Overrides the default value for a setting in this specific browser tab. If the page - * is reloaded the default override is lost. - */ - public overrideLocalDefault(key: string, newDefault: any) { + overrideLocalDefault(key: string, newDefault: any) { // capture the previous value const prevDefault = this.defaults[key] ? this.defaults[key].value : undefined; @@ -201,39 +150,18 @@ You can use \`config.get("${key}", defaultValue)\`, which will just return } } - /** - * Returns an Observable that notifies subscribers of each update to the uiSettings, - * including the key, newValue, and oldValue of the setting that changed. - */ - public getUpdate$() { + getUpdate$() { return this.update$.asObservable(); } - /** - * Returns an Observable that notifies subscribers of each update to the uiSettings, - * including the key, newValue, and oldValue of the setting that changed. - */ - public getSaved$() { + getSaved$() { return this.saved$.asObservable(); } - /** - * Returns an Observable that notifies subscribers of each error while trying to update - * the settings, containing the actual Error class. - */ - public getUpdateErrors$() { + getUpdateErrors$() { return this.updateErrors$.asObservable(); } - /** - * Prepares the uiSettingsClient to be discarded, completing any update$ observables - * that have been created. - */ - public stop() { - this.update$.complete(); - this.saved$.complete(); - } - private assertUpdateAllowed(key: string) { if (this.isOverridden(key)) { throw new Error( @@ -242,7 +170,7 @@ You can use \`config.get("${key}", defaultValue)\`, which will just return } } - private async update(key: string, newVal: any) { + private async update(key: string, newVal: any): Promise { this.assertUpdateAllowed(key); const declared = this.isDeclared(key); diff --git a/src/core/public/ui_settings/ui_settings_service.mock.ts b/src/core/public/ui_settings/ui_settings_service.mock.ts index 2ec6175ff67d5..27dde2f10703e 100644 --- a/src/core/public/ui_settings/ui_settings_service.mock.ts +++ b/src/core/public/ui_settings/ui_settings_service.mock.ts @@ -17,10 +17,11 @@ * under the License. */ import * as Rx from 'rxjs'; -import { UiSettingsService, UiSettingsClientContract } from './'; +import { UiSettingsService } from './'; +import { IUiSettingsClient } from './types'; const createSetupContractMock = () => { - const setupContract: jest.Mocked = { + const setupContract: jest.Mocked = { getAll: jest.fn(), get: jest.fn(), get$: jest.fn(), @@ -34,7 +35,6 @@ const createSetupContractMock = () => { getUpdate$: jest.fn(), getSaved$: jest.fn(), getUpdateErrors$: jest.fn(), - stop: jest.fn(), }; setupContract.get$.mockReturnValue(new Rx.Subject()); setupContract.getUpdate$.mockReturnValue(new Rx.Subject()); diff --git a/src/core/public/ui_settings/ui_settings_service.test.mocks.ts b/src/core/public/ui_settings/ui_settings_service.test.mocks.ts deleted file mode 100644 index b94401c5928df..0000000000000 --- a/src/core/public/ui_settings/ui_settings_service.test.mocks.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -function mockClass( - module: string, - Class: new (...args: any[]) => T, - setup: (instance: any, args: any[]) => void -) { - const MockClass = jest.fn(function(this: any, ...args: any[]) { - setup(this, args); - }); - - // define the mock name which is used in some snapshots - MockClass.mockName(`Mock${Class.name}`); - - // define the class name for the MockClass which is used in other snapshots - Object.defineProperty(MockClass, 'name', { - value: `Mock${Class.name}`, - }); - - jest.doMock(module, () => ({ - [Class.name]: MockClass, - })); - - return MockClass; -} - -// Mock the UiSettingsApi class -import { UiSettingsApi } from './ui_settings_api'; -export const MockUiSettingsApi = mockClass('./ui_settings_api', UiSettingsApi, inst => { - inst.stop = jest.fn(); - inst.getLoadingCount$ = jest.fn().mockReturnValue({ - loadingCountObservable: true, - }); -}); - -// Mock the UiSettingsClient class -import { UiSettingsClient } from './ui_settings_client'; -export const MockUiSettingsClient = mockClass('./ui_settings_client', UiSettingsClient, inst => { - inst.stop = jest.fn(); -}); diff --git a/src/core/public/ui_settings/ui_settings_service.test.ts b/src/core/public/ui_settings/ui_settings_service.test.ts index 94e5e6e2418be..afb68c4844901 100644 --- a/src/core/public/ui_settings/ui_settings_service.test.ts +++ b/src/core/public/ui_settings/ui_settings_service.test.ts @@ -16,8 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import { MockUiSettingsApi, MockUiSettingsClient } from './ui_settings_service.test.mocks'; +import * as Rx from 'rxjs'; import { httpServiceMock } from '../http/http_service.mock'; import { injectedMetadataServiceMock } from '../injected_metadata/injected_metadata_service.mock'; @@ -30,53 +29,27 @@ const defaultDeps = { injectedMetadata: injectedMetadataServiceMock.createSetupContract(), }; -afterEach(() => { - jest.clearAllMocks(); -}); - -describe('#setup', () => { - it('returns an instance of UiSettingsClient', () => { - const setup = new UiSettingsService().setup(defaultDeps); - expect(setup).toBeInstanceOf(MockUiSettingsClient); - }); - - it('constructs UiSettingsClient and UiSettingsApi', () => { - new UiSettingsService().setup(defaultDeps); - - expect(MockUiSettingsApi).toMatchSnapshot('UiSettingsApi args'); - expect(MockUiSettingsClient).toMatchSnapshot('UiSettingsClient args'); - }); - - it('passes the uiSettings loading count to the loading count api', () => { - new UiSettingsService().setup(defaultDeps); - - expect(httpSetup.addLoadingCount).toMatchSnapshot('http.addLoadingCount calls'); - }); -}); - -describe('#start', () => { - it('returns an instance of UiSettingsClient', () => { - const uiSettings = new UiSettingsService(); - uiSettings.setup(defaultDeps); - const start = uiSettings.start(); - expect(start).toBeInstanceOf(MockUiSettingsClient); - }); -}); - describe('#stop', () => { it('runs fine if service never set up', () => { const service = new UiSettingsService(); expect(() => service.stop()).not.toThrowError(); }); - it('stops the uiSettingsClient and uiSettingsApi', () => { + it('stops the uiSettingsClient and uiSettingsApi', async () => { const service = new UiSettingsService(); + let loadingCount$: Rx.Observable; + defaultDeps.http.addLoadingCount.mockImplementation(obs$ => (loadingCount$ = obs$)); const client = service.setup(defaultDeps); - const [[{ api }]] = MockUiSettingsClient.mock.calls; - jest.spyOn(client, 'stop'); - jest.spyOn(api, 'stop'); + service.stop(); - expect(api.stop).toHaveBeenCalledTimes(1); - expect(client.stop).toHaveBeenCalledTimes(1); + + await expect( + Rx.combineLatest( + client.getUpdate$(), + client.getSaved$(), + client.getUpdateErrors$(), + loadingCount$! + ).toPromise() + ).resolves.toBe(undefined); }); }); diff --git a/src/core/public/ui_settings/ui_settings_service.ts b/src/core/public/ui_settings/ui_settings_service.ts index 2efb0884312d8..5a03cd1cfeedc 100644 --- a/src/core/public/ui_settings/ui_settings_service.ts +++ b/src/core/public/ui_settings/ui_settings_service.ts @@ -16,12 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +import { Subject } from 'rxjs'; import { HttpSetup } from '../http'; import { InjectedMetadataSetup } from '../injected_metadata'; import { UiSettingsApi } from './ui_settings_api'; -import { UiSettingsClient, UiSettingsClientContract } from './ui_settings_client'; +import { UiSettingsClient } from './ui_settings_client'; +import { IUiSettingsClient } from './types'; interface UiSettingsServiceDeps { http: HttpSetup; @@ -32,8 +34,9 @@ interface UiSettingsServiceDeps { export class UiSettingsService { private uiSettingsApi?: UiSettingsApi; private uiSettingsClient?: UiSettingsClient; + private done$ = new Subject(); - public setup({ http, injectedMetadata }: UiSettingsServiceDeps): UiSettingsClientContract { + public setup({ http, injectedMetadata }: UiSettingsServiceDeps): IUiSettingsClient { this.uiSettingsApi = new UiSettingsApi(http); http.addLoadingCount(this.uiSettingsApi.getLoadingCount$()); @@ -44,19 +47,18 @@ export class UiSettingsService { api: this.uiSettingsApi, defaults: legacyMetadata.uiSettings.defaults, initialSettings: legacyMetadata.uiSettings.user, + done$: this.done$, }); return this.uiSettingsClient; } - public start(): UiSettingsClientContract { + public start(): IUiSettingsClient { return this.uiSettingsClient!; } public stop() { - if (this.uiSettingsClient) { - this.uiSettingsClient.stop(); - } + this.done$.complete(); if (this.uiSettingsApi) { this.uiSettingsApi.stop(); diff --git a/src/core/server/context/context_service.ts b/src/core/server/context/context_service.ts index 1625fc9ad75ed..bbb7660bf9615 100644 --- a/src/core/server/context/context_service.ts +++ b/src/core/server/context/context_service.ts @@ -48,7 +48,7 @@ export class ContextService { * export interface VizRenderContext { * core: { * i18n: I18nStart; - * uiSettings: UISettingsClientContract; + * uiSettings: IUiSettingsClient; * } * [contextName: string]: unknown; * } diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 25ca8ade77aca..c8a68b4e2ea2a 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -742,15 +742,15 @@ export type IScopedClusterClient = Pick(key: string) => Promise; - getAll: () => Promise>; + get: (key: string) => Promise; + getAll: () => Promise>; getRegistered: () => Readonly>; - getUserProvided: () => Promise>>; + getUserProvided: () => Promise>>; isOverridden: (key: string) => boolean; remove: (key: string) => Promise; removeMany: (keys: string[]) => Promise; - set: (key: string, value: T) => Promise; - setMany: (changes: Record) => Promise; + set: (key: string, value: any) => Promise; + setMany: (changes: Record) => Promise; } // @public @@ -1713,7 +1713,7 @@ export interface UiSettingsServiceSetup { export type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string'; // @public -export interface UserProvidedValues { +export interface UserProvidedValues { // (undocumented) isOverridden?: boolean; // (undocumented) diff --git a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts index 809e15248b5b0..0544a1806e09a 100644 --- a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts +++ b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts @@ -19,7 +19,7 @@ import { defaults } from 'lodash'; -import { SavedObjectsClientContract, SavedObjectAttribute } from '../../saved_objects/types'; +import { SavedObjectsClientContract } from '../../saved_objects/types'; import { SavedObjectsErrorHelpers } from '../../saved_objects/'; import { Logger } from '../../logging'; @@ -33,9 +33,9 @@ interface Options { handleWriteErrors: boolean; } -export async function createOrUpgradeSavedConfig( +export async function createOrUpgradeSavedConfig( options: Options -): Promise | undefined> { +): Promise | undefined> { const { savedObjectsClient, version, buildNum, log, handleWriteErrors } = options; // try to find an older config we can upgrade diff --git a/src/core/server/ui_settings/types.ts b/src/core/server/ui_settings/types.ts index 0fa6b3702af24..49d3d3b33392f 100644 --- a/src/core/server/ui_settings/types.ts +++ b/src/core/server/ui_settings/types.ts @@ -33,25 +33,23 @@ export interface IUiSettingsClient { /** * Retrieves uiSettings values set by the user with fallbacks to default values if not specified. */ - get: (key: string) => Promise; + get: (key: string) => Promise; /** * Retrieves a set of all uiSettings values set by the user with fallbacks to default values if not specified. */ - getAll: () => Promise>; + getAll: () => Promise>; /** * Retrieves a set of all uiSettings values set by the user. */ - getUserProvided: () => Promise< - Record> - >; + getUserProvided: () => Promise>>; /** * Writes multiple uiSettings values and marks them as set by the user. */ - setMany: (changes: Record) => Promise; + setMany: (changes: Record) => Promise; /** * Writes uiSettings value and marks it as set by the user. */ - set: (key: string, value: T) => Promise; + set: (key: string, value: any) => Promise; /** * Removes uiSettings value by key. */ @@ -70,7 +68,7 @@ export interface IUiSettingsClient { * Describes the values explicitly set by user. * @public * */ -export interface UserProvidedValues { +export interface UserProvidedValues { userValue?: T; isOverridden?: boolean; } diff --git a/src/core/server/ui_settings/ui_settings_client.ts b/src/core/server/ui_settings/ui_settings_client.ts index 1a0f29f6ae6d9..3c9c232bff280 100644 --- a/src/core/server/ui_settings/ui_settings_client.ts +++ b/src/core/server/ui_settings/ui_settings_client.ts @@ -19,7 +19,7 @@ import { defaultsDeep } from 'lodash'; import { SavedObjectsErrorHelpers } from '../saved_objects'; -import { SavedObjectsClientContract, SavedObjectAttribute } from '../saved_objects/types'; +import { SavedObjectsClientContract } from '../saved_objects/types'; import { Logger } from '../logging'; import { createOrUpgradeSavedConfig } from './create_or_upgrade_saved_config'; import { IUiSettingsClient, UiSettingsParams } from './types'; @@ -30,7 +30,7 @@ export interface UiSettingsServiceOptions { id: string; buildNum: number; savedObjectsClient: SavedObjectsClientContract; - overrides?: Record; + overrides?: Record; defaults?: Record; log: Logger; } @@ -40,14 +40,14 @@ interface ReadOptions { autoCreateOrUpgradeIfMissing?: boolean; } -interface UserProvidedValue { +interface UserProvidedValue { userValue?: T; isOverridden?: boolean; } type UiSettingsRawValue = UiSettingsParams & UserProvidedValue; -type UserProvided = Record>; +type UserProvided = Record>; type UiSettingsRaw = Record; export class UiSettingsClient implements IUiSettingsClient { @@ -75,12 +75,12 @@ export class UiSettingsClient implements IUiSettingsClient { return this.defaults; } - async get(key: string): Promise { + async get(key: string): Promise { const all = await this.getAll(); return all[key]; } - async getAll() { + async getAll() { const raw = await this.getRaw(); return Object.keys(raw).reduce((all, key) => { @@ -90,7 +90,7 @@ export class UiSettingsClient implements IUiSettingsClient { }, {} as Record); } - async getUserProvided(): Promise> { + async getUserProvided(): Promise> { const userProvided: UserProvided = {}; // write the userValue for each key stored in the saved object that is not overridden @@ -112,11 +112,11 @@ export class UiSettingsClient implements IUiSettingsClient { return userProvided; } - async setMany(changes: Record) { + async setMany(changes: Record) { await this.write({ changes }); } - async set(key: string, value: T) { + async set(key: string, value: any) { await this.setMany({ [key]: value }); } @@ -147,11 +147,11 @@ export class UiSettingsClient implements IUiSettingsClient { return defaultsDeep(userProvided, this.defaults); } - private async write({ + private async write({ changes, autoCreateOrUpgradeIfMissing = true, }: { - changes: Record; + changes: Record; autoCreateOrUpgradeIfMissing?: boolean; }) { for (const key of Object.keys(changes)) { @@ -180,16 +180,16 @@ export class UiSettingsClient implements IUiSettingsClient { } } - private async read({ + private async read({ ignore401Errors = false, autoCreateOrUpgradeIfMissing = true, - }: ReadOptions = {}): Promise> { + }: ReadOptions = {}): Promise> { try { const resp = await this.savedObjectsClient.get(this.type, this.id); return resp.attributes; } catch (error) { if (SavedObjectsErrorHelpers.isNotFoundError(error) && autoCreateOrUpgradeIfMissing) { - const failedUpgradeAttributes = await createOrUpgradeSavedConfig({ + const failedUpgradeAttributes = await createOrUpgradeSavedConfig({ savedObjectsClient: this.savedObjectsClient, version: this.id, buildNum: this.buildNum, diff --git a/src/core/server/ui_settings/ui_settings_service.ts b/src/core/server/ui_settings/ui_settings_service.ts index a8f5663f8bd1e..8458a80de4952 100644 --- a/src/core/server/ui_settings/ui_settings_service.ts +++ b/src/core/server/ui_settings/ui_settings_service.ts @@ -23,7 +23,7 @@ import { CoreService } from '../../types'; import { CoreContext } from '../core_context'; import { Logger } from '../logging'; -import { SavedObjectsClientContract, SavedObjectAttribute } from '../saved_objects/types'; +import { SavedObjectsClientContract } from '../saved_objects/types'; import { InternalHttpServiceSetup } from '../http'; import { UiSettingsConfigType } from './ui_settings_config'; import { UiSettingsClient } from './ui_settings_client'; @@ -84,7 +84,7 @@ export class UiSettingsService implements CoreService = config.overrides; + const overrides: Record = config.overrides; // manually implemented deprecation until New platform Config service // supports them https://github.com/elastic/kibana/issues/40255 if (typeof deps.http.config.defaultRoute !== 'undefined') { diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts index 2ad0a1f1394e5..591290065d024 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.test.ts @@ -19,11 +19,7 @@ // eslint-disable-next-line max-classes-per-file import { IndexPatterns } from './index_patterns'; -import { - SavedObjectsClientContract, - UiSettingsClientContract, - HttpServiceBase, -} from 'kibana/public'; +import { SavedObjectsClientContract, IUiSettingsClient, HttpServiceBase } from 'kibana/public'; jest.mock('./index_pattern', () => { class IndexPattern { @@ -52,7 +48,7 @@ describe('IndexPatterns', () => { beforeEach(() => { const savedObjectsClient = {} as SavedObjectsClientContract; - const uiSettings = {} as UiSettingsClientContract; + const uiSettings = {} as IUiSettingsClient; const http = {} as HttpServiceBase; indexPatterns = new IndexPatterns(uiSettings, savedObjectsClient, http); diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts index c8e80b3aede20..d6a8e7b20451d 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -21,7 +21,7 @@ import { idx } from '@kbn/elastic-idx'; import { SavedObjectsClientContract, SimpleSavedObject, - UiSettingsClientContract, + IUiSettingsClient, HttpServiceBase, } from 'src/core/public'; @@ -32,13 +32,13 @@ import { IndexPatternsApiClient, GetFieldsOptions } from './index_patterns_api_c const indexPatternCache = createIndexPatternCache(); export class IndexPatterns { - private config: UiSettingsClientContract; + private config: IUiSettingsClient; private savedObjectsClient: SavedObjectsClientContract; private savedObjectsCache?: Array>> | null; private apiClient: IndexPatternsApiClient; constructor( - config: UiSettingsClientContract, + config: IUiSettingsClient, savedObjectsClient: SavedObjectsClientContract, http: HttpServiceBase ) { diff --git a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts index 9973a7081443d..83738ffe5b747 100644 --- a/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts +++ b/src/legacy/core_plugins/data/public/index_patterns/index_patterns_service.ts @@ -18,7 +18,7 @@ */ import { - UiSettingsClientContract, + IUiSettingsClient, SavedObjectsClientContract, HttpServiceBase, NotificationsStart, @@ -36,7 +36,7 @@ import { } from './index_patterns'; export interface IndexPatternDependencies { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; savedObjectsClient: SavedObjectsClientContract; http: HttpServiceBase; notifications: NotificationsStart; diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_string_input.test.tsx.snap b/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_string_input.test.tsx.snap index 6f155de95d6eb..61aac70b4a7ec 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_string_input.test.tsx.snap +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/__snapshots__/query_string_input.test.tsx.snap @@ -344,7 +344,6 @@ exports[`QueryStringInput Should disable autoFocus on EuiFieldText when disableA "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, } } @@ -907,7 +906,6 @@ exports[`QueryStringInput Should disable autoFocus on EuiFieldText when disableA "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, }, } @@ -1458,7 +1456,6 @@ exports[`QueryStringInput Should pass the query language to the language switche "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, } } @@ -2018,7 +2015,6 @@ exports[`QueryStringInput Should pass the query language to the language switche "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, }, } @@ -2569,7 +2565,6 @@ exports[`QueryStringInput Should render the given query 1`] = ` "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, } } @@ -3129,7 +3124,6 @@ exports[`QueryStringInput Should render the given query 1`] = ` "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, }, } diff --git a/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts b/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts index 4cf17dc9be37e..3dcab22605c07 100644 --- a/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts +++ b/src/legacy/core_plugins/data/public/query/query_bar/components/fetch_index_patterns.ts @@ -17,13 +17,13 @@ * under the License. */ import { isEmpty } from 'lodash'; -import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public'; import { getFromSavedObject } from '../../../index_patterns'; export async function fetchIndexPatterns( savedObjectsClient: SavedObjectsClientContract, indexPatternStrings: string[], - uiSettings: UiSettingsClientContract + uiSettings: IUiSettingsClient ) { if (!indexPatternStrings || isEmpty(indexPatternStrings)) { return []; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/application.ts b/src/legacy/core_plugins/kibana/public/dashboard/application.ts index f98a4ca53f467..797583362a8f8 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/application.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/application.ts @@ -26,7 +26,7 @@ import { ChromeStart, LegacyCoreStart, SavedObjectsClientContract, - UiSettingsClientContract, + IUiSettingsClient, } from 'kibana/public'; import { Storage } from '../../../../../plugins/kibana_utils/public'; import { @@ -64,7 +64,7 @@ export interface RenderDeps { dashboardConfig: any; savedDashboards: any; dashboardCapabilities: any; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; chrome: ChromeStart; addBasePath: (path: string) => string; savedQueryService: NpDataStart['query']['savedQueries']; diff --git a/src/legacy/core_plugins/kibana/public/home/kibana_services.ts b/src/legacy/core_plugins/kibana/public/home/kibana_services.ts index 5ef6e019db042..3ec095f4f26bf 100644 --- a/src/legacy/core_plugins/kibana/public/home/kibana_services.ts +++ b/src/legacy/core_plugins/kibana/public/home/kibana_services.ts @@ -25,7 +25,7 @@ import { NotificationsSetup, OverlayStart, SavedObjectsClientContract, - UiSettingsClientContract, + IUiSettingsClient, UiSettingsState, } from 'kibana/public'; import { UiStatsMetricType } from '@kbn/analytics'; @@ -50,7 +50,7 @@ export interface HomeKibanaServices { getInjected: (name: string, defaultValue?: any) => unknown; chrome: ChromeStart; telemetryOptInProvider: any; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; http: HttpStart; savedObjectsClient: SavedObjectsClientContract; toastNotifications: NotificationsSetup['toasts']; diff --git a/src/legacy/core_plugins/region_map/public/plugin.ts b/src/legacy/core_plugins/region_map/public/plugin.ts index a41d638986ae5..aaf0a8a308aea 100644 --- a/src/legacy/core_plugins/region_map/public/plugin.ts +++ b/src/legacy/core_plugins/region_map/public/plugin.ts @@ -21,7 +21,7 @@ import { CoreStart, Plugin, PluginInitializerContext, - UiSettingsClientContract, + IUiSettingsClient, } from '../../../../core/public'; import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public'; import { VisualizationsSetup } from '../../visualizations/public'; @@ -35,7 +35,7 @@ import { createRegionMapTypeDefinition } from './region_map_type'; /** @private */ interface RegionMapVisualizationDependencies extends LegacyDependenciesPluginSetup { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/legacy/core_plugins/tile_map/public/plugin.ts b/src/legacy/core_plugins/tile_map/public/plugin.ts index 14a348f624002..52acaf51b39b1 100644 --- a/src/legacy/core_plugins/tile_map/public/plugin.ts +++ b/src/legacy/core_plugins/tile_map/public/plugin.ts @@ -21,7 +21,7 @@ import { CoreStart, Plugin, PluginInitializerContext, - UiSettingsClientContract, + IUiSettingsClient, } from '../../../../core/public'; import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public'; import { VisualizationsSetup } from '../../visualizations/public'; @@ -35,7 +35,7 @@ import { createTileMapTypeDefinition } from './tile_map_type'; /** @private */ interface TileMapVisualizationDependencies extends LegacyDependenciesPluginSetup { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/legacy/core_plugins/timelion/public/plugin.ts b/src/legacy/core_plugins/timelion/public/plugin.ts index b0123cd34b49e..ba8c25c20abea 100644 --- a/src/legacy/core_plugins/timelion/public/plugin.ts +++ b/src/legacy/core_plugins/timelion/public/plugin.ts @@ -21,7 +21,7 @@ import { CoreStart, Plugin, PluginInitializerContext, - UiSettingsClientContract, + IUiSettingsClient, HttpSetup, } from 'kibana/public'; import { Plugin as ExpressionsPlugin } from 'src/plugins/expressions/public'; @@ -35,7 +35,7 @@ import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim' /** @internal */ export interface TimelionVisualizationDependencies extends LegacyDependenciesPluginSetup { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; http: HttpSetup; timelionPanels: Map; timefilter: TimefilterContract; diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/contexts/query_input_bar_context.ts b/src/legacy/core_plugins/vis_type_timeseries/public/contexts/query_input_bar_context.ts index 925b483905d01..04a63f60aacf2 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/contexts/query_input_bar_context.ts +++ b/src/legacy/core_plugins/vis_type_timeseries/public/contexts/query_input_bar_context.ts @@ -18,12 +18,12 @@ */ import React from 'react'; -import { UiSettingsClientContract, SavedObjectsClientContract } from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; export interface ICoreStartContext { appName: string; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; savedObjectsClient: SavedObjectsClientContract; storage: IStorageWrapper; } diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/plugin.ts b/src/legacy/core_plugins/vis_type_timeseries/public/plugin.ts index 75a65e131797d..4d1222d6f5a87 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/plugin.ts +++ b/src/legacy/core_plugins/vis_type_timeseries/public/plugin.ts @@ -22,7 +22,7 @@ import { CoreStart, Plugin, SavedObjectsClientContract, - UiSettingsClientContract, + IUiSettingsClient, } from '../../../../core/public'; import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public'; import { VisualizationsSetup } from '../../visualizations/public'; @@ -37,7 +37,7 @@ export interface MetricsPluginSetupDependencies { visualizations: VisualizationsSetup; } export interface MetricsVisualizationDependencies { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; savedObjectsClient: SavedObjectsClientContract; } diff --git a/src/legacy/core_plugins/vis_type_timeseries/public/services.ts b/src/legacy/core_plugins/vis_type_timeseries/public/services.ts index dcc7de4098bdd..af04578b8e27f 100644 --- a/src/legacy/core_plugins/vis_type_timeseries/public/services.ts +++ b/src/legacy/core_plugins/vis_type_timeseries/public/services.ts @@ -17,12 +17,10 @@ * under the License. */ -import { I18nStart, SavedObjectsStart, UiSettingsClientContract } from 'src/core/public'; +import { I18nStart, SavedObjectsStart, IUiSettingsClient } from 'src/core/public'; import { createGetterSetter } from '../../../../plugins/kibana_utils/public'; -export const [getUISettings, setUISettings] = createGetterSetter( - 'UISettings' -); +export const [getUISettings, setUISettings] = createGetterSetter('UISettings'); export const [getSavedObjectsClient, setSavedObjectsClient] = createGetterSetter( 'SavedObjectsClient' diff --git a/src/legacy/core_plugins/vis_type_vega/public/plugin.ts b/src/legacy/core_plugins/vis_type_vega/public/plugin.ts index 9001164afe820..5166770d1727b 100644 --- a/src/legacy/core_plugins/vis_type_vega/public/plugin.ts +++ b/src/legacy/core_plugins/vis_type_vega/public/plugin.ts @@ -21,7 +21,7 @@ import { CoreSetup, CoreStart, Plugin, - UiSettingsClientContract, + IUiSettingsClient, } from '../../../../core/public'; import { LegacyDependenciesPlugin, LegacyDependenciesPluginSetup } from './shim'; import { Plugin as ExpressionsPublicPlugin } from '../../../../plugins/expressions/public'; @@ -32,7 +32,7 @@ import { createVegaTypeDefinition } from './vega_type'; /** @internal */ export interface VegaVisualizationDependencies extends LegacyDependenciesPluginSetup { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } /** @internal */ diff --git a/src/legacy/core_plugins/visualizations/public/np_ready/public/services.ts b/src/legacy/core_plugins/visualizations/public/np_ready/public/services.ts index 63afbca71a280..434612d11b28a 100644 --- a/src/legacy/core_plugins/visualizations/public/np_ready/public/services.ts +++ b/src/legacy/core_plugins/visualizations/public/np_ready/public/services.ts @@ -17,13 +17,11 @@ * under the License. */ -import { I18nStart, UiSettingsClientContract } from 'src/core/public'; +import { I18nStart, IUiSettingsClient } from 'src/core/public'; import { TypesStart } from './types'; import { createGetterSetter } from '../../../../../../plugins/kibana_utils/public'; -export const [getUISettings, setUISettings] = createGetterSetter( - 'UISettings' -); +export const [getUISettings, setUISettings] = createGetterSetter('UISettings'); export const [getTypes, setTypes] = createGetterSetter('Types'); diff --git a/src/legacy/ui/public/agg_types/buckets/date_range.test.ts b/src/legacy/ui/public/agg_types/buckets/date_range.test.ts index 7d9fe002636a2..e34cb4e36720f 100644 --- a/src/legacy/ui/public/agg_types/buckets/date_range.test.ts +++ b/src/legacy/ui/public/agg_types/buckets/date_range.test.ts @@ -95,7 +95,7 @@ describe('date_range params', () => { }); it('should use the Kibana time_zone if no parameter specified', () => { - npStart.core.uiSettings.get = jest.fn(() => 'kibanaTimeZone'); + npStart.core.uiSettings.get = jest.fn(() => 'kibanaTimeZone' as any); const aggConfigs = getAggConfigs( { diff --git a/src/legacy/ui/public/agg_types/buckets/histogram.test.ts b/src/legacy/ui/public/agg_types/buckets/histogram.test.ts index 338af2e41cb88..4e89d7db1ff64 100644 --- a/src/legacy/ui/public/agg_types/buckets/histogram.test.ts +++ b/src/legacy/ui/public/agg_types/buckets/histogram.test.ts @@ -159,7 +159,7 @@ describe('Histogram Agg', () => { } // mock histogram:maxBars value; - npStart.core.uiSettings.get = jest.fn(() => maxBars); + npStart.core.uiSettings.get = jest.fn(() => maxBars as any); return aggConfig.write(aggConfigs).params; }; diff --git a/src/legacy/ui/public/courier/fetch/fetch_soon.test.ts b/src/legacy/ui/public/courier/fetch/fetch_soon.test.ts index e753c526b748d..d96fb536985da 100644 --- a/src/legacy/ui/public/courier/fetch/fetch_soon.test.ts +++ b/src/legacy/ui/public/courier/fetch/fetch_soon.test.ts @@ -19,14 +19,14 @@ import { fetchSoon } from './fetch_soon'; import { callClient } from './call_client'; -import { UiSettingsClientContract } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../core/public'; import { FetchHandlers, FetchOptions } from './types'; import { SearchRequest, SearchResponse } from '../types'; function getConfigStub(config: any = {}) { return { get: key => config[key], - } as UiSettingsClientContract; + } as IUiSettingsClient; } const mockResponses: Record = { diff --git a/src/legacy/ui/public/courier/fetch/get_search_params.test.ts b/src/legacy/ui/public/courier/fetch/get_search_params.test.ts index d6f3d33099599..76f3105d7f942 100644 --- a/src/legacy/ui/public/courier/fetch/get_search_params.test.ts +++ b/src/legacy/ui/public/courier/fetch/get_search_params.test.ts @@ -18,12 +18,12 @@ */ import { getMSearchParams, getSearchParams } from './get_search_params'; -import { UiSettingsClientContract } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../core/public'; function getConfigStub(config: any = {}) { return { get: key => config[key], - } as UiSettingsClientContract; + } as IUiSettingsClient; } describe('getMSearchParams', () => { diff --git a/src/legacy/ui/public/courier/fetch/get_search_params.ts b/src/legacy/ui/public/courier/fetch/get_search_params.ts index 6b8da07ca93d4..21cdbf97945c5 100644 --- a/src/legacy/ui/public/courier/fetch/get_search_params.ts +++ b/src/legacy/ui/public/courier/fetch/get_search_params.ts @@ -17,11 +17,11 @@ * under the License. */ -import { UiSettingsClientContract } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../core/public'; const sessionId = Date.now(); -export function getMSearchParams(config: UiSettingsClientContract) { +export function getMSearchParams(config: IUiSettingsClient) { return { rest_total_hits_as_int: true, ignore_throttled: getIgnoreThrottled(config), @@ -29,7 +29,7 @@ export function getMSearchParams(config: UiSettingsClientContract) { }; } -export function getSearchParams(config: UiSettingsClientContract, esShardTimeout: number = 0) { +export function getSearchParams(config: IUiSettingsClient, esShardTimeout: number = 0) { return { rest_total_hits_as_int: true, ignore_unavailable: true, @@ -40,16 +40,16 @@ export function getSearchParams(config: UiSettingsClientContract, esShardTimeout }; } -export function getIgnoreThrottled(config: UiSettingsClientContract) { +export function getIgnoreThrottled(config: IUiSettingsClient) { return !config.get('search:includeFrozen'); } -export function getMaxConcurrentShardRequests(config: UiSettingsClientContract) { +export function getMaxConcurrentShardRequests(config: IUiSettingsClient) { const maxConcurrentShardRequests = config.get('courier:maxConcurrentShardRequests'); return maxConcurrentShardRequests > 0 ? maxConcurrentShardRequests : undefined; } -export function getPreference(config: UiSettingsClientContract) { +export function getPreference(config: IUiSettingsClient) { const setRequestPreference = config.get('courier:setRequestPreference'); if (setRequestPreference === 'sessionId') return sessionId; return setRequestPreference === 'custom' diff --git a/src/legacy/ui/public/courier/fetch/types.ts b/src/legacy/ui/public/courier/fetch/types.ts index e341e1ab35c5c..03bf51ae15d45 100644 --- a/src/legacy/ui/public/courier/fetch/types.ts +++ b/src/legacy/ui/public/courier/fetch/types.ts @@ -17,7 +17,7 @@ * under the License. */ -import { UiSettingsClientContract } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../core/public'; import { SearchRequest, SearchResponse } from '../types'; export interface ApiCaller { @@ -36,6 +36,6 @@ export interface FetchOptions { export interface FetchHandlers { es: ApiCaller; - config: UiSettingsClientContract; + config: IUiSettingsClient; esShardTimeout: number; } diff --git a/src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts b/src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts index 29921fc7a11d3..53a857a72c1a3 100644 --- a/src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts +++ b/src/legacy/ui/public/courier/search_strategy/default_search_strategy.test.ts @@ -18,7 +18,7 @@ */ import { defaultSearchStrategy } from './default_search_strategy'; -import { UiSettingsClientContract } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../core/public'; import { SearchStrategySearchParams } from './types'; const { search } = defaultSearchStrategy; @@ -26,7 +26,7 @@ const { search } = defaultSearchStrategy; function getConfigStub(config: any = {}) { return { get: key => config[key], - } as UiSettingsClientContract; + } as IUiSettingsClient; } const msearchMockResponse: any = Promise.resolve([]); diff --git a/src/legacy/ui/public/test_harness/test_harness.js b/src/legacy/ui/public/test_harness/test_harness.js index 8c58ca4e0ad03..fa7ca0dd62ac1 100644 --- a/src/legacy/ui/public/test_harness/test_harness.js +++ b/src/legacy/ui/public/test_harness/test_harness.js @@ -21,9 +21,11 @@ import chrome from '../chrome'; import { parse as parseUrl } from 'url'; +import { Subject } from 'rxjs'; import sinon from 'sinon'; import { metadata } from '../metadata'; -import { UiSettingsClient } from '../../../../core/public'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { UiSettingsClient } from '../../../../core/public/ui_settings'; import './test_harness.css'; import 'ng_mock'; @@ -46,10 +48,12 @@ before(() => { }); let stubUiSettings; +let done$; function createStubUiSettings() { if (stubUiSettings) { - stubUiSettings.stop(); + done$.complete(); } + done$ = new Subject(); stubUiSettings = new UiSettingsClient({ api: { @@ -60,6 +64,7 @@ function createStubUiSettings() { onUpdateError: () => {}, defaults: metadata.uiSettings.defaults, initialSettings: {}, + done$, }); } diff --git a/src/plugins/data/common/es_query/es_query/get_es_query_config.test.ts b/src/plugins/data/common/es_query/es_query/get_es_query_config.test.ts index a4ab03687f92e..d146d81973d0d 100644 --- a/src/plugins/data/common/es_query/es_query/get_es_query_config.test.ts +++ b/src/plugins/data/common/es_query/es_query/get_es_query_config.test.ts @@ -18,7 +18,7 @@ */ import { get } from 'lodash'; import { getEsQueryConfig } from './get_es_query_config'; -import { UiSettingsClientContract } from 'kibana/public'; +import { IUiSettingsClient } from 'kibana/public'; const config = ({ get(item: string) { @@ -36,7 +36,7 @@ const config = ({ 'dateFormat:tz': { dateFormatTZ: 'Browser', }, -} as unknown) as UiSettingsClientContract; +} as unknown) as IUiSettingsClient; describe('getEsQueryConfig', () => { test('should return the parameters of an Elasticsearch query config requested', () => { diff --git a/src/plugins/data/public/field_formats_provider/field_formats.ts b/src/plugins/data/public/field_formats_provider/field_formats.ts index f46994c209ded..20e90b8e4a545 100644 --- a/src/plugins/data/public/field_formats_provider/field_formats.ts +++ b/src/plugins/data/public/field_formats_provider/field_formats.ts @@ -18,7 +18,7 @@ */ import { forOwn, isFunction, memoize } from 'lodash'; -import { UiSettingsClientContract } from 'kibana/public'; +import { IUiSettingsClient } from 'kibana/public'; import { ES_FIELD_TYPES, KBN_FIELD_TYPES, @@ -31,7 +31,7 @@ import { FieldType } from './types'; export class FieldFormatRegisty { private fieldFormats: Map; - private uiSettings!: UiSettingsClientContract; + private uiSettings!: IUiSettingsClient; private defaultMap: Record; constructor() { @@ -41,7 +41,7 @@ export class FieldFormatRegisty { getConfig = (key: string, override?: any) => this.uiSettings.get(key, override); - init(uiSettings: UiSettingsClientContract) { + init(uiSettings: IUiSettingsClient) { this.uiSettings = uiSettings; this.parseDefaultTypeMap(this.uiSettings.get('format:defaultTypeMap')); diff --git a/src/plugins/data/public/field_formats_provider/field_formats_service.ts b/src/plugins/data/public/field_formats_provider/field_formats_service.ts index b144ea7ec2530..ea1a8af2930b0 100644 --- a/src/plugins/data/public/field_formats_provider/field_formats_service.ts +++ b/src/plugins/data/public/field_formats_provider/field_formats_service.ts @@ -17,7 +17,7 @@ * under the License. */ -import { UiSettingsClientContract } from 'src/core/public'; +import { IUiSettingsClient } from 'src/core/public'; import { FieldFormatRegisty } from './field_formats'; import { @@ -43,7 +43,7 @@ import { * @internal */ interface FieldFormatsServiceDependencies { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } export class FieldFormatsService { diff --git a/src/plugins/data/public/query/filter_manager/filter_manager.ts b/src/plugins/data/public/query/filter_manager/filter_manager.ts index feab75ed7457f..c25e5df2b168a 100644 --- a/src/plugins/data/public/query/filter_manager/filter_manager.ts +++ b/src/plugins/data/public/query/filter_manager/filter_manager.ts @@ -20,7 +20,7 @@ import _ from 'lodash'; import { Subject } from 'rxjs'; -import { UiSettingsClientContract } from 'src/core/public'; +import { IUiSettingsClient } from 'src/core/public'; import { compareFilters } from './lib/compare_filters'; import { mapAndFlattenFilters } from './lib/map_and_flatten_filters'; @@ -33,9 +33,9 @@ export class FilterManager { private filters: esFilters.Filter[] = []; private updated$: Subject = new Subject(); private fetch$: Subject = new Subject(); - private uiSettings: UiSettingsClientContract; + private uiSettings: IUiSettingsClient; - constructor(uiSettings: UiSettingsClientContract) { + constructor(uiSettings: IUiSettingsClient) { this.uiSettings = uiSettings; } diff --git a/src/plugins/data/public/query/lib/get_query_log.ts b/src/plugins/data/public/query/lib/get_query_log.ts index 67073a9078046..a71eb7580cf07 100644 --- a/src/plugins/data/public/query/lib/get_query_log.ts +++ b/src/plugins/data/public/query/lib/get_query_log.ts @@ -17,12 +17,12 @@ * under the License. */ -import { UiSettingsClientContract } from 'src/core/public'; +import { IUiSettingsClient } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { PersistedLog } from '../persisted_log'; export function getQueryLog( - uiSettings: UiSettingsClientContract, + uiSettings: IUiSettingsClient, storage: IStorageWrapper, appName: string, language: string diff --git a/src/plugins/data/public/query/timefilter/timefilter_service.ts b/src/plugins/data/public/query/timefilter/timefilter_service.ts index 831ccebedc9cc..413163ed059ad 100644 --- a/src/plugins/data/public/query/timefilter/timefilter_service.ts +++ b/src/plugins/data/public/query/timefilter/timefilter_service.ts @@ -17,7 +17,7 @@ * under the License. */ -import { UiSettingsClientContract } from 'src/core/public'; +import { IUiSettingsClient } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { TimeHistory, Timefilter, TimeHistoryContract, TimefilterContract } from './index'; @@ -27,7 +27,7 @@ import { TimeHistory, Timefilter, TimeHistoryContract, TimefilterContract } from */ export interface TimeFilterServiceDependencies { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; storage: IStorageWrapper; } diff --git a/src/plugins/data/public/suggestions_provider/value_suggestions.test.ts b/src/plugins/data/public/suggestions_provider/value_suggestions.test.ts index 7dc8ff0fe133d..02aaaaf6f4689 100644 --- a/src/plugins/data/public/suggestions_provider/value_suggestions.test.ts +++ b/src/plugins/data/public/suggestions_provider/value_suggestions.test.ts @@ -22,7 +22,7 @@ jest.mock('ui/new_platform'); import { stubIndexPattern, stubFields } from '../stubs'; import { getSuggestionsProvider } from './value_suggestions'; -import { UiSettingsClientContract } from 'kibana/public'; +import { IUiSettingsClient } from 'kibana/public'; describe('getSuggestions', () => { let getSuggestions: any; @@ -30,7 +30,7 @@ describe('getSuggestions', () => { describe('with value suggestions disabled', () => { beforeEach(() => { - const config = { get: (key: string) => false } as UiSettingsClientContract; + const config = { get: (key: string) => false } as IUiSettingsClient; http = { fetch: jest.fn() }; getSuggestions = getSuggestionsProvider(config, http); }); @@ -47,7 +47,7 @@ describe('getSuggestions', () => { describe('with value suggestions enabled', () => { beforeEach(() => { - const config = { get: (key: string) => true } as UiSettingsClientContract; + const config = { get: (key: string) => true } as IUiSettingsClient; http = { fetch: jest.fn() }; getSuggestions = getSuggestionsProvider(config, http); }); diff --git a/src/plugins/data/public/suggestions_provider/value_suggestions.ts b/src/plugins/data/public/suggestions_provider/value_suggestions.ts index 3bc1b45d87395..282f4ee65dc96 100644 --- a/src/plugins/data/public/suggestions_provider/value_suggestions.ts +++ b/src/plugins/data/public/suggestions_provider/value_suggestions.ts @@ -19,12 +19,12 @@ import { memoize } from 'lodash'; -import { UiSettingsClientContract, HttpServiceBase } from 'src/core/public'; +import { IUiSettingsClient, HttpServiceBase } from 'src/core/public'; import { IGetSuggestions } from './types'; import { IFieldType } from '../../common'; export function getSuggestionsProvider( - uiSettings: UiSettingsClientContract, + uiSettings: IUiSettingsClient, http: HttpServiceBase ): IGetSuggestions { const requestSuggestions = memoize( diff --git a/src/plugins/data/public/ui/filter_bar/filter_item.tsx b/src/plugins/data/public/ui/filter_bar/filter_item.tsx index 4ef0b2740e5fa..1921f6672755d 100644 --- a/src/plugins/data/public/ui/filter_bar/filter_item.tsx +++ b/src/plugins/data/public/ui/filter_bar/filter_item.tsx @@ -21,7 +21,7 @@ import { EuiContextMenu, EuiPopover } from '@elastic/eui'; import { InjectedIntl, injectI18n } from '@kbn/i18n/react'; import classNames from 'classnames'; import React, { Component } from 'react'; -import { UiSettingsClientContract } from 'src/core/public'; +import { IUiSettingsClient } from 'src/core/public'; import { FilterEditor } from './filter_editor'; import { FilterView } from './filter_view'; import { esFilters, utils, IIndexPattern } from '../..'; @@ -34,7 +34,7 @@ interface Props { onUpdate: (filter: esFilters.Filter) => void; onRemove: () => void; intl: InjectedIntl; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } interface State { diff --git a/src/plugins/data/public/ui/query_string_input/__snapshots__/language_switcher.test.tsx.snap b/src/plugins/data/public/ui/query_string_input/__snapshots__/language_switcher.test.tsx.snap index d4990ed59f441..7ab7d7653eb5e 100644 --- a/src/plugins/data/public/ui/query_string_input/__snapshots__/language_switcher.test.tsx.snap +++ b/src/plugins/data/public/ui/query_string_input/__snapshots__/language_switcher.test.tsx.snap @@ -206,7 +206,6 @@ exports[`LanguageSwitcher should toggle off if language is lucene 1`] = ` "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, } } @@ -497,7 +496,6 @@ exports[`LanguageSwitcher should toggle on if language is kuery 1`] = ` "overrideLocalDefault": [MockFunction], "remove": [MockFunction], "set": [MockFunction], - "stop": [MockFunction], }, } } diff --git a/src/plugins/inspector/public/views/data/components/data_table.tsx b/src/plugins/inspector/public/views/data/components/data_table.tsx index d5f2d4645ce0b..b78a3920804d2 100644 --- a/src/plugins/inspector/public/views/data/components/data_table.tsx +++ b/src/plugins/inspector/public/views/data/components/data_table.tsx @@ -36,7 +36,7 @@ import { i18n } from '@kbn/i18n'; import { DataDownloadOptions } from './download_options'; import { DataViewRow, DataViewColumn } from '../types'; import { TabularData } from '../../../adapters/data/types'; -import { UiSettingsClientContract } from '../../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; interface DataTableFormatState { columns: DataViewColumn[]; @@ -46,7 +46,7 @@ interface DataTableFormatState { interface DataTableFormatProps { data: TabularData; exportTitle: string; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; isFormatted?: boolean; } diff --git a/src/plugins/inspector/public/views/data/components/data_view.test.tsx b/src/plugins/inspector/public/views/data/components/data_view.test.tsx index d067757350b51..55322bf5ec91a 100644 --- a/src/plugins/inspector/public/views/data/components/data_view.test.tsx +++ b/src/plugins/inspector/public/views/data/components/data_view.test.tsx @@ -21,7 +21,7 @@ import React from 'react'; import { getDataViewDescription } from '../index'; import { DataAdapter } from '../../../adapters/data'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { UiSettingsClientContract } from '../../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; jest.mock('../lib/export_csv', () => ({ exportAsCsv: jest.fn(), @@ -31,7 +31,7 @@ describe('Inspector Data View', () => { let DataView: any; beforeEach(() => { - const uiSettings = {} as UiSettingsClientContract; + const uiSettings = {} as IUiSettingsClient; DataView = getDataViewDescription(uiSettings); }); diff --git a/src/plugins/inspector/public/views/data/components/data_view.tsx b/src/plugins/inspector/public/views/data/components/data_view.tsx index 34e0bfaa52693..91f42a54f64d0 100644 --- a/src/plugins/inspector/public/views/data/components/data_view.tsx +++ b/src/plugins/inspector/public/views/data/components/data_view.tsx @@ -32,7 +32,7 @@ import { import { DataTableFormat } from './data_table'; import { InspectorViewProps, Adapters } from '../../../types'; import { TabularLoaderOptions, TabularData, TabularCallback } from '../../../adapters/data/types'; -import { UiSettingsClientContract } from '../../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../../core/public'; interface DataViewComponentState { tabularData: TabularData | null; @@ -42,7 +42,7 @@ interface DataViewComponentState { } interface DataViewComponentProps extends InspectorViewProps { - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } export class DataViewComponent extends Component { diff --git a/src/plugins/inspector/public/views/data/index.tsx b/src/plugins/inspector/public/views/data/index.tsx index a33bf5ebf1f52..0cd88442bf8f8 100644 --- a/src/plugins/inspector/public/views/data/index.tsx +++ b/src/plugins/inspector/public/views/data/index.tsx @@ -21,10 +21,10 @@ import { i18n } from '@kbn/i18n'; import { DataViewComponent } from './components/data_view'; import { Adapters, InspectorViewDescription, InspectorViewProps } from '../../types'; -import { UiSettingsClientContract } from '../../../../../core/public'; +import { IUiSettingsClient } from '../../../../../core/public'; export const getDataViewDescription = ( - uiSettings: UiSettingsClientContract + uiSettings: IUiSettingsClient ): InspectorViewDescription => ({ title: i18n.translate('inspector.data.dataTitle', { defaultMessage: 'Data', diff --git a/src/plugins/kibana_react/public/table_list_view/table_list_view.tsx b/src/plugins/kibana_react/public/table_list_view/table_list_view.tsx index e3be0b08ab83f..4bb7ce75073ae 100644 --- a/src/plugins/kibana_react/public/table_list_view/table_list_view.tsx +++ b/src/plugins/kibana_react/public/table_list_view/table_list_view.tsx @@ -37,7 +37,7 @@ import { EuiConfirmModal, EuiCallOut, } from '@elastic/eui'; -import { ToastsStart, UiSettingsClientContract } from 'kibana/public'; +import { ToastsStart, IUiSettingsClient } from 'kibana/public'; import { toMountPoint } from '../util'; export const EMPTY_FILTER = ''; @@ -66,7 +66,7 @@ export interface TableListViewProps { tableColumns: Column[]; tableListTitle: string; toastNotifications: ToastsStart; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; } export interface TableListViewState { diff --git a/src/test_utils/public/stub_field_formats.ts b/src/test_utils/public/stub_field_formats.ts index 39c6fb2f6d10e..da1a31f1cc7a5 100644 --- a/src/test_utils/public/stub_field_formats.ts +++ b/src/test_utils/public/stub_field_formats.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { UiSettingsClientContract } from 'kibana/public'; +import { IUiSettingsClient } from 'kibana/public'; import { FieldFormatRegisty, @@ -37,7 +37,7 @@ import { UrlFormat, } from '../../plugins/data/public/'; -export const getFieldFormatsRegistry = (uiSettings: UiSettingsClientContract) => { +export const getFieldFormatsRegistry = (uiSettings: IUiSettingsClient) => { const fieldFormats = new FieldFormatRegisty(); fieldFormats.register([ diff --git a/x-pack/legacy/plugins/graph/public/render_app.ts b/x-pack/legacy/plugins/graph/public/render_app.ts index 18cdf0ddd81b2..1beee2e73721b 100644 --- a/x-pack/legacy/plugins/graph/public/render_app.ts +++ b/x-pack/legacy/plugins/graph/public/render_app.ts @@ -28,7 +28,7 @@ import { LegacyCoreStart, SavedObjectsClientContract, ToastsStart, - UiSettingsClientContract, + IUiSettingsClient, } from 'kibana/public'; // @ts-ignore import { initGraphApp } from './app'; @@ -48,7 +48,7 @@ export interface GraphDependencies extends LegacyAngularInjectedDependencies { coreStart: AppMountContext['core']; navigation: NavigationStart; chrome: ChromeStart; - config: UiSettingsClientContract; + config: IUiSettingsClient; toastNotifications: ToastsStart; indexPatterns: DataStart['indexPatterns']['indexPatterns']; npData: ReturnType; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx index f615914360a35..f3e86c5b59214 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.test.tsx @@ -17,11 +17,7 @@ import { import { DropHandler, DragContextState } from '../../drag_drop'; import { createMockedDragDropContext } from '../mocks'; import { mountWithIntl as mount, shallowWithIntl as shallow } from 'test_utils/enzyme_helpers'; -import { - UiSettingsClientContract, - SavedObjectsClientContract, - HttpServiceBase, -} from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract, HttpServiceBase } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { IndexPatternPrivateState } from '../types'; import { documentField } from '../document_field'; @@ -140,7 +136,7 @@ describe('IndexPatternDimensionPanel', () => { uniqueLabel: 'stuff', filterOperations: () => true, storage: {} as IStorageWrapper, - uiSettings: {} as UiSettingsClientContract, + uiSettings: {} as IUiSettingsClient, savedObjectsClient: {} as SavedObjectsClientContract, http: {} as HttpServiceBase, }; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx index dd9fde4bf1572..fded53cd35f59 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/dimension_panel/dimension_panel.tsx @@ -8,11 +8,7 @@ import _ from 'lodash'; import React, { memo, useMemo } from 'react'; import { EuiButtonIcon } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { - UiSettingsClientContract, - SavedObjectsClientContract, - HttpServiceBase, -} from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract, HttpServiceBase } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { DatasourceDimensionPanelProps, StateSetter } from '../../types'; import { IndexPatternColumn, OperationType } from '../indexpattern'; @@ -29,7 +25,7 @@ export type IndexPatternDimensionPanelProps = DatasourceDimensionPanelProps & { state: IndexPatternPrivateState; setState: StateSetter; dragDropContext: DragContextState; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; storage: IStorageWrapper; savedObjectsClient: SavedObjectsClientContract; layerId: string; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx index d0b77a425d14a..f7125a1adae52 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/date_histogram.test.tsx @@ -9,11 +9,7 @@ import { DateHistogramIndexPatternColumn } from './date_histogram'; import { dateHistogramOperation } from '.'; import { shallow } from 'enzyme'; import { EuiSwitch, EuiSwitchEvent } from '@elastic/eui'; -import { - UiSettingsClientContract, - SavedObjectsClientContract, - HttpServiceBase, -} from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract, HttpServiceBase } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { createMockedIndexPattern } from '../../mocks'; import { IndexPatternPrivateState } from '../../types'; @@ -34,7 +30,7 @@ jest.mock('ui/new_platform', () => ({ const defaultOptions = { storage: {} as IStorageWrapper, - uiSettings: {} as UiSettingsClientContract, + uiSettings: {} as IUiSettingsClient, savedObjectsClient: {} as SavedObjectsClientContract, dateRange: { fromDate: 'now-1y', diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts index 9ad3fb679471e..252a3d788fd30 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/index.ts @@ -4,11 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - UiSettingsClientContract, - SavedObjectsClientContract, - HttpServiceBase, -} from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract, HttpServiceBase } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { termsOperation } from './terms'; import { cardinalityOperation } from './cardinality'; @@ -48,7 +44,7 @@ export interface ParamEditorProps { setState: StateSetter; columnId: string; layerId: string; - uiSettings: UiSettingsClientContract; + uiSettings: IUiSettingsClient; storage: IStorageWrapper; savedObjectsClient: SavedObjectsClientContract; http: HttpServiceBase; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx index 7b21ef92ab82b..c0d995d420760 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operations/definitions/terms.test.tsx @@ -7,11 +7,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { EuiRange, EuiSelect } from '@elastic/eui'; -import { - UiSettingsClientContract, - SavedObjectsClientContract, - HttpServiceBase, -} from 'src/core/public'; +import { IUiSettingsClient, SavedObjectsClientContract, HttpServiceBase } from 'src/core/public'; import { IStorageWrapper } from 'src/plugins/kibana_utils/public'; import { createMockedIndexPattern } from '../../mocks'; import { TermsIndexPatternColumn } from './terms'; @@ -22,7 +18,7 @@ jest.mock('ui/new_platform'); const defaultProps = { storage: {} as IStorageWrapper, - uiSettings: {} as UiSettingsClientContract, + uiSettings: {} as IUiSettingsClient, savedObjectsClient: {} as SavedObjectsClientContract, dateRange: { fromDate: 'now-1d', toDate: 'now' }, http: {} as HttpServiceBase, diff --git a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx index 9867d014217e7..f0603f021c452 100644 --- a/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx +++ b/x-pack/legacy/plugins/lens/public/xy_visualization_plugin/plugin.tsx @@ -5,7 +5,7 @@ */ import { npSetup } from 'ui/new_platform'; -import { CoreSetup, UiSettingsClientContract } from 'src/core/public'; +import { CoreSetup, IUiSettingsClient } from 'src/core/public'; import chrome, { Chrome } from 'ui/chrome'; import moment from 'moment-timezone'; import { getFormat, FormatFactory } from 'ui/visualize/loader/pipeline_helpers/utilities'; @@ -24,7 +24,7 @@ export interface XyVisualizationPluginSetupPlugins { }; } -function getTimeZone(uiSettings: UiSettingsClientContract) { +function getTimeZone(uiSettings: IUiSettingsClient) { const configuredTimeZone = uiSettings.get('dateFormat:tz'); if (configuredTimeZone === 'Browser') { return moment.tz.guess(); diff --git a/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts b/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts index b465392a50ae1..b40645799fb4b 100644 --- a/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts +++ b/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SavedObjectsClientContract, UiSettingsClientContract } from 'src/core/public'; +import { SavedObjectsClientContract, IUiSettingsClient } from 'src/core/public'; import { IndexPattern as IndexPatternType, IndexPatterns as IndexPatternsType, @@ -73,7 +73,7 @@ export function loadCurrentSavedSearch(savedSearches: any, savedSearchId: SavedS export function createSearchItems( indexPattern: IndexPatternType | undefined, savedSearch: any, - config: UiSettingsClientContract + config: IUiSettingsClient ) { // query is only used by the data visualizer as it needs // a lucene query_string.