Skip to content

Commit

Permalink
[7.x] No common registry implementation (#39168) (#39309)
Browse files Browse the repository at this point in the history
* refactor: πŸ’‘ use new Map() in Embeddables

* refactor: πŸ’‘ remove IndexPatternCreationConfigRegistry

* refactor: πŸ’‘ make indexPatternTypes registry semantic

* fix: πŸ› fix TypeScript errors
  • Loading branch information
streamich authored Jun 20, 2019
1 parent 7d52f0f commit 251142b
Show file tree
Hide file tree
Showing 35 changed files with 58 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ beforeAll(() => {
});

afterAll(() => {
embeddableFactories.reset();
embeddableFactories.clear();
});

test('ApplyFilterAction applies the filter to the root of the container tree', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action>();
export const actionRegistry = new Map<string, Action>();
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory());
embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new SlowContactCardEmbeddableFactory());
embeddableFactories.set(HELLO_WORLD_EMBEDDABLE_TYPE, new HelloWorldEmbeddableFactory());
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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',
Expand All @@ -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(
Expand All @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T extends {}>(o: T): Array<keyof T> => Object.keys(o) as Array<keyof T>;
Expand All @@ -44,14 +43,14 @@ export abstract class Container<
protected readonly children: {
[key: string]: IEmbeddable<any, any> | ErrorEmbeddable;
} = {};
public readonly embeddableFactories: IRegistry<EmbeddableFactory>;
public readonly embeddableFactories: Map<string, EmbeddableFactory>;

private subscription: Subscription;

constructor(
input: TContainerInput,
output: TContainerOutput,
embeddableFactories: IRegistry<EmbeddableFactory>,
embeddableFactories: Map<string, EmbeddableFactory>,
parent?: Container
) {
super(input, output, parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } & {
Expand Down Expand Up @@ -59,7 +58,7 @@ export interface IContainer<
I extends ContainerInput = ContainerInput,
O extends ContainerOutput = ContainerOutput
> extends IEmbeddable<I, O> {
readonly embeddableFactories: IRegistry<EmbeddableFactory>;
readonly embeddableFactories: Map<string, EmbeddableFactory>;

/**
* Call if you want to wait until an embeddable with that id has finished loading.
Expand Down
43 changes: 0 additions & 43 deletions src/legacy/core_plugins/embeddable_api/public/create_registry.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
*/

import { EmbeddableFactory } from './embeddable_factory';
import { createRegistry } from '../create_registry';

export const embeddableFactories = createRegistry<EmbeddableFactory>();
export const embeddableFactories = new Map<string, EmbeddableFactory>();
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Action>,
triggerRegistry: IRegistry<Trigger>,
actionRegistry: Map<string, Action>,
triggerRegistry: Map<string, Trigger>,
triggerId: string,
context: { embeddable: IEmbeddable; container?: IContainer }
) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/embeddable_api/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -55,7 +54,7 @@ attachAction(triggerRegistry, {
actionId: editModeAction.id,
});

const embeddableFactories = createRegistry<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory());

test('HelloWorldContainer initializes embeddables', async done => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory());

let container: FilterableContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory());
return new HelloWorldContainer(input, embeddableFactories);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ export class AddPanelFlyout extends React.Component<Props> {
</EuiText>
),
},

...this.props.container.embeddableFactories
.getAll()
...[...this.props.container.embeddableFactories.values()]
.filter(
factory => factory.isEditable() && !factory.isContainerType && factory.canCreateNew()
)
Expand Down Expand Up @@ -147,8 +145,7 @@ export class AddPanelFlyout extends React.Component<Props> {
<SavedObjectFinder
onChoose={this.onAddPanel}
savedObjectMetaData={
this.props.container.embeddableFactories
.getAll()
[...this.props.container.embeddableFactories.values()]
.filter(
embeddableFactory =>
Boolean(embeddableFactory.savedObjectMetaData) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory());
return new HelloWorldContainer(input, embeddableFactories);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(CONTACT_CARD_EMBEDDABLE, new ContactCardEmbeddableFactory());
container = new HelloWorldContainer({ id: '123', panels: {} }, embeddableFactories);
const contactCardEmbeddable = await container.addNewEmbeddable<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory());

let container: FilterableContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddableFactory>();
const embeddableFactories = new Map<string, EmbeddableFactory>();
embeddableFactories.set(FILTERABLE_EMBEDDABLE, new FilterableEmbeddableFactory());

let container: FilterableContainer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -40,7 +39,7 @@ export class FilterableContainer extends Container<

constructor(
initialInput: FilterableContainerInput,
embeddableFactories: IRegistry<EmbeddableFactory>,
embeddableFactories: Map<string, EmbeddableFactory>,
parent?: Container
) {
super(initialInput, { embeddableLoaded: {} }, embeddableFactories, parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -35,7 +34,7 @@ interface InheritedInput {
export class HelloWorldContainer extends Container<InheritedInput> {
public readonly type = HELLO_WORLD_CONTAINER;

constructor(input: ContainerInput, embeddableFactories: IRegistry<EmbeddableFactory>) {
constructor(input: ContainerInput, embeddableFactories: Map<string, EmbeddableFactory>) {
super(input, { embeddableLoaded: {} }, embeddableFactories);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* under the License.
*/

import { IRegistry, Trigger } from '../types';
import { Trigger } from '../types';

export function attachAction(
triggerRegistry: IRegistry<Trigger>,
triggerRegistry: Map<string, Trigger>,
{ triggerId, actionId }: { triggerId: string; actionId: string }
) {
const trigger = triggerRegistry.get(triggerId);
Expand All @@ -31,5 +31,4 @@ export function attachAction(
if (!trigger.actionIds.find(id => id === actionId)) {
trigger.actionIds.push(actionId);
}
triggerRegistry.set(trigger.id, trigger);
}
Loading

0 comments on commit 251142b

Please sign in to comment.