(defaultContextValue as CanvasServices);
export const useServices = () => useContext(context);
-export const usePlatformService = () => useServices().platform;
export const useEmbeddablesService = () => useServices().embeddables;
export const useExpressionsService = () => useServices().expressions;
export const useNavLinkService = () => useServices().navLink;
@@ -50,7 +48,6 @@ export const LegacyServicesProvider: FC<{
const value = {
embeddables: specifiedProviders.embeddables.getService(),
expressions: specifiedProviders.expressions.getService(),
- platform: specifiedProviders.platform.getService(),
navLink: specifiedProviders.navLink.getService(),
search: specifiedProviders.search.getService(),
reporting: specifiedProviders.reporting.getService(),
diff --git a/x-pack/plugins/canvas/public/services/legacy/index.ts b/x-pack/plugins/canvas/public/services/legacy/index.ts
index 763fd657ad800..01f252c8eb0d6 100644
--- a/x-pack/plugins/canvas/public/services/legacy/index.ts
+++ b/x-pack/plugins/canvas/public/services/legacy/index.ts
@@ -8,7 +8,6 @@
import { BehaviorSubject } from 'rxjs';
import { CoreSetup, CoreStart, AppUpdater } from '../../../../../../src/core/public';
import { CanvasSetupDeps, CanvasStartDeps } from '../../plugin';
-import { platformServiceFactory } from './platform';
import { navLinkServiceFactory } from './nav_link';
import { embeddablesServiceFactory } from './embeddables';
import { expressionsServiceFactory } from './expressions';
@@ -17,7 +16,6 @@ import { labsServiceFactory } from './labs';
import { reportingServiceFactory } from './reporting';
export { SearchService } from './search';
-export { PlatformService } from './platform';
export { NavLinkService } from './nav_link';
export { EmbeddablesService } from './embeddables';
export { ExpressionsService } from '../../../../../../src/plugins/expressions/common';
@@ -77,7 +75,6 @@ export type ServiceFromProvider = P extends CanvasServiceProvider ?
export const services = {
embeddables: new CanvasServiceProvider(embeddablesServiceFactory),
expressions: new CanvasServiceProvider(expressionsServiceFactory),
- platform: new CanvasServiceProvider(platformServiceFactory),
navLink: new CanvasServiceProvider(navLinkServiceFactory),
search: new CanvasServiceProvider(searchServiceFactory),
reporting: new CanvasServiceProvider(reportingServiceFactory),
@@ -89,7 +86,6 @@ export type CanvasServiceProviders = typeof services;
export interface CanvasServices {
embeddables: ServiceFromProvider;
expressions: ServiceFromProvider;
- platform: ServiceFromProvider;
navLink: ServiceFromProvider;
search: ServiceFromProvider;
reporting: ServiceFromProvider;
@@ -116,7 +112,6 @@ export const stopServices = () => {
export const {
embeddables: embeddableService,
- platform: platformService,
navLink: navLinkService,
expressions: expressionsService,
search: searchService,
diff --git a/x-pack/plugins/canvas/public/services/legacy/stubs/index.ts b/x-pack/plugins/canvas/public/services/legacy/stubs/index.ts
index cebefdd7682cc..9857e27d8a3cf 100644
--- a/x-pack/plugins/canvas/public/services/legacy/stubs/index.ts
+++ b/x-pack/plugins/canvas/public/services/legacy/stubs/index.ts
@@ -11,7 +11,6 @@ import { expressionsService } from './expressions';
import { reportingService } from './reporting';
import { navLinkService } from './nav_link';
import { labsService } from './labs';
-import { platformService } from './platform';
import { searchService } from './search';
export const stubs: CanvasServices = {
@@ -19,7 +18,6 @@ export const stubs: CanvasServices = {
expressions: expressionsService,
reporting: reportingService,
navLink: navLinkService,
- platform: platformService,
search: searchService,
labs: labsService,
};
diff --git a/x-pack/plugins/canvas/public/services/platform.ts b/x-pack/plugins/canvas/public/services/platform.ts
new file mode 100644
index 0000000000000..7a452d809a614
--- /dev/null
+++ b/x-pack/plugins/canvas/public/services/platform.ts
@@ -0,0 +1,33 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0; you may not use this file except in compliance with the Elastic License
+ * 2.0.
+ */
+
+import {
+ SavedObjectsStart,
+ SavedObjectsClientContract,
+ IUiSettingsClient,
+ ChromeBreadcrumb,
+ IBasePath,
+ ChromeStart,
+} from '../../../../../src/core/public';
+
+export interface CanvasPlatformService {
+ getBasePath: () => string;
+ getBasePathInterface: () => IBasePath;
+ getDocLinkVersion: () => string;
+ getElasticWebsiteUrl: () => string;
+ getHasWriteAccess: () => boolean;
+ getUISetting: (key: string, defaultValue?: any) => any;
+ setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => void;
+ setRecentlyAccessed: (link: string, label: string, id: string) => void;
+ setFullscreen: ChromeStart['setIsVisible'];
+
+ // TODO: these should go away. We want thin accessors, not entire objects.
+ // Entire objects are hard to mock, and hide our dependency on the external service.
+ getSavedObjects: () => SavedObjectsStart;
+ getSavedObjectsClient: () => SavedObjectsClientContract;
+ getUISettings: () => IUiSettingsClient;
+}
diff --git a/x-pack/plugins/canvas/public/services/stubs/index.ts b/x-pack/plugins/canvas/public/services/stubs/index.ts
index 5c3440cc4cdbc..1aa05647f7e9e 100644
--- a/x-pack/plugins/canvas/public/services/stubs/index.ts
+++ b/x-pack/plugins/canvas/public/services/stubs/index.ts
@@ -16,13 +16,16 @@ import {
import { CanvasPluginServices } from '..';
import { workpadServiceFactory } from './workpad';
import { notifyServiceFactory } from './notify';
+import { platformServiceFactory } from './platform';
export { workpadServiceFactory } from './workpad';
export { notifyServiceFactory } from './notify';
+export { platformServiceFactory } from './platform';
export const pluginServiceProviders: PluginServiceProviders = {
workpad: new PluginServiceProvider(workpadServiceFactory),
notify: new PluginServiceProvider(notifyServiceFactory),
+ platform: new PluginServiceProvider(platformServiceFactory),
};
export const pluginServiceRegistry = new PluginServiceRegistry(
diff --git a/x-pack/plugins/canvas/public/services/legacy/stubs/platform.ts b/x-pack/plugins/canvas/public/services/stubs/platform.ts
similarity index 72%
rename from x-pack/plugins/canvas/public/services/legacy/stubs/platform.ts
rename to x-pack/plugins/canvas/public/services/stubs/platform.ts
index 5776a1d0d6983..181d355df8a1c 100644
--- a/x-pack/plugins/canvas/public/services/legacy/stubs/platform.ts
+++ b/x-pack/plugins/canvas/public/services/stubs/platform.ts
@@ -5,7 +5,11 @@
* 2.0.
*/
-import { PlatformService } from '../platform';
+import { PluginServiceFactory } from '../../../../../../src/plugins/presentation_util/public';
+
+import { CanvasPlatformService } from '../platform';
+
+type CanvasPlatformServiceFactory = PluginServiceFactory;
const noop = (..._args: any[]): any => {};
@@ -15,7 +19,7 @@ const uiSettings: Record = {
const getUISetting = (setting: string) => uiSettings[setting];
-export const platformService: PlatformService = {
+export const platformServiceFactory: CanvasPlatformServiceFactory = () => ({
getBasePath: () => '/base/path',
getBasePathInterface: noop,
getDocLinkVersion: () => 'dockLinkVersion',
@@ -28,4 +32,4 @@ export const platformService: PlatformService = {
getSavedObjectsClient: noop,
getUISettings: noop,
setFullscreen: noop,
-};
+});
diff --git a/x-pack/plugins/canvas/public/state/initial_state.js b/x-pack/plugins/canvas/public/state/initial_state.js
index e4909bdb95081..c652cc573abe9 100644
--- a/x-pack/plugins/canvas/public/state/initial_state.js
+++ b/x-pack/plugins/canvas/public/state/initial_state.js
@@ -6,11 +6,12 @@
*/
import { get } from 'lodash';
-import { platformService } from '../services';
+import { pluginServices } from '../services';
import { getDefaultWorkpad } from './defaults';
export const getInitialState = (path) => {
- const { getHasWriteAccess } = platformService.getService();
+ const platformService = pluginServices.getServices().platform;
+ const { getHasWriteAccess } = platformService;
const state = {
app: {}, // Kibana stuff in here
diff --git a/x-pack/plugins/canvas/public/state/reducers/workpad.js b/x-pack/plugins/canvas/public/state/reducers/workpad.js
index acd371e9490fb..ebde0106f9c01 100644
--- a/x-pack/plugins/canvas/public/state/reducers/workpad.js
+++ b/x-pack/plugins/canvas/public/state/reducers/workpad.js
@@ -6,7 +6,7 @@
*/
import { handleActions } from 'redux-actions';
-import { platformService } from '../../services';
+import { pluginServices } from '../../services';
import { getDefaultWorkpad } from '../defaults';
import {
setWorkpad,
@@ -24,9 +24,13 @@ import { APP_ROUTE_WORKPAD } from '../../../common/lib/constants';
export const workpadReducer = handleActions(
{
[setWorkpad]: (workpadState, { payload }) => {
- platformService
- .getService()
- .setRecentlyAccessed(`${APP_ROUTE_WORKPAD}/${payload.id}`, payload.name, payload.id);
+ pluginServices
+ .getServices()
+ .platform.setRecentlyAccessed(
+ `${APP_ROUTE_WORKPAD}/${payload.id}`,
+ payload.name,
+ payload.id
+ );
return payload;
},
@@ -39,9 +43,13 @@ export const workpadReducer = handleActions(
},
[setName]: (workpadState, { payload }) => {
- platformService
- .getService()
- .setRecentlyAccessed(`${APP_ROUTE_WORKPAD}/${workpadState.id}`, payload, workpadState.id);
+ pluginServices
+ .getServices()
+ .platform.setRecentlyAccessed(
+ `${APP_ROUTE_WORKPAD}/${workpadState.id}`,
+ payload,
+ workpadState.id
+ );
return { ...workpadState, name: payload };
},
diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts
index 11003d0fcc171..1b5dab0839663 100644
--- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts
+++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/handle_api_errors.ts
@@ -5,6 +5,8 @@
* 2.0.
*/
+import { i18n } from '@kbn/i18n';
+
import { HttpResponse } from 'src/core/public';
import { FlashMessagesLogic } from './flash_messages_logic';
@@ -31,12 +33,17 @@ interface Options {
isQueued?: boolean;
}
+export const defaultErrorMessage = i18n.translate(
+ 'xpack.enterpriseSearch.shared.flashMessages.defaultErrorMessage',
+ {
+ defaultMessage: 'An unexpected error occurred',
+ }
+);
+
/**
* Converts API/HTTP errors into user-facing Flash Messages
*/
export const flashAPIErrors = (error: HttpResponse