Skip to content

Commit

Permalink
Embeddables 2 np (#46771) (#46783)
Browse files Browse the repository at this point in the history
* chore: πŸ€– move embeddable_api to NP "embeddable" plugin

* fix: πŸ› fix TypeScript type check errors

* fix: πŸ› fix TypeScript and build errors

* test: πŸ’ fix Jest tests

* fix: πŸ› fix translations

* test: πŸ’ add Mocha mocks

* fix: πŸ› change import syntax from function test sample plugin

* fix: πŸ› revert canvas changes back and leave placeholders

* chore: πŸ€– revert more changes

* chore: πŸ€– revert more changes

* fix: πŸ› fix TypeScript type check errors

* fix: πŸ› fix functional test imports

* fix: πŸ› fix x-pack Jest test importa

* test: πŸ’ fix advanced_ui_actiosn import for tests
  • Loading branch information
streamich authored Sep 27, 2019
1 parent 4bda107 commit e7c15e2
Show file tree
Hide file tree
Showing 146 changed files with 387 additions and 320 deletions.
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dashboardEmbeddableContainer": "src/legacy/core_plugins/dashboard_embeddable_container",
"kbn": "src/legacy/core_plugins/kibana",
"kbnDocViews": "src/legacy/core_plugins/kbn_doc_views",
"embeddableApi": "src/legacy/core_plugins/embeddable_api",
"embeddableApi": "src/plugins/embeddable",
"kbnVislibVisTypes": "src/legacy/core_plugins/kbn_vislib_vis_types",
"visTypeMarkdown": "src/legacy/core_plugins/vis_type_markdown",
"visTypeMetric": "src/legacy/core_plugins/vis_type_metric",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ import { getSampleDashboardInput, getSampleDashboardPanel } from '../test_helper
import {
CONTACT_CARD_EMBEDDABLE,
ContactCardEmbeddableFactory,
} from '../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory';
import {
ContactCardEmbeddable,
ContactCardEmbeddableInput,
ContactCardEmbeddableOutput,
} from '../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable';
} from '../../../../../../embeddable_api/public/np_ready/public/lib/test_samples';
import { DashboardOptions } from '../embeddable/dashboard_container_factory';

const embeddableFactories = new Map<string, EmbeddableFactory>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import { getSampleDashboardInput, getSampleDashboardPanel } from '../test_helper
import {
CONTACT_CARD_EMBEDDABLE,
ContactCardEmbeddableFactory,
} from '../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory';
import {
ContactCardEmbeddableInput,
ContactCardEmbeddable,
ContactCardEmbeddableOutput,
} from '../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable';
} from '../../../../../../embeddable_api/public/np_ready/public/lib/test_samples';

const options: DashboardContainerOptions = {
application: {} as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { getSampleDashboardInput } from '../../test_helpers';
import {
CONTACT_CARD_EMBEDDABLE,
ContactCardEmbeddableFactory,
} from '../../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory';
} from '../../../../../../../embeddable_api/public/np_ready/public/lib/test_samples';
import { KibanaContextProvider } from '../../../../../../../../../plugins/kibana_react/public';

let dashboardContainer: DashboardContainer | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import { DEFAULT_PANEL_HEIGHT, DEFAULT_PANEL_WIDTH } from '../dashboard_constant
import { DashboardPanelState } from '../types';
import { createPanelState } from './create_panel_state';
import { EmbeddableInput } from '../../embeddable_api';
import { CONTACT_CARD_EMBEDDABLE } from '../../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { CONTACT_CARD_EMBEDDABLE } from '../../../../../../../embeddable_api/public/np_ready/public/lib/test_samples';

interface TestInput extends EmbeddableInput {
test: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { getSampleDashboardInput } from '../../test_helpers';
import {
CONTACT_CARD_EMBEDDABLE,
ContactCardEmbeddableFactory,
} from '../../../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory';
} from '../../../../../../../embeddable_api/public/np_ready/public/lib/test_samples';
import { KibanaContextProvider } from '../../../../../../../../../plugins/kibana_react/public';

