From 071a52d4d4c83dc367c4376acfa8ed03b4d2c35b Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Wed, 19 Jun 2019 22:21:15 +0200 Subject: [PATCH] No common registry implementation (#39168) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 use new Map() in Embeddables * refactor: 💡 remove IndexPatternCreationConfigRegistry * refactor: 💡 make indexPatternTypes registry semantic * fix: 🐛 fix TypeScript errors --- .../actions/apply_filter_action.test.ts | 2 +- .../embeddable_api/public/actions/index.ts | 4 +- .../public/containers/container.test.ts | 11 +++-- .../public/containers/container.ts | 5 +-- .../public/containers/i_container.ts | 3 +- .../embeddable_api/public/create_registry.ts | 43 ------------------- .../embeddable_factories_registry.ts | 4 +- .../public/get_actions_for_trigger.test.ts | 11 +++-- .../public/get_actions_for_trigger.ts | 6 +-- .../embeddable_api/public/index.ts | 2 +- .../public/panel/embeddable_panel.test.tsx | 3 +- .../add_panel/add_panel_action.test.tsx | 3 +- .../add_panel/add_panel_flyout.test.tsx | 3 +- .../add_panel/add_panel_flyout.tsx | 7 +-- .../customize_panel_action.test.ts | 3 +- .../customize_panel_modal.test.tsx | 3 +- .../inspect_panel_action.test.tsx | 3 +- .../remove_panel_action.test.tsx | 3 +- .../embeddables/filterable_container.tsx | 3 +- .../embeddables/hello_world_container.tsx | 3 +- .../public/triggers/attach_action.ts | 5 +-- .../public/triggers/detach_action.ts | 5 +-- .../triggers/execute_trigger_actions.test.ts | 6 +-- .../embeddable_api/public/triggers/index.ts | 5 +-- .../public/triggers/trigger_registry.test.ts | 4 +- .../embeddable_api/public/types.ts | 9 ---- .../index_pattern_creation/index.js | 2 +- .../index_pattern_creation.js | 12 +++--- ...fig_registry.js => index_pattern_types.js} | 9 +--- .../index_pattern_creation/register.js | 4 +- src/plugins/kibana_utils/README.md | 1 - .../public/app/app.tsx | 7 +-- .../app/hello_world_container_example.tsx | 3 +- .../public/shim.tsx | 4 +- .../public/index_pattern_creation/register.js | 4 +- 35 files changed, 58 insertions(+), 147 deletions(-) delete mode 100644 src/legacy/core_plugins/embeddable_api/public/create_registry.ts rename src/legacy/ui/public/management/index_pattern_creation/{index_pattern_creation_config_registry.js => index_pattern_types.js} (80%) diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts index 67071cc171b5d..88f24be36b117 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/apply_filter_action.test.ts @@ -39,7 +39,7 @@ beforeAll(() => { }); afterAll(() => { - embeddableFactories.reset(); + embeddableFactories.clear(); }); test('ApplyFilterAction applies the filter to the root of the container tree', async () => { diff --git a/src/legacy/core_plugins/embeddable_api/public/actions/index.ts b/src/legacy/core_plugins/embeddable_api/public/actions/index.ts index 81964b62520bc..a0e71340eee23 100644 --- a/src/legacy/core_plugins/embeddable_api/public/actions/index.ts +++ b/src/legacy/core_plugins/embeddable_api/public/actions/index.ts @@ -19,7 +19,5 @@ export { Action, ActionContext } from './action'; export { IncompatibleActionError } from './incompatible_action_error'; -import { createRegistry } from '../create_registry'; import { Action } from './action'; - -export const actionRegistry = createRegistry(); +export const actionRegistry = new Map(); diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts index 58e8e74b4c178..3ac23902f11e0 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/containers/container.test.ts @@ -38,7 +38,6 @@ import { import { isErrorEmbeddable, EmbeddableOutput, EmbeddableFactory } from '../embeddables'; import { ContainerInput } from './i_container'; import { ViewMode } from '../types'; -import { createRegistry } from '../create_registry'; import { FilterableEmbeddableInput, FilterableEmbeddable, @@ -47,7 +46,7 @@ import { ERROR_EMBEDDABLE_TYPE } from '../embeddables/error_embeddable'; import { Filter, FilterStateStore } from '@kbn/es-query'; import { PanelNotFoundError } from './panel_not_found_error'; -const embeddableFactories = createRegistry(); +const embeddableFactories = new Map(); embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory()); embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new SlowContactCardEmbeddableFactory()); embeddableFactories.set(HELLO_WORLD_EMBEDDABLE_TYPE, new HelloWorldEmbeddableFactory()); @@ -555,7 +554,7 @@ test('Container changes made directly after adding a new embeddable are propagat embeddableFactories ); - embeddableFactories.reset(); + embeddableFactories.clear(); embeddableFactories.set( CONTACT_CARD_EMBEDDABLE, new SlowContactCardEmbeddableFactory({ loadTickCount: 3 }) @@ -678,7 +677,7 @@ test('untilEmbeddableLoaded throws an error if there is no such child panel in t }); test('untilEmbeddableLoaded resolves if child is has an type that does not exist', async done => { - embeddableFactories.reset(); + embeddableFactories.clear(); const container = new HelloWorldContainer( { id: 'hello', @@ -699,7 +698,7 @@ test('untilEmbeddableLoaded resolves if child is has an type that does not exist }); test('untilEmbeddableLoaded resolves if child is loaded in the container', async done => { - embeddableFactories.reset(); + embeddableFactories.clear(); embeddableFactories.set(HELLO_WORLD_EMBEDDABLE_TYPE, new HelloWorldEmbeddableFactory()); const container = new HelloWorldContainer( @@ -722,7 +721,7 @@ test('untilEmbeddableLoaded resolves if child is loaded in the container', async }); test('untilEmbeddableLoaded rejects with an error if child is subsequently removed', async done => { - embeddableFactories.reset(); + embeddableFactories.clear(); embeddableFactories.set( CONTACT_CARD_EMBEDDABLE, new SlowContactCardEmbeddableFactory({ loadTickCount: 3 }) diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/container.ts b/src/legacy/core_plugins/embeddable_api/public/containers/container.ts index e848c0a23d828..0fd53e4f335af 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/container.ts +++ b/src/legacy/core_plugins/embeddable_api/public/containers/container.ts @@ -29,7 +29,6 @@ import { } from '../embeddables'; import { IContainer, ContainerInput, ContainerOutput, PanelState } from './i_container'; import { IEmbeddable } from '../embeddables/i_embeddable'; -import { IRegistry } from '../types'; import { PanelNotFoundError } from './panel_not_found_error'; const getKeys = (o: T): Array => Object.keys(o) as Array; @@ -44,14 +43,14 @@ export abstract class Container< protected readonly children: { [key: string]: IEmbeddable | ErrorEmbeddable; } = {}; - public readonly embeddableFactories: IRegistry; + public readonly embeddableFactories: Map; private subscription: Subscription; constructor( input: TContainerInput, output: TContainerOutput, - embeddableFactories: IRegistry, + embeddableFactories: Map, parent?: Container ) { super(input, output, parent); diff --git a/src/legacy/core_plugins/embeddable_api/public/containers/i_container.ts b/src/legacy/core_plugins/embeddable_api/public/containers/i_container.ts index 1c8374d193e98..fb87062af1fd8 100644 --- a/src/legacy/core_plugins/embeddable_api/public/containers/i_container.ts +++ b/src/legacy/core_plugins/embeddable_api/public/containers/i_container.ts @@ -25,7 +25,6 @@ import { EmbeddableFactory, } from '../embeddables'; import { IEmbeddable } from '../embeddables/i_embeddable'; -import { IRegistry } from '../types'; export interface PanelState< E extends { [key: string]: unknown } & { id: string } = { [key: string]: unknown } & { @@ -59,7 +58,7 @@ export interface IContainer< I extends ContainerInput = ContainerInput, O extends ContainerOutput = ContainerOutput > extends IEmbeddable { - readonly embeddableFactories: IRegistry; + readonly embeddableFactories: Map; /** * Call if you want to wait until an embeddable with that id has finished loading. diff --git a/src/legacy/core_plugins/embeddable_api/public/create_registry.ts b/src/legacy/core_plugins/embeddable_api/public/create_registry.ts deleted file mode 100644 index dbc8318c78a64..0000000000000 --- a/src/legacy/core_plugins/embeddable_api/public/create_registry.ts +++ /dev/null @@ -1,43 +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. - */ - -import { IRegistry } from './types'; - -export const createRegistry = (): IRegistry => { - let data = new Map(); - - const get = (id: string) => data.get(id); - const set = (id: string, obj: T) => { - data.set(id, obj); - }; - const reset = () => { - data = new Map(); - }; - const length = () => data.size; - - const getAll = () => Array.from(data.values()); - - return { - get, - set, - reset, - length, - getAll, - }; -}; diff --git a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable_factories_registry.ts b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable_factories_registry.ts index ca648a62b412b..c8ebd942d49eb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable_factories_registry.ts +++ b/src/legacy/core_plugins/embeddable_api/public/embeddables/embeddable_factories_registry.ts @@ -18,6 +18,4 @@ */ import { EmbeddableFactory } from './embeddable_factory'; -import { createRegistry } from '../create_registry'; - -export const embeddableFactories = createRegistry(); +export const embeddableFactories = new Map(); diff --git a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts index 14fafacd5de69..eccde1c3d59a7 100644 --- a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.test.ts @@ -33,13 +33,13 @@ import { getActionsForTrigger } from './get_actions_for_trigger'; import { attachAction } from './triggers/attach_action'; beforeEach(() => { - actionRegistry.reset(); - triggerRegistry.reset(); + actionRegistry.clear(); + triggerRegistry.clear(); }); afterAll(() => { - actionRegistry.reset(); - triggerRegistry.reset(); + actionRegistry.clear(); + triggerRegistry.clear(); }); test('ActionRegistry adding and getting an action', async () => { @@ -49,8 +49,7 @@ test('ActionRegistry adding and getting an action', async () => { actionRegistry.set(sayHelloAction.id, sayHelloAction); actionRegistry.set(helloWorldAction.id, helloWorldAction); - expect(actionRegistry.length()).toBe(2); - + expect(actionRegistry.size).toBe(2); expect(actionRegistry.get(sayHelloAction.id)).toBe(sayHelloAction); expect(actionRegistry.get(helloWorldAction.id)).toBe(helloWorldAction); }); diff --git a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.ts b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.ts index 6574e10d6002c..eea740aca2767 100644 --- a/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.ts +++ b/src/legacy/core_plugins/embeddable_api/public/get_actions_for_trigger.ts @@ -20,11 +20,11 @@ import { Action } from './actions'; import { IEmbeddable } from './embeddables'; import { IContainer } from './containers'; -import { IRegistry, Trigger } from './types'; +import { Trigger } from './types'; export async function getActionsForTrigger( - actionRegistry: IRegistry, - triggerRegistry: IRegistry, + actionRegistry: Map, + triggerRegistry: Map, triggerId: string, context: { embeddable: IEmbeddable; container?: IContainer } ) { diff --git a/src/legacy/core_plugins/embeddable_api/public/index.ts b/src/legacy/core_plugins/embeddable_api/public/index.ts index 7b80fe4b51664..92cfe0a369c21 100644 --- a/src/legacy/core_plugins/embeddable_api/public/index.ts +++ b/src/legacy/core_plugins/embeddable_api/public/index.ts @@ -29,7 +29,7 @@ export { isErrorEmbeddable, } from './embeddables'; -export { ViewMode, Trigger, IRegistry } from './types'; +export { ViewMode, Trigger } from './types'; export { actionRegistry, Action, ActionContext, IncompatibleActionError } from './actions'; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx index a0207a1de0c2b..489ee970f9deb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/embeddable_panel.test.tsx @@ -45,7 +45,6 @@ import { findTestSubject } from '@elastic/eui/lib/test'; import { I18nProvider } from '@kbn/i18n/react'; import { CONTEXT_MENU_TRIGGER } from '../triggers'; import { attachAction } from '../triggers/attach_action'; -import { createRegistry } from '../create_registry'; import { EmbeddableFactory } from '../embeddables'; const editModeAction = new EditModeAction(); @@ -55,7 +54,7 @@ attachAction(triggerRegistry, { actionId: editModeAction.id, }); -const embeddableFactories = createRegistry(); +const embeddableFactories = new Map(); embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory()); test('HelloWorldContainer initializes embeddables', async done => { diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx index c375494d497c8..e08f806f8477f 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_action.test.tsx @@ -30,11 +30,10 @@ import { import { ViewMode, EmbeddableOutput, isErrorEmbeddable } from '../../../../'; import { AddPanelAction } from './add_panel_action'; -import { createRegistry } from '../../../../create_registry'; import { EmbeddableFactory } from '../../../../embeddables'; import { Filter, FilterStateStore } from '@kbn/es-query'; -const embeddableFactories = createRegistry(); +const embeddableFactories = new Map(); embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory()); let container: FilterableContainer; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx index 42289ab65df27..137bf36d0230c 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.test.tsx @@ -35,14 +35,13 @@ import { findTestSubject } from '@elastic/eui/lib/test'; import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers'; import { skip } from 'rxjs/operators'; import * as Rx from 'rxjs'; -import { createRegistry } from '../../../../create_registry'; import { EmbeddableFactory } from '../../../../embeddables'; const onClose = jest.fn(); let container: Container; function createHelloWorldContainer(input = { id: '123', panels: {} }) { - const embeddableFactories = createRegistry(); + const embeddableFactories = new Map(); embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory()); return new HelloWorldContainer(input, embeddableFactories); } diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx index 962ab1989ec62..1683f05c1d6b7 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/add_panel/add_panel_flyout.tsx @@ -109,9 +109,7 @@ export class AddPanelFlyout extends React.Component { ), }, - - ...this.props.container.embeddableFactories - .getAll() + ...[...this.props.container.embeddableFactories.values()] .filter( factory => factory.isEditable() && !factory.isContainerType && factory.canCreateNew() ) @@ -147,8 +145,7 @@ export class AddPanelFlyout extends React.Component { Boolean(embeddableFactory.savedObjectMetaData) && diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts index eee46df447194..5215f662c6a6a 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_action.test.ts @@ -33,14 +33,13 @@ import { Container, isErrorEmbeddable } from '../../../..'; import { findTestSubject } from '@elastic/eui/lib/test'; import { nextTick } from 'test_utils/enzyme_helpers'; import { CustomizePanelTitleAction } from './customize_panel_action'; -import { createRegistry } from '../../../../create_registry'; import { EmbeddableFactory } from '../../../../embeddables'; let container: Container; let embeddable: ContactCardEmbeddable; function createHelloWorldContainer(input = { id: '123', panels: {} }) { - const embeddableFactories = createRegistry(); + const embeddableFactories = new Map(); embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory()); return new HelloWorldContainer(input, embeddableFactories); } diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx index 9dbb481c429bd..3192c4838a855 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/customize_title/customize_panel_modal.test.tsx @@ -34,14 +34,13 @@ import { findTestSubject } from '@elastic/eui/lib/test'; import { CustomizePanelModal } from './customize_panel_modal'; import { Container, isErrorEmbeddable } from '../../../..'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { createRegistry } from '../../../../create_registry'; import { EmbeddableFactory } from '../../../../embeddables'; let container: Container; let embeddable: ContactCardEmbeddable; beforeEach(async () => { - const embeddableFactories = createRegistry(); + const embeddableFactories = new Map(); embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory()); container = new HelloWorldContainer({ id: '123', panels: {} }, embeddableFactories); const contactCardEmbeddable = await container.addNewEmbeddable< diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx index d5e9a2e222424..0a0ba4f08f646 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/inspect_panel_action.test.tsx @@ -42,11 +42,10 @@ import { import { EmbeddableOutput, isErrorEmbeddable } from '../../..'; import { InspectPanelAction } from './inspect_panel_action'; import { Inspector, Adapters } from 'ui/inspector'; -import { createRegistry } from '../../../create_registry'; import { EmbeddableFactory } from '../../../embeddables'; import { Filter, FilterStateStore } from '@kbn/es-query'; -const embeddableFactories = createRegistry(); +const embeddableFactories = new Map(); embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory()); let container: FilterableContainer; diff --git a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx index cadcb315439b9..f8b7c9ef6fbd3 100644 --- a/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/panel/panel_header/panel_actions/remove_panel_action.test.tsx @@ -30,11 +30,10 @@ import { import { EmbeddableOutput, isErrorEmbeddable } from '../../../'; import { RemovePanelAction } from './remove_panel_action'; -import { createRegistry } from '../../../create_registry'; import { EmbeddableFactory } from '../../../embeddables'; import { Filter, FilterStateStore } from '@kbn/es-query'; -const embeddableFactories = createRegistry(); +const embeddableFactories = new Map(); embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory()); let container: FilterableContainer; diff --git a/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/filterable_container.tsx b/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/filterable_container.tsx index 56e5d0779c8fe..73195cbab529e 100644 --- a/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/filterable_container.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/filterable_container.tsx @@ -18,7 +18,6 @@ */ import { Filter } from '@kbn/es-query'; import { EmbeddableFactory } from '../../embeddables'; -import { IRegistry } from '../../types'; import { Container, ContainerInput } from '../../containers'; export const FILTERABLE_CONTAINER = 'FILTERABLE_CONTAINER'; @@ -40,7 +39,7 @@ export class FilterableContainer extends Container< constructor( initialInput: FilterableContainerInput, - embeddableFactories: IRegistry, + embeddableFactories: Map, parent?: Container ) { super(initialInput, { embeddableLoaded: {} }, embeddableFactories, parent); diff --git a/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/hello_world_container.tsx b/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/hello_world_container.tsx index f4fdc8329097c..3793f0e10959c 100644 --- a/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/hello_world_container.tsx +++ b/src/legacy/core_plugins/embeddable_api/public/test_samples/embeddables/hello_world_container.tsx @@ -21,7 +21,6 @@ import ReactDOM from 'react-dom'; import { I18nProvider } from '@kbn/i18n/react'; import { Container, ViewMode, ContainerInput } from '../..'; import { HelloWorldContainerComponent } from './hello_world_container_component'; -import { IRegistry } from '../../types'; import { EmbeddableFactory } from '../../embeddables'; export const HELLO_WORLD_CONTAINER = 'HELLO_WORLD_CONTAINER'; @@ -35,7 +34,7 @@ interface InheritedInput { export class HelloWorldContainer extends Container { public readonly type = HELLO_WORLD_CONTAINER; - constructor(input: ContainerInput, embeddableFactories: IRegistry) { + constructor(input: ContainerInput, embeddableFactories: Map) { super(input, { embeddableLoaded: {} }, embeddableFactories); } diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/attach_action.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/attach_action.ts index 711f641b0cbeb..b6b6abf2abbb2 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/attach_action.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/attach_action.ts @@ -17,10 +17,10 @@ * under the License. */ -import { IRegistry, Trigger } from '../types'; +import { Trigger } from '../types'; export function attachAction( - triggerRegistry: IRegistry, + triggerRegistry: Map, { triggerId, actionId }: { triggerId: string; actionId: string } ) { const trigger = triggerRegistry.get(triggerId); @@ -31,5 +31,4 @@ export function attachAction( if (!trigger.actionIds.find(id => id === actionId)) { trigger.actionIds.push(actionId); } - triggerRegistry.set(trigger.id, trigger); } diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/detach_action.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/detach_action.ts index 7cb4670e50b12..f77bb6b5bb8eb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/detach_action.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/detach_action.ts @@ -17,10 +17,10 @@ * under the License. */ -import { IRegistry, Trigger } from '../types'; +import { Trigger } from '../types'; export function detachAction( - triggerRegistry: IRegistry, + triggerRegistry: Map, { triggerId, actionId }: { triggerId: string; actionId: string } ) { const trigger = triggerRegistry.get(triggerId); @@ -29,5 +29,4 @@ export function detachAction( } trigger.actionIds = trigger.actionIds.filter(id => id !== actionId); - triggerRegistry.set(trigger.id, trigger); } diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts index beefff8f75b14..5a95da378b847 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/execute_trigger_actions.test.ts @@ -55,13 +55,13 @@ class TestAction extends Action { } beforeEach(() => { - triggerRegistry.reset(); - actionRegistry.reset(); + triggerRegistry.clear(); + actionRegistry.clear(); executeFn.mockReset(); }); afterAll(() => { - triggerRegistry.reset(); + triggerRegistry.clear(); }); test('executeTriggerActions executes a single action mapped to a trigger', async () => { diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/index.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/index.ts index 134d3387f1eee..82cecafb417f4 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/index.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/index.ts @@ -22,11 +22,8 @@ export { executeTriggerActions } from './execute_trigger_actions'; export const CONTEXT_MENU_TRIGGER = 'CONTEXT_MENU_TRIGGER'; export const APPLY_FILTER_TRIGGER = 'FITLER_TRIGGER'; - -import { createRegistry } from '../create_registry'; import { Trigger } from '../types'; - -export const triggerRegistry = createRegistry(); +export const triggerRegistry = new Map(); triggerRegistry.set(CONTEXT_MENU_TRIGGER, { id: CONTEXT_MENU_TRIGGER, diff --git a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts index f457b42118887..f2dac33da80b1 100644 --- a/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/triggers/trigger_registry.test.ts @@ -25,11 +25,11 @@ import { attachAction } from './attach_action'; import { detachAction } from './detach_action'; beforeAll(() => { - triggerRegistry.reset(); + triggerRegistry.clear(); }); afterAll(() => { - triggerRegistry.reset(); + triggerRegistry.clear(); }); test('TriggerRegistry adding and getting a new trigger', async () => { diff --git a/src/legacy/core_plugins/embeddable_api/public/types.ts b/src/legacy/core_plugins/embeddable_api/public/types.ts index ebb51ac199c28..62fcbc82cbdb9 100644 --- a/src/legacy/core_plugins/embeddable_api/public/types.ts +++ b/src/legacy/core_plugins/embeddable_api/public/types.ts @@ -24,15 +24,6 @@ export interface Trigger { actionIds: string[]; } -// TODO: use the official base Registry interface when available -export interface IRegistry { - get(id: string): T | undefined; - length(): number; - set(id: string, item: T): void; - reset(): void; - getAll(): T[]; -} - export interface PropertySpec { displayName: string; accessPath: string; diff --git a/src/legacy/ui/public/management/index_pattern_creation/index.js b/src/legacy/ui/public/management/index_pattern_creation/index.js index 6b1dbcc084e2f..0b677cbfd1f64 100644 --- a/src/legacy/ui/public/management/index_pattern_creation/index.js +++ b/src/legacy/ui/public/management/index_pattern_creation/index.js @@ -20,4 +20,4 @@ import './register'; export { IndexPatternCreationFactory } from './index_pattern_creation'; export { IndexPatternCreationConfig } from './index_pattern_creation_config'; -export { IndexPatternCreationConfigRegistry } from './index_pattern_creation_config_registry'; +export { indexPatternTypes, addIndexPatternType } from './index_pattern_types'; diff --git a/src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation.js b/src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation.js index 4e44173151080..12cecc956ab68 100644 --- a/src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation.js +++ b/src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation.js @@ -17,17 +17,16 @@ * under the License. */ -import { IndexPatternCreationConfigRegistry } from './index_pattern_creation_config_registry'; +import { indexPatternTypes } from './index_pattern_types'; class IndexPatternCreation { - constructor(registry, httpClient, type) { - this._registry = registry; - this._allTypes = this._registry.inOrder.map(Plugin => new Plugin({ httpClient })); + constructor(httpClient, type) { + this._allTypes = indexPatternTypes.map(Plugin => new Plugin({ httpClient })); this._setCurrentType(type); } _setCurrentType = (type) => { - const index = type ? this._registry.inOrder.findIndex(Plugin => Plugin.key === type) : -1; + const index = type ? indexPatternTypes.findIndex(Plugin => Plugin.key === type) : -1; this._currentType = index > -1 && this._allTypes[index] ? this._allTypes[index] : null; } @@ -49,8 +48,7 @@ class IndexPatternCreation { export const IndexPatternCreationFactory = (Private, $http) => { return (type = 'default') => { - const indexPatternCreationRegistry = Private(IndexPatternCreationConfigRegistry); - const indexPatternCreationProvider = new IndexPatternCreation(indexPatternCreationRegistry, $http, type); + const indexPatternCreationProvider = new IndexPatternCreation($http, type); return indexPatternCreationProvider; }; }; diff --git a/src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation_config_registry.js b/src/legacy/ui/public/management/index_pattern_creation/index_pattern_types.js similarity index 80% rename from src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation_config_registry.js rename to src/legacy/ui/public/management/index_pattern_creation/index_pattern_types.js index 9fb65a1bcb002..9e94a52278ab2 100644 --- a/src/legacy/ui/public/management/index_pattern_creation/index_pattern_creation_config_registry.js +++ b/src/legacy/ui/public/management/index_pattern_creation/index_pattern_types.js @@ -17,10 +17,5 @@ * under the License. */ -import { uiRegistry } from 'ui/registry/_registry'; - -export const IndexPatternCreationConfigRegistry = uiRegistry({ - name: 'indexPatternCreation', - index: ['name'], - order: ['order'], -}); +export const indexPatternTypes = []; +export const addIndexPatternType = (type) => indexPatternTypes.push(type); diff --git a/src/legacy/ui/public/management/index_pattern_creation/register.js b/src/legacy/ui/public/management/index_pattern_creation/register.js index 764c275fdf3a0..bca4387b496fd 100644 --- a/src/legacy/ui/public/management/index_pattern_creation/register.js +++ b/src/legacy/ui/public/management/index_pattern_creation/register.js @@ -18,6 +18,6 @@ */ import { IndexPatternCreationConfig } from './index_pattern_creation_config'; -import { IndexPatternCreationConfigRegistry } from './index_pattern_creation_config_registry'; +import { addIndexPatternType } from './index_pattern_types'; -IndexPatternCreationConfigRegistry.register(() => IndexPatternCreationConfig); +addIndexPatternType(IndexPatternCreationConfig); diff --git a/src/plugins/kibana_utils/README.md b/src/plugins/kibana_utils/README.md index 7e3aea954923c..61ceea2b18385 100644 --- a/src/plugins/kibana_utils/README.md +++ b/src/plugins/kibana_utils/README.md @@ -3,4 +3,3 @@ Utilities for building Kibana plugins. - [Store reactive serializable app state in state containers, `createStore`](./docs/store/README.md). -- Store non-serializable or any other state in registries, `createRegistry` diff --git a/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/app.tsx b/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/app.tsx index 9bedefd62cccd..a9ec0095b5ea2 100644 --- a/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/app.tsx +++ b/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/app.tsx @@ -19,15 +19,12 @@ import { I18nContext } from 'ui/i18n'; import { EuiTab } from '@elastic/eui'; import React, { Component } from 'react'; -import { - IRegistry, - EmbeddableFactory, -} from '../../../../../../src/legacy/core_plugins/embeddable_api/public'; +import { EmbeddableFactory } from '../../../../../../src/legacy/core_plugins/embeddable_api/public'; import { ContactCardEmbeddableExample } from './hello_world_embeddable_example'; import { HelloWorldContainerExample } from './hello_world_container_example'; export interface AppProps { - embeddableFactories: IRegistry; + embeddableFactories: Map; } export class App extends Component { diff --git a/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/hello_world_container_example.tsx b/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/hello_world_container_example.tsx index 2faea80769aa1..c614a5f0420ff 100644 --- a/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/hello_world_container_example.tsx +++ b/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/app/hello_world_container_example.tsx @@ -23,7 +23,6 @@ import { EmbeddablePanel, Container, embeddableFactories, - IRegistry, EmbeddableFactory, } from 'plugins/embeddable_api'; import { @@ -33,7 +32,7 @@ import { } from '../../../../../../src/legacy/core_plugins/embeddable_api/public/test_samples'; interface Props { - embeddableFactories: IRegistry; + embeddableFactories: Map; } export class HelloWorldContainerExample extends React.Component { diff --git a/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/shim.tsx b/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/shim.tsx index 590e3e954827f..7e430f6ea119b 100644 --- a/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/shim.tsx +++ b/test/plugin_functional/plugins/kbn_tp_embeddable_explorer/public/shim.tsx @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { embeddableFactories, IRegistry, EmbeddableFactory } from 'plugins/embeddable_api'; +import { embeddableFactories, EmbeddableFactory } from 'plugins/embeddable_api'; import 'ui/autoload/all'; import 'uiExports/embeddableActions'; @@ -30,7 +30,7 @@ import template from './index.html'; export interface PluginShim { embeddableAPI: { - embeddableFactories: IRegistry; + embeddableFactories: Map; }; } diff --git a/x-pack/plugins/rollup/public/index_pattern_creation/register.js b/x-pack/plugins/rollup/public/index_pattern_creation/register.js index c5ce42a3022b2..b14531d8f6efd 100644 --- a/x-pack/plugins/rollup/public/index_pattern_creation/register.js +++ b/x-pack/plugins/rollup/public/index_pattern_creation/register.js @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { IndexPatternCreationConfigRegistry } from 'ui/management/index_pattern_creation'; +import { addIndexPatternType } from 'ui/management/index_pattern_creation'; import { RollupIndexPatternCreationConfig } from './rollup_index_pattern_creation_config'; export function initIndexPatternCreation() { - IndexPatternCreationConfigRegistry.register(() => RollupIndexPatternCreationConfig); + addIndexPatternType(RollupIndexPatternCreationConfig); }