Skip to content

Commit

Permalink
[canvas] Create Labs Service; remove legacy service (#107354)
Browse files Browse the repository at this point in the history
  • Loading branch information
clintandrewhall authored Aug 13, 2021
1 parent f952643 commit d78d66d
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 26 deletions.
10 changes: 7 additions & 3 deletions x-pack/plugins/canvas/public/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
export * from './legacy';

import { PluginServices } from '../../../../../src/plugins/presentation_util/public';

import { CanvasCustomElementService } from './custom_element';
import { CanvasEmbeddablesService } from './embeddables';
import { CanvasExpressionsService } from './expressions';
import { CanvasCustomElementService } from './custom_element';
import { CanvasLabsService } from './labs';
import { CanvasNavLinkService } from './nav_link';
import { CanvasNotifyService } from './notify';
import { CanvasPlatformService } from './platform';
Expand All @@ -21,6 +23,7 @@ export interface CanvasPluginServices {
customElement: CanvasCustomElementService;
embeddables: CanvasEmbeddablesService;
expressions: CanvasExpressionsService;
labs: CanvasLabsService;
navLink: CanvasNavLinkService;
notify: CanvasNotifyService;
platform: CanvasPlatformService;
Expand All @@ -30,12 +33,13 @@ export interface CanvasPluginServices {

export const pluginServices = new PluginServices<CanvasPluginServices>();

export const useEmbeddablesService = () =>
(() => pluginServices.getHooks().embeddables.useService())();
export const useCustomElementService = () =>
(() => pluginServices.getHooks().customElement.useService())();
export const useEmbeddablesService = () =>
(() => pluginServices.getHooks().embeddables.useService())();
export const useExpressionsService = () =>
(() => pluginServices.getHooks().expressions.useService())();
export const useLabsService = () => (() => pluginServices.getHooks().labs.useService())();
export const useNavLinkService = () => (() => pluginServices.getHooks().navLink.useService())();
export const useNotifyService = () => (() => pluginServices.getHooks().notify.useService())();
export const usePlatformService = () => (() => pluginServices.getHooks().platform.useService())();
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/canvas/public/services/kibana/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CanvasStartDeps } from '../../plugin';
import { customElementServiceFactory } from './custom_element';
import { embeddablesServiceFactory } from './embeddables';
import { expressionsServiceFactory } from './expressions';
import { labsServiceFactory } from './labs';
import { navLinkServiceFactory } from './nav_link';
import { notifyServiceFactory } from './notify';
import { platformServiceFactory } from './platform';
Expand All @@ -26,6 +27,7 @@ import { workpadServiceFactory } from './workpad';
export { customElementServiceFactory } from './custom_element';
export { embeddablesServiceFactory } from './embeddables';
export { expressionsServiceFactory } from './expressions';
export { labsServiceFactory } from './labs';
export { notifyServiceFactory } from './notify';
export { platformServiceFactory } from './platform';
export { reportingServiceFactory } from './reporting';
Expand All @@ -38,6 +40,7 @@ export const pluginServiceProviders: PluginServiceProviders<
customElement: new PluginServiceProvider(customElementServiceFactory),
embeddables: new PluginServiceProvider(embeddablesServiceFactory),
expressions: new PluginServiceProvider(expressionsServiceFactory),
labs: new PluginServiceProvider(labsServiceFactory),
navLink: new PluginServiceProvider(navLinkServiceFactory),
notify: new PluginServiceProvider(notifyServiceFactory),
platform: new PluginServiceProvider(platformServiceFactory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@
*/

import {
KibanaPluginServiceFactory,
projectIDs,
PresentationLabsService,
} from '../../../../../../src/plugins/presentation_util/public';

import { CanvasServiceFactory } from '.';
import { UI_SETTINGS } from '../../../common';
export interface CanvasLabsService extends PresentationLabsService {
projectIDs: typeof projectIDs;
isLabsEnabled: () => boolean;
}
import { CanvasStartDeps } from '../../plugin';
import { CanvasLabsService } from '../labs';

export type CanvasLabsServiceFactory = KibanaPluginServiceFactory<
CanvasLabsService,
CanvasStartDeps
>;

export const labsServiceFactory: CanvasServiceFactory<CanvasLabsService> = async (
_coreSetup,
coreStart,
_setupPlugins,
startPlugins
) => ({
export const labsServiceFactory: CanvasLabsServiceFactory = ({ startPlugins, coreStart }) => ({
projectIDs,
isLabsEnabled: () => coreStart.uiSettings.get(UI_SETTINGS.ENABLE_LABS_UI),
...startPlugins.presentationUtil.labsService,
Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugins/canvas/public/services/labs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 {
projectIDs,
PresentationLabsService,
} from '../../../../../src/plugins/presentation_util/public';

export interface CanvasLabsService extends PresentationLabsService {
projectIDs: typeof projectIDs;
isLabsEnabled: () => boolean;
}
2 changes: 0 additions & 2 deletions x-pack/plugins/canvas/public/services/legacy/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const defaultContextValue = {
export const ServicesContext = createContext<CanvasServices>(defaultContextValue as CanvasServices);

export const useServices = () => useContext(ServicesContext);
export const useLabsService = () => useServices().labs;
export const withServices = <Props extends WithServicesProps>(type: ComponentType<Props>) => {
const EnhancedType: FC<Props> = (props) =>
createElement(type, { ...props, services: useServices() });
Expand All @@ -40,7 +39,6 @@ export const LegacyServicesProvider: FC<{
const specifiedProviders: CanvasServiceProviders = { ...services, ...providers };
const value = {
search: specifiedProviders.search.getService(),
labs: specifiedProviders.labs.getService(),
};
return <ServicesContext.Provider value={value}>{children}</ServicesContext.Provider>;
};
3 changes: 0 additions & 3 deletions x-pack/plugins/canvas/public/services/legacy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { BehaviorSubject } from 'rxjs';
import { CoreSetup, CoreStart, AppUpdater } from '../../../../../../src/core/public';
import { CanvasSetupDeps, CanvasStartDeps } from '../../plugin';
import { searchServiceFactory } from './search';
import { labsServiceFactory } from './labs';

export { SearchService } from './search';
export { ExpressionsService } from '../../../../../../src/plugins/expressions/common';
Expand Down Expand Up @@ -68,14 +67,12 @@ export type ServiceFromProvider<P> = P extends CanvasServiceProvider<infer T> ?

export const services = {
search: new CanvasServiceProvider(searchServiceFactory),
labs: new CanvasServiceProvider(labsServiceFactory),
};

export type CanvasServiceProviders = typeof services;

export interface CanvasServices {
search: ServiceFromProvider<typeof services.search>;
labs: ServiceFromProvider<typeof services.labs>;
}

export const startLegacyServices = async (
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/canvas/public/services/legacy/stubs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
*/

import { CanvasServices, services } from '../';
import { labsService } from './labs';
import { searchService } from './search';

export const stubs: CanvasServices = {
search: searchService,
labs: labsService,
};

export const startServices = async (providedServices: Partial<CanvasServices> = {}) => {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/canvas/public/services/stubs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CanvasPluginServices } from '..';
import { customElementServiceFactory } from './custom_element';
import { embeddablesServiceFactory } from './embeddables';
import { expressionsServiceFactory } from './expressions';
import { labsServiceFactory } from './labs';
import { navLinkServiceFactory } from './nav_link';
import { notifyServiceFactory } from './notify';
import { platformServiceFactory } from './platform';
Expand All @@ -25,6 +26,7 @@ import { workpadServiceFactory } from './workpad';

export { customElementServiceFactory } from './custom_element';
export { expressionsServiceFactory } from './expressions';
export { labsServiceFactory } from './labs';
export { navLinkServiceFactory } from './nav_link';
export { notifyServiceFactory } from './notify';
export { platformServiceFactory } from './platform';
Expand All @@ -35,6 +37,7 @@ export const pluginServiceProviders: PluginServiceProviders<CanvasPluginServices
customElement: new PluginServiceProvider(customElementServiceFactory),
embeddables: new PluginServiceProvider(embeddablesServiceFactory),
expressions: new PluginServiceProvider(expressionsServiceFactory),
labs: new PluginServiceProvider(labsServiceFactory),
navLink: new PluginServiceProvider(navLinkServiceFactory),
notify: new PluginServiceProvider(notifyServiceFactory),
platform: new PluginServiceProvider(platformServiceFactory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
* 2.0.
*/

import { projectIDs } from '../../../../../../../src/plugins/presentation_util/public';
import {
PluginServiceFactory,
projectIDs,
} from '../../../../../../src/plugins/presentation_util/public';
import { CanvasLabsService } from '../labs';

type CanvasLabsServiceFactory = PluginServiceFactory<CanvasLabsService>;

const noop = (..._args: any[]): any => {};

export const labsService: CanvasLabsService = {
export const labsServiceFactory: CanvasLabsServiceFactory = () => ({
getProject: noop,
getProjects: noop,
getProjectIDs: () => projectIDs,
Expand All @@ -19,4 +24,4 @@ export const labsService: CanvasLabsService = {
projectIDs,
reset: noop,
setProjectStatus: noop,
};
});

0 comments on commit d78d66d

Please sign in to comment.