Skip to content

Commit

Permalink
Lens client side shim cleanup (#56976)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Feb 13, 2020
1 parent 717d471 commit 4437858
Show file tree
Hide file tree
Showing 152 changed files with 835 additions and 1,731 deletions.
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/lens/public/app_plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export * from './plugin';
export * from './app';
32 changes: 32 additions & 0 deletions x-pack/legacy/plugins/lens/public/datatable_visualization/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { CoreSetup } from 'src/core/public';
import { datatableVisualization } from './visualization';
import { ExpressionsSetup } from '../../../../../../src/plugins/expressions/public';
import { datatable, datatableColumns, getDatatableRenderer } from './expression';
import { FormatFactory } from '../legacy_imports';
import { EditorFrameSetup } from '../types';

export interface DatatableVisualizationPluginSetupPlugins {
expressions: ExpressionsSetup;
formatFactory: FormatFactory;
editorFrame: EditorFrameSetup;
}

export class DatatableVisualization {
constructor() {}

setup(
_core: CoreSetup | null,
{ expressions, formatFactory, editorFrame }: DatatableVisualizationPluginSetupPlugins
) {
expressions.registerFunction(() => datatableColumns);
expressions.registerFunction(() => datatable);
expressions.registerRenderer(() => getDatatableRenderer(formatFactory));
editorFrame.registerVisualization(datatableVisualization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { createMockDatasource } from '../editor_frame_plugin/mocks';
import { createMockDatasource } from '../editor_frame_service/mocks';
import {
DatatableVisualizationState,
datatableVisualization,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import _ from 'lodash';
import { Chrome } from 'ui/chrome';

import { capabilities } from 'ui/capabilities';
import {
Capabilities,
HttpSetup,
RecursiveReadonly,
SavedObjectsClientContract,
} from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { IndexPatternsContract, IndexPattern } from '../../../../../../../src/plugins/data/public';
import { ReactExpressionRendererType } from '../../../../../../../src/plugins/expressions/public';
Expand All @@ -24,14 +26,12 @@ import { getEditPath } from '../../../../../../plugins/lens/common';
export class EmbeddableFactory extends AbstractEmbeddableFactory {
type = DOC_TYPE;

private chrome: Chrome;
private indexPatternService: IndexPatternsContract;
private expressionRenderer: ReactExpressionRendererType;

constructor(
chrome: Chrome,
expressionRenderer: ReactExpressionRendererType,
indexPatternService: IndexPatternsContract
private coreHttp: HttpSetup,
private capabilities: RecursiveReadonly<Capabilities>,
private savedObjectsClient: SavedObjectsClientContract,
private expressionRenderer: ReactExpressionRendererType,
private indexPatternService: IndexPatternsContract
) {
super({
savedObjectMetaData: {
Expand All @@ -42,13 +42,10 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory {
getIconForSavedObject: () => 'lensApp',
},
});
this.chrome = chrome;
this.expressionRenderer = expressionRenderer;
this.indexPatternService = indexPatternService;
}

public isEditable() {
return capabilities.get().visualize.save as boolean;
return this.capabilities.visualize.save as boolean;
}

canCreateNew() {
Expand All @@ -66,7 +63,7 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory {
input: Partial<EmbeddableInput> & { id: string },
parent?: IContainer
) {
const store = new SavedObjectIndexStore(this.chrome.getSavedObjectsClient());
const store = new SavedObjectIndexStore(this.savedObjectsClient);
const savedVis = await store.load(savedObjectId);

const promises = savedVis.state.datasourceMetaData.filterableIndexPatterns.map(
Expand All @@ -91,7 +88,7 @@ export class EmbeddableFactory extends AbstractEmbeddableFactory {
this.expressionRenderer,
{
savedVis,
editUrl: this.chrome.addBasePath(getEditPath(savedObjectId)),
editUrl: this.coreHttp.basePath.prepend(getEditPath(savedObjectId)),
editable: this.isEditable(),
indexPatterns,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export * from './plugin';
export * from './service';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
KibanaDatatable,
} from 'src/plugins/expressions/public';
import { LensMultiTable } from '../types';
import { toAbsoluteDates } from '../indexpattern_plugin/auto_date';
import { toAbsoluteDates } from '../indexpattern_datasource/auto_date';

interface MergeTables {
layerIds: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import {
ExpressionsSetup,
ExpressionsStart,
} from '../../../../../../src/plugins/expressions/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { embeddablePluginMock } from '../../../../../../src/plugins/embeddable/public/mocks';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { expressionsPluginMock } from '../../../../../../src/plugins/expressions/public/mocks';
import { DatasourcePublicAPI, FramePublicAPI, Datasource, Visualization } from '../types';
import { EditorFrameSetupPlugins, EditorFrameStartPlugins } from './plugin';
import { EditorFrameSetupPlugins, EditorFrameStartPlugins } from './service';

export function createMockVisualization(): jest.Mocked<Visualization> {
return {
Expand Down Expand Up @@ -108,9 +106,6 @@ export function createMockSetupDependencies() {
data: {},
embeddable: embeddablePluginMock.createSetupContract(),
expressions: expressionsPluginMock.createSetupContract(),
chrome: {
getSavedObjectsClient: () => {},
},
} as unknown) as MockedSetupDependencies;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EditorFramePlugin } from './plugin';
import { EditorFrameService } from './service';
import { coreMock } from 'src/core/public/mocks';
import {
MockedSetupDependencies,
Expand All @@ -25,14 +25,14 @@ jest.mock('./embeddable/embeddable_factory', () => ({
EmbeddableFactory: class Mock {},
}));

describe('editor_frame plugin', () => {
let pluginInstance: EditorFramePlugin;
describe('editor_frame service', () => {
let pluginInstance: EditorFrameService;
let mountpoint: Element;
let pluginSetupDependencies: MockedSetupDependencies;
let pluginStartDependencies: MockedStartDependencies;

beforeEach(() => {
pluginInstance = new EditorFramePlugin();
pluginInstance = new EditorFrameService();
mountpoint = document.createElement('div');
pluginSetupDependencies = createMockSetupDependencies();
pluginStartDependencies = createMockStartDependencies();
Expand All @@ -42,26 +42,28 @@ describe('editor_frame plugin', () => {
mountpoint.remove();
});

it('should create an editor frame instance which mounts and unmounts', () => {
expect(() => {
pluginInstance.setup(coreMock.createSetup(), pluginSetupDependencies);
const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies);
const instance = publicAPI.createInstance({});
instance.mount(mountpoint, {
onError: jest.fn(),
onChange: jest.fn(),
dateRange: { fromDate: '', toDate: '' },
query: { query: '', language: 'lucene' },
filters: [],
});
instance.unmount();
}).not.toThrowError();
it('should create an editor frame instance which mounts and unmounts', async () => {
await expect(
(async () => {
pluginInstance.setup(coreMock.createSetup(), pluginSetupDependencies);
const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies);
const instance = await publicAPI.createInstance({});
instance.mount(mountpoint, {
onError: jest.fn(),
onChange: jest.fn(),
dateRange: { fromDate: '', toDate: '' },
query: { query: '', language: 'lucene' },
filters: [],
});
instance.unmount();
})()
).resolves.toBeUndefined();
});

it('should not have child nodes after unmount', () => {
it('should not have child nodes after unmount', async () => {
pluginInstance.setup(coreMock.createSetup(), pluginSetupDependencies);
const publicAPI = pluginInstance.start(coreMock.createStart(), pluginStartDependencies);
const instance = publicAPI.createInstance({});
const instance = await publicAPI.createInstance({});
instance.mount(mountpoint, {
onError: jest.fn(),
onChange: jest.fn(),
Expand Down
Loading

0 comments on commit 4437858

Please sign in to comment.