Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Common Registry interface #39059

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,7 @@
export { Action, ActionContext } from './action';
export { IncompatibleActionError } from './incompatible_action_error';

import { createRegistry } from '../create_registry';
import { createRegistry } from '../../../../../plugins/kibana_utils/public';
import { Action } from './action';

export const actionRegistry = createRegistry<Action>();
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
import { isErrorEmbeddable, EmbeddableOutput, EmbeddableFactory } from '../embeddables';
import { ContainerInput } from './i_container';
import { ViewMode } from '../types';
import { createRegistry } from '../create_registry';
import { createRegistry } from '../../../../../plugins/kibana_utils/public';
import {
FilterableEmbeddableInput,
FilterableEmbeddable,
Expand Down Expand Up @@ -555,7 +555,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 +678,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 +699,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 +722,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,7 @@ import {
} from '../embeddables';
import { IContainer, ContainerInput, ContainerOutput, PanelState } from './i_container';
import { IEmbeddable } from '../embeddables/i_embeddable';
import { IRegistry } from '../types';
import { Registry } from '../../../../../plugins/kibana_utils/public';
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 +44,14 @@ export abstract class Container<
protected readonly children: {
[key: string]: IEmbeddable<any, any> | ErrorEmbeddable;
} = {};
public readonly embeddableFactories: IRegistry<EmbeddableFactory>;
public readonly embeddableFactories: Registry<EmbeddableFactory>;

private subscription: Subscription;

constructor(
input: TContainerInput,
output: TContainerOutput,
embeddableFactories: IRegistry<EmbeddableFactory>,
embeddableFactories: Registry<EmbeddableFactory>,
parent?: Container
) {
super(input, output, parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
EmbeddableFactory,
} from '../embeddables';
import { IEmbeddable } from '../embeddables/i_embeddable';
import { IRegistry } from '../types';
import { Registry } from '../../../../../plugins/kibana_utils/public';

export interface PanelState<
E extends { [key: string]: unknown } & { id: string } = { [key: string]: unknown } & {
Expand Down Expand Up @@ -59,7 +59,7 @@ export interface IContainer<
I extends ContainerInput = ContainerInput,
O extends ContainerOutput = ContainerOutput
> extends IEmbeddable<I, O> {
readonly embeddableFactories: IRegistry<EmbeddableFactory>;
readonly embeddableFactories: Registry<EmbeddableFactory>;

/**
* Call if you want to wait until an embeddable with that id has finished loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*/

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

export const embeddableFactories = createRegistry<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,7 +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,12 @@
import { Action } from './actions';
import { IEmbeddable } from './embeddables';
import { IContainer } from './containers';
import { IRegistry, Trigger } from './types';
import { Trigger } from './types';
import { Registry } from '../../../../plugins/kibana_utils/public';

export async function getActionsForTrigger(
actionRegistry: IRegistry<Action>,
triggerRegistry: IRegistry<Trigger>,
actionRegistry: Registry<Action>,
triggerRegistry: Registry<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 { Query, TimeRange, ViewMode, QueryLanguageType, Trigger, IRegistry } from './types';
export { Query, TimeRange, ViewMode, QueryLanguageType, 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,7 @@ 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 { createRegistry } from '../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../embeddables';

const editModeAction = new EditModeAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

import { ViewMode, EmbeddableOutput, isErrorEmbeddable } from '../../../../';
import { AddPanelAction } from './add_panel_action';
import { createRegistry } from '../../../../create_registry';
import { createRegistry } from '../../../../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../../../embeddables';
import { Filter, FilterStateStore } from '@kbn/es-query';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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 { createRegistry } from '../../../../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../../../embeddables';

const onClose = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ export class AddPanelFlyout extends React.Component<Props> {
),
},

...this.props.container.embeddableFactories
.getAll()
...[...this.props.container.embeddableFactories.records()]
.filter(
factory => factory.isEditable() && !factory.isContainerType && factory.canCreateNew()
)
Expand Down Expand Up @@ -147,8 +146,7 @@ export class AddPanelFlyout extends React.Component<Props> {
<SavedObjectFinder
onChoose={this.onAddPanel}
savedObjectMetaData={
this.props.container.embeddableFactories
.getAll()
[...this.props.container.embeddableFactories.records()]
.filter(
embeddableFactory =>
Boolean(embeddableFactory.savedObjectMetaData) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ 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 { createRegistry } from '../../../../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../../../embeddables';

let container: Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ 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 { createRegistry } from '../../../../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../../../embeddables';

let container: Container;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
import { EmbeddableOutput, isErrorEmbeddable } from '../../..';
import { InspectPanelAction } from './inspect_panel_action';
import { Inspector, Adapters } from 'ui/inspector';
import { createRegistry } from '../../../create_registry';
import { createRegistry } from '../../../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../../embeddables';
import { Filter, FilterStateStore } from '@kbn/es-query';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

import { EmbeddableOutput, isErrorEmbeddable } from '../../../';
import { RemovePanelAction } from './remove_panel_action';
import { createRegistry } from '../../../create_registry';
import { createRegistry } from '../../../../../../../../src/plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../../embeddables';
import { Filter, FilterStateStore } from '@kbn/es-query';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
import { Filter } from '@kbn/es-query';
import { EmbeddableFactory } from '../../embeddables';
import { IRegistry } from '../../types';
import { Container, ContainerInput } from '../../containers';
import { Registry } from '../../../../../../plugins/kibana_utils/public';

export const FILTERABLE_CONTAINER = 'FILTERABLE_CONTAINER';

Expand All @@ -40,7 +40,7 @@ export class FilterableContainer extends Container<

constructor(
initialInput: FilterableContainerInput,
embeddableFactories: IRegistry<EmbeddableFactory>,
embeddableFactories: Registry<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,7 @@ 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 { Registry } from '../../../../../../plugins/kibana_utils/public';
import { EmbeddableFactory } from '../../embeddables';

export const HELLO_WORLD_CONTAINER = 'HELLO_WORLD_CONTAINER';
Expand All @@ -35,7 +35,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: Registry<EmbeddableFactory>) {
super(input, { embeddableLoaded: {} }, embeddableFactories);
}

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

import { IRegistry, Trigger } from '../types';
import { Trigger } from '../types';
import { Registry } from '../../../../../plugins/kibana_utils/public';

export function attachAction(
triggerRegistry: IRegistry<Trigger>,
triggerRegistry: Registry<Trigger>,
{ triggerId, actionId }: { triggerId: string; actionId: string }
) {
const trigger = triggerRegistry.get(triggerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
* under the License.
*/

import { IRegistry, Trigger } from '../types';
import { Trigger } from '../types';
import { Registry } from '../../../../../plugins/kibana_utils/public';

export function detachAction(
triggerRegistry: IRegistry<Trigger>,
triggerRegistry: Registry<Trigger>,
{ triggerId, actionId }: { triggerId: string; actionId: string }
) {
const trigger = triggerRegistry.get(triggerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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 { createRegistry } from '../../../../../plugins/kibana_utils/public';
import { Trigger } from '../types';

export const triggerRegistry = createRegistry<Trigger>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
9 changes: 0 additions & 9 deletions src/legacy/core_plugins/embeddable_api/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ export interface Trigger {
actionIds: string[];
}

// TODO: use the official base Registry interface when available
export interface IRegistry<T> {
get(id: string): T | undefined;
length(): number;
set(id: string, item: T): void;
reset(): void;
getAll(): T[];
}

export interface PropertySpec {
displayName: string;
accessPath: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from './index_pattern_types';
Loading