let dashboardContainer: DashboardContainer | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import { getSampleDashboardInput } from '../lib/test_helpers';
import {
CONTACT_CARD_EMBEDDABLE,
ContactCardEmbeddableFactory,
} from '../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable_factory';
} from '../../../../../embeddable_api/public/np_ready/public/lib/test_samples';
import {
ContactCardEmbeddableInput,
ContactCardEmbeddable,
ContactCardEmbeddableOutput,
} from '../../../../../embeddable_api/public/np_ready/public/lib/test_samples/embeddables/contact_card/contact_card_embeddable';
} from '../../../../../embeddable_api/public/np_ready/public/lib/test_samples';
import { embeddablePluginMock } from '../../../../../embeddable_api/public/np_ready/public/mocks';
import { createEditModeAction } from '../../../../../embeddable_api/public/np_ready/public/lib/test_samples/actions/edit_mode_action';
import { createEditModeAction } from '../../../../../embeddable_api/public/np_ready/public/lib/test_samples';
// eslint-disable-next-line
import { inspectorPluginMock } from '../../../../../../../plugins/inspector/public/mocks';
import { KibanaContextProvider } from '../../../../../../../plugins/kibana_react/public';
Expand Down
41 changes: 2 additions & 39 deletions src/legacy/core_plugins/embeddable_api/README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,2 @@
# The Embeddable API V2

The Embeddable API's main goal is to have documented and standardized ways to share and exchange information and functionality across applications and plugins.

There are three main pieces of this infrastructure:
- Embeddables & Containers
- Actions
- Triggers

## Embeddables & Containers

Embeddables are isolated, serializable, renderable widgets. A developer can hard code an embeddable inside their
application, or they can use some built in actions to allow users to dynamically add them to *containers*.

Containers are a special type of embeddable that can contain nested embeddables.

## Actions

Actions are pluggable pieces of functionality exposed to the user that take an embeddable as context, plus an optional action context.

## Triggers

Triggers are the way actions are connected to a user action. We ship with two default triggers, `CONTEXT_MENU_TRIGGER` and `APPLY_FILTER`.

Actions attached to the `CONTEXT_MENU_TRIGGER` will be displayed in supported embeddables context menu to the user. Actions attached to the `APPLY_FILTER` trigger will show up when any embeddable emits this trigger.

A developer can register new triggers that their embeddables, or external components, can emit (as long as they have an embeddable to pass along as context).

## Examples

Many examples can be viewed in the functionally tested `kbn_tp_embeddable_explorer` plugin, as well as the jest tested classes inside the `embeddable_api/public/test_samples` folder.

## Testing

Run unit tests

```shell
node scripts/jest embeddable_api
```
- Embeddables have been moved to `/src/plugins/embeddable` NP plugin.
- This legacy plugin is still there to make necessary CSS working, but soon will be completely deleted.
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/embeddable_api/public/index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import 'src/legacy/ui/public/styles/styling_constants';

@import './variables';
@import './np_ready/public/lib/panel/index';
@import './np_ready/public/lib/panel/panel_header/index';
@import '../../../../plugins/embeddable/public/lib/panel/index';
@import '../../../../plugins/embeddable/public/lib/panel/panel_header/index';
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,4 @@
* under the License.
*/

import { PluginInitializerContext } from 'src/core/public';
import { EmbeddablePublicPlugin } from './plugin';

