[canvas] Create Embeddables Service; remove legacy service (#107351)
This commit is contained in:
parent
cc9d69ebc6
commit
5533a4061f
|
@ -13,7 +13,7 @@ import {
|
|||
SavedObjectFinderUi,
|
||||
SavedObjectMetaData,
|
||||
} from '../../../../../../src/plugins/saved_objects/public/';
|
||||
import { usePlatformService, useServices } from '../../services';
|
||||
import { useEmbeddablesService, usePlatformService } from '../../services';
|
||||
|
||||
const strings = {
|
||||
getNoItemsText: () =>
|
||||
|
@ -32,10 +32,9 @@ export interface Props {
|
|||
}
|
||||
|
||||
export const AddEmbeddableFlyout: FC<Props> = ({ onSelect, availableEmbeddables, onClose }) => {
|
||||
const services = useServices();
|
||||
const embeddablesService = useEmbeddablesService();
|
||||
const platformService = usePlatformService();
|
||||
const { embeddables } = services;
|
||||
const { getEmbeddableFactories } = embeddables;
|
||||
const { getEmbeddableFactories } = embeddablesService;
|
||||
const { getSavedObjects, getUISettings } = platformService;
|
||||
|
||||
const onAddPanel = (id: string, savedObjectType: string, name: string) => {
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { EmbeddablesService } from '../embeddables';
|
||||
import { EmbeddableFactory } from '../../../../../src/plugins/embeddable/public';
|
||||
|
||||
const noop = (..._args: any[]): any => {};
|
||||
|
||||
export const embeddablesService: EmbeddablesService = {
|
||||
getEmbeddableFactories: noop,
|
||||
};
|
||||
export interface CanvasEmbeddablesService {
|
||||
getEmbeddableFactories: () => IterableIterator<EmbeddableFactory>;
|
||||
}
|
|
@ -10,6 +10,7 @@ export * from './legacy';
|
|||
import { PluginServices } from '../../../../../src/plugins/presentation_util/public';
|
||||
import { CanvasExpressionsService } from './expressions';
|
||||
import { CanvasNavLinkService } from './nav_link';
|
||||
import { CanvasEmbeddablesService } from './embeddables';
|
||||
import { CanvasNotifyService } from './notify';
|
||||
import { CanvasPlatformService } from './platform';
|
||||
import { CanvasReportingService } from './reporting';
|
||||
|
@ -18,6 +19,7 @@ import { CanvasWorkpadService } from './workpad';
|
|||
export interface CanvasPluginServices {
|
||||
expressions: CanvasExpressionsService;
|
||||
navLink: CanvasNavLinkService;
|
||||
embeddables: CanvasEmbeddablesService;
|
||||
notify: CanvasNotifyService;
|
||||
platform: CanvasPlatformService;
|
||||
reporting: CanvasReportingService;
|
||||
|
@ -29,6 +31,8 @@ export const pluginServices = new PluginServices<CanvasPluginServices>();
|
|||
export const useExpressionsService = () =>
|
||||
(() => pluginServices.getHooks().expressions.useService())();
|
||||
export const useNavLinkService = () => (() => pluginServices.getHooks().navLink.useService())();
|
||||
export const useEmbeddablesService = () =>
|
||||
(() => pluginServices.getHooks().embeddables.useService())();
|
||||
export const useNotifyService = () => (() => pluginServices.getHooks().notify.useService())();
|
||||
export const usePlatformService = () => (() => pluginServices.getHooks().platform.useService())();
|
||||
export const useReportingService = () => (() => pluginServices.getHooks().reporting.useService())();
|
||||
|
|
19
x-pack/plugins/canvas/public/services/kibana/embeddables.ts
Normal file
19
x-pack/plugins/canvas/public/services/kibana/embeddables.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* 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 { KibanaPluginServiceFactory } from '../../../../../../src/plugins/presentation_util/public';
|
||||
import { CanvasStartDeps } from '../../plugin';
|
||||
import { CanvasEmbeddablesService } from '../embeddables';
|
||||
|
||||
export type EmbeddablesServiceFactory = KibanaPluginServiceFactory<
|
||||
CanvasEmbeddablesService,
|
||||
CanvasStartDeps
|
||||
>;
|
||||
|
||||
export const embeddablesServiceFactory: EmbeddablesServiceFactory = ({ startPlugins }) => ({
|
||||
getEmbeddableFactories: startPlugins.embeddable.getEmbeddableFactories,
|
||||
});
|
|
@ -14,6 +14,7 @@ import {
|
|||
|
||||
import { CanvasPluginServices } from '..';
|
||||
import { CanvasStartDeps } from '../../plugin';
|
||||
import { embeddablesServiceFactory } from './embeddables';
|
||||
import { expressionsServiceFactory } from './expressions';
|
||||
import { navLinkServiceFactory } from './nav_link';
|
||||
import { notifyServiceFactory } from './notify';
|
||||
|
@ -22,6 +23,7 @@ import { reportingServiceFactory } from './reporting';
|
|||
import { workpadServiceFactory } from './workpad';
|
||||
|
||||
export { expressionsServiceFactory } from './expressions';
|
||||
export { embeddablesServiceFactory } from './embeddables';
|
||||
export { notifyServiceFactory } from './notify';
|
||||
export { platformServiceFactory } from './platform';
|
||||
export { reportingServiceFactory } from './reporting';
|
||||
|
@ -33,6 +35,7 @@ export const pluginServiceProviders: PluginServiceProviders<
|
|||
> = {
|
||||
expressions: new PluginServiceProvider(expressionsServiceFactory),
|
||||
navLink: new PluginServiceProvider(navLinkServiceFactory),
|
||||
embeddables: new PluginServiceProvider(embeddablesServiceFactory),
|
||||
notify: new PluginServiceProvider(notifyServiceFactory),
|
||||
platform: new PluginServiceProvider(platformServiceFactory),
|
||||
reporting: new PluginServiceProvider(reportingServiceFactory),
|
||||
|
|
|
@ -20,14 +20,12 @@ export interface WithServicesProps {
|
|||
}
|
||||
|
||||
const defaultContextValue = {
|
||||
embeddables: {},
|
||||
search: {},
|
||||
};
|
||||
|
||||
export const ServicesContext = createContext<CanvasServices>(defaultContextValue as CanvasServices);
|
||||
|
||||
export const useServices = () => useContext(ServicesContext);
|
||||
export const useEmbeddablesService = () => useServices().embeddables;
|
||||
export const useLabsService = () => useServices().labs;
|
||||
export const withServices = <Props extends WithServicesProps>(type: ComponentType<Props>) => {
|
||||
const EnhancedType: FC<Props> = (props) =>
|
||||
|
@ -41,7 +39,6 @@ export const LegacyServicesProvider: FC<{
|
|||
}> = ({ providers = {}, children }) => {
|
||||
const specifiedProviders: CanvasServiceProviders = { ...services, ...providers };
|
||||
const value = {
|
||||
embeddables: specifiedProviders.embeddables.getService(),
|
||||
search: specifiedProviders.search.getService(),
|
||||
labs: specifiedProviders.labs.getService(),
|
||||
};
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
/*
|
||||
* 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 { EmbeddableFactory } from '../../../../../../src/plugins/embeddable/public';
|
||||
import { CanvasServiceFactory } from '.';
|
||||
|
||||
export interface EmbeddablesService {
|
||||
getEmbeddableFactories: () => IterableIterator<EmbeddableFactory>;
|
||||
}
|
||||
|
||||
export const embeddablesServiceFactory: CanvasServiceFactory<EmbeddablesService> = async (
|
||||
_coreSetup,
|
||||
_coreStart,
|
||||
_setupPlugins,
|
||||
startPlugins
|
||||
) => ({
|
||||
getEmbeddableFactories: startPlugins.embeddable.getEmbeddableFactories,
|
||||
});
|
|
@ -8,12 +8,10 @@
|
|||
import { BehaviorSubject } from 'rxjs';
|
||||
import { CoreSetup, CoreStart, AppUpdater } from '../../../../../../src/core/public';
|
||||
import { CanvasSetupDeps, CanvasStartDeps } from '../../plugin';
|
||||
import { embeddablesServiceFactory } from './embeddables';
|
||||
import { searchServiceFactory } from './search';
|
||||
import { labsServiceFactory } from './labs';
|
||||
|
||||
export { SearchService } from './search';
|
||||
export { EmbeddablesService } from './embeddables';
|
||||
export { ExpressionsService } from '../../../../../../src/plugins/expressions/common';
|
||||
export * from './context';
|
||||
|
||||
|
@ -69,7 +67,6 @@ export class CanvasServiceProvider<Service> {
|
|||
export type ServiceFromProvider<P> = P extends CanvasServiceProvider<infer T> ? T : never;
|
||||
|
||||
export const services = {
|
||||
embeddables: new CanvasServiceProvider(embeddablesServiceFactory),
|
||||
search: new CanvasServiceProvider(searchServiceFactory),
|
||||
labs: new CanvasServiceProvider(labsServiceFactory),
|
||||
};
|
||||
|
@ -77,7 +74,6 @@ export const services = {
|
|||
export type CanvasServiceProviders = typeof services;
|
||||
|
||||
export interface CanvasServices {
|
||||
embeddables: ServiceFromProvider<typeof services.embeddables>;
|
||||
search: ServiceFromProvider<typeof services.search>;
|
||||
labs: ServiceFromProvider<typeof services.labs>;
|
||||
}
|
||||
|
@ -100,4 +96,4 @@ export const stopServices = () => {
|
|||
Object.values(services).forEach((provider) => provider.stop());
|
||||
};
|
||||
|
||||
export const { embeddables: embeddableService, search: searchService } = services;
|
||||
export const { search: searchService } = services;
|
||||
|
|
|
@ -6,12 +6,10 @@
|
|||
*/
|
||||
|
||||
import { CanvasServices, services } from '../';
|
||||
import { embeddablesService } from './embeddables';
|
||||
import { labsService } from './labs';
|
||||
import { searchService } from './search';
|
||||
|
||||
export const stubs: CanvasServices = {
|
||||
embeddables: embeddablesService,
|
||||
search: searchService,
|
||||
labs: labsService,
|
||||
};
|
||||
|
|
17
x-pack/plugins/canvas/public/services/stubs/embeddables.ts
Normal file
17
x-pack/plugins/canvas/public/services/stubs/embeddables.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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 { PluginServiceFactory } from '../../../../../../src/plugins/presentation_util/public';
|
||||
import { CanvasEmbeddablesService } from '../embeddables';
|
||||
|
||||
type EmbeddablesServiceFactory = PluginServiceFactory<CanvasEmbeddablesService>;
|
||||
|
||||
const noop = (..._args: any[]): any => {};
|
||||
|
||||
export const embeddablesServiceFactory: EmbeddablesServiceFactory = () => ({
|
||||
getEmbeddableFactories: noop,
|
||||
});
|
|
@ -14,6 +14,7 @@ import {
|
|||
} from '../../../../../../src/plugins/presentation_util/public';
|
||||
|
||||
import { CanvasPluginServices } from '..';
|
||||
import { embeddablesServiceFactory } from './embeddables';
|
||||
import { expressionsServiceFactory } from './expressions';
|
||||
import { navLinkServiceFactory } from './nav_link';
|
||||
import { notifyServiceFactory } from './notify';
|
||||
|
@ -29,6 +30,7 @@ export { reportingServiceFactory } from './reporting';
|
|||
export { workpadServiceFactory } from './workpad';
|
||||
|
||||
export const pluginServiceProviders: PluginServiceProviders<CanvasPluginServices> = {
|
||||
embeddables: new PluginServiceProvider(embeddablesServiceFactory),
|
||||
expressions: new PluginServiceProvider(expressionsServiceFactory),
|
||||
navLink: new PluginServiceProvider(navLinkServiceFactory),
|
||||
notify: new PluginServiceProvider(notifyServiceFactory),
|
||||
|
|
Loading…
Reference in a new issue