export {
ADD_PANEL_ACTION_ID,
APPLY_FILTER_ACTION,
APPLY_FILTER_TRIGGER,
PANEL_BADGE_TRIGGER,
Adapters,
AddPanelAction,
CONTEXT_MENU_TRIGGER,
Container,
ContainerInput,
ContainerOutput,
EDIT_PANEL_ACTION_ID,
EditPanelAction,
Embeddable,
EmbeddableChildPanel,
EmbeddableChildPanelProps,
EmbeddableFactory,
EmbeddableFactoryNotFoundError,
EmbeddableInput,
EmbeddableInstanceConfiguration,
EmbeddableOutput,
EmbeddablePanel,
ErrorEmbeddable,
GetEmbeddableFactories,
GetEmbeddableFactory,
IContainer,
IEmbeddable,
OutputSpec,
PanelNotFoundError,
PanelState,
PropertySpec,
SavedObjectMetaData,
ViewMode,
isErrorEmbeddable,
openAddPanelFlyout,
} from './lib';

export function plugin(initializerContext: PluginInitializerContext) {
return new EmbeddablePublicPlugin(initializerContext);
}

export { EmbeddablePublicPlugin as Plugin };
export * from './plugin';
export * from '../../../../../../plugins/embeddable/public';
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
* under the License.
*/

/* eslint-disable @kbn/eslint/no-restricted-paths */
// eslint-disable-next-line
import { npSetup, npStart } from 'ui/new_platform';
/* eslint-enable @kbn/eslint/no-restricted-paths */

import { plugin } from '.';

const pluginInstance = plugin({} as any);
export const setup = pluginInstance.setup(npSetup.core, { uiActions: npSetup.plugins.uiActions });
export const start = pluginInstance.start(npStart.core);
export const setup = npSetup.plugins.embeddable;
export const start = npStart.plugins.embeddable;
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export * from './actions';
export * from './embeddables';
// eslint-disable-next-line
export * from '../../../../../../../../plugins/embeddable/public/lib/test_samples';
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,5 @@
* under the License.
*/

import { Plugin } from '.';
import { coreMock } from '../../../../../../core/public/mocks';

// eslint-disable-next-line
import { uiActionsPluginMock } from '../../../../../../plugins/ui_actions/public/mocks';

export type Setup = jest.Mocked<ReturnType<Plugin['setup']>>;
export type Start = jest.Mocked<ReturnType<Plugin['start']>>;

const createSetupContract = (): Setup => {
const setupContract: Setup = {
registerEmbeddableFactory: jest.fn(),
};
return setupContract;
};

const createStartContract = (): Start => {
const startContract: Start = {
registerEmbeddableFactory: jest.fn(),
getEmbeddableFactories: jest.fn(),
getEmbeddableFactory: jest.fn(),
};
return startContract;
};

const createInstance = () => {
const plugin = new Plugin({} as any);
const setup = plugin.setup(coreMock.createSetup(), {
uiActions: uiActionsPluginMock.createSetupContract(),
});
const doStart = () => plugin.start(coreMock.createStart());
return {
plugin,
setup,
doStart,
};
};

export const embeddablePluginMock = {
createSetupContract,
createStartContract,
createInstance,
};
export * from '../../../../../../plugins/embeddable/public/mocks';
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getAppStateMock, getSavedDashboardMock } from './__tests__';
import { AppStateClass } from 'ui/state_management/app_state';
import { DashboardAppState } from './types';
import { TimeRange } from 'src/plugins/data/public';
import { ViewMode } from '../../../embeddable_api/public/np_ready/public';
import { ViewMode } from 'src/plugins/embeddable/public';
import { InputTimeRange } from 'ui/timefilter';

jest.mock('ui/registry/field_formats', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { migrateLegacyQuery } from 'ui/utils/migrate_legacy_query';
import { Moment } from 'moment';

import { DashboardContainer } from 'src/legacy/core_plugins/dashboard_embeddable_container/public/np_ready/public';
import { ViewMode } from '../../../embeddable_api/public/np_ready/public';
import { ViewMode } from '../../../../../../src/plugins/embeddable/public';
import { Query } from '../../../data/public';

import { getAppStateDefaults, migrateAppState } from './lib';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ViewMode } from '../../../embeddable_api/public/np_ready/public';
import { ViewMode } from '../../../../../../src/plugins/embeddable/public';

/**
* @param title {string} the current title of the dashboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { ViewMode } from '../../../../embeddable_api/public/np_ready/public';
import { ViewMode } from '../../../../../../../src/plugins/embeddable/public';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';
import { DashboardAppStateDefaults } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ViewMode } from '../../../../embeddable_api/public/np_ready/public';
import { ViewMode } from '../../../../../../plugins/embeddable/public';
import { TopNavIds } from './top_nav_ids';
import { NavAction } from '../types';

Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { AppState } from 'ui/state_management/app_state';
import { Filter } from '@kbn/es-query';
import { Query } from 'src/legacy/core_plugins/data/public';
import { AppState as TAppState } from 'ui/state_management/app_state';
import { ViewMode } from 'src/legacy/core_plugins/embeddable_api/public/np_ready/public';
import { ViewMode } from 'src/plugins/embeddable/public';
import {
RawSavedDashboardPanelTo60,
RawSavedDashboardPanel610,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import '../doc_table';
import { capabilities } from 'ui/capabilities';
import { npStart } from 'ui/new_platform';
import { npStart, npSetup } from 'ui/new_platform';
import { i18n } from '@kbn/i18n';
import chrome from 'ui/chrome';
import { IPrivate } from 'ui/private';
Expand All @@ -30,8 +30,7 @@ import {
EmbeddableFactory,
ErrorEmbeddable,
Container,
} from '../../../../embeddable_api/public/np_ready/public';
import { setup } from '../../../../embeddable_api/public/np_ready/public/legacy';
} from '../../../../../../plugins/embeddable/public';
import { SavedSearchLoader } from '../types';
import { SearchEmbeddable, SEARCH_EMBEDDABLE_TYPE } from './search_embeddable';
import { SearchInput, SearchOutput } from './types';
Expand Down Expand Up @@ -112,4 +111,4 @@ export class SearchEmbeddableFactory extends EmbeddableFactory<
}

const factory = new SearchEmbeddableFactory(npStart.plugins.uiActions.executeTriggerActions);
setup.registerEmbeddableFactory(factory.type, factory);
npSetup.plugins.embeddable.registerEmbeddableFactory(factory.type, factory);
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ import { StaticIndexPattern } from 'ui/index_patterns';
import { TimeRange } from 'src/plugins/data/public';
import { Query } from 'src/legacy/core_plugins/data/public';
import { Filter } from '@kbn/es-query';
import { EmbeddableInput, EmbeddableOutput, IEmbeddable } from 'src/plugins/embeddable/public';
import { SavedSearch } from '../types';
import {
EmbeddableInput,
EmbeddableOutput,
IEmbeddable,
} from '../../../../embeddable_api/public/np_ready/public';
import { SortOrder } from '../doc_table/components/table_header/helpers';

export interface SearchInput extends EmbeddableInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { Embeddable, EmbeddableOutput } from '../../../../embeddable_api/public/np_ready/public';
import { Embeddable, EmbeddableOutput } from '../../../../../../plugins/embeddable/public';
import { DisabledLabVisualization } from './disabled_lab_visualization';
import { VisualizeInput } from './visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import {
} from 'ui/visualize/loader/types';
import { Subscription } from 'rxjs';
import * as Rx from 'rxjs';
import { TimeRange } from 'src/plugins/data/public';
import { Filter } from '@kbn/es-query';
import { TimeRange } from '../../../../../../plugins/data/public';
import {
EmbeddableInput,
EmbeddableOutput,
Embeddable,
Container,
} from '../../../../embeddable_api/public/np_ready/public';
} from '../../../../../../plugins/embeddable/public';
import { Query, onlyDisabledFiltersChanged } from '../../../../data/public';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';

Expand Down
Loading

0 comments on commit e7c15e2

Please sign in to comment.