Skip to content

Commit

Permalink
Expose Vis on the contract as it requires visTypes (elastic#56968) (e…
Browse files Browse the repository at this point in the history
…lastic#57753)

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
Dosant and elasticmachine authored Feb 15, 2020
1 parent f71a43d commit 76157e1
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
mergeOtherBucketAggResponse,
updateMissingBucket,
} from '../../buckets/_terms_other_bucket_helper';
import { Vis } from '../../../../../../../core_plugins/visualizations/public';
import { start as visualizationsStart } from '../../../../../../../core_plugins/visualizations/public/np_ready/public/legacy';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

const visConfigSingleTerm = {
Expand Down Expand Up @@ -191,7 +191,7 @@ describe('Terms Agg Other bucket helper', () => {
ngMock.inject(Private => {
const indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);

vis = new Vis(indexPattern, aggConfig);
vis = new visualizationsStart.Vis(indexPattern, aggConfig);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { SharePluginStart } from '../../../../../plugins/share/public';
import { SavedSearch } from './np_ready/types';
import { DocViewsRegistry } from './np_ready/doc_views/doc_views_registry';
import { ChartsPluginStart } from '../../../../../plugins/charts/public';
import { VisualizationsStart } from '../../../visualizations/public';

export interface DiscoverServices {
addBasePath: (path: string) => string;
Expand All @@ -56,6 +57,7 @@ export interface DiscoverServices {
getSavedSearchById: (id: string) => Promise<SavedSearch>;
getSavedSearchUrlById: (id: string) => Promise<string>;
uiSettings: IUiSettingsClient;
visualizations: VisualizationsStart;
}
export async function buildServices(
core: CoreStart,
Expand Down Expand Up @@ -89,5 +91,6 @@ export async function buildServices(
timefilter: plugins.data.query.timefilter.timefilter,
toastNotifications: core.notifications.toasts,
uiSettings: core.uiSettings,
visualizations: plugins.visualizations,
};
}
10 changes: 9 additions & 1 deletion src/legacy/core_plugins/kibana/public/discover/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from 'ui/new_platform';
import { plugin } from './index';
import {
setup as visualizationsSetup,
start as visualizationsStart,
} from '../../../../core_plugins/visualizations/public/np_ready/public/legacy';

// Legacy compatibility part - to be removed at cutover, replaced by a kibana.json file
export const pluginInstance = plugin({} as PluginInitializerContext);
export const setup = pluginInstance.setup(npSetup.core, {
...npSetup.plugins,
visualizations: visualizationsSetup,
});
export const start = pluginInstance.start(npStart.core, {
...npStart.plugins,
visualizations: visualizationsStart,
});
export const start = pluginInstance.start(npStart.core, npStart.plugins);
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import {
ensureDefaultIndexPattern,
registerTimefilterWithGlobalStateFactory,
} from '../../kibana_services';
import { Vis } from '../../../../../visualizations/public';

const {
core,
Expand All @@ -71,6 +70,7 @@ const {
timefilter,
toastNotifications,
uiSettings,
visualizations,
} = getServices();

import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs';
Expand Down Expand Up @@ -990,7 +990,10 @@ function discoverController(
},
};

$scope.vis = new Vis($scope.searchSource.getField('index'), visSavedObject.visState);
$scope.vis = new visualizations.Vis(
$scope.searchSource.getField('index'),
visSavedObject.visState
);
visSavedObject.vis = $scope.vis;

$scope.searchSource.onRequestStart((searchSource, options) => {
Expand Down
6 changes: 6 additions & 0 deletions src/legacy/core_plugins/kibana/public/discover/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import { DocViewInput, DocViewInputFn } from './np_ready/doc_views/doc_views_typ
import { DocViewTable } from './np_ready/components/table/table';
import { JsonCodeBlock } from './np_ready/components/json_code_block/json_code_block';
import { HomePublicPluginSetup } from '../../../../../plugins/home/public';
import {
VisualizationsStart,
VisualizationsSetup,
} from '../../../visualizations/public/np_ready/public';

/**
* These are the interfaces with your public contracts. You should export these
Expand All @@ -51,6 +55,7 @@ export interface DiscoverSetupPlugins {
embeddable: IEmbeddableSetup;
kibanaLegacy: KibanaLegacySetup;
home: HomePublicPluginSetup;
visualizations: VisualizationsSetup;
}
export interface DiscoverStartPlugins {
uiActions: UiActionsStart;
Expand All @@ -60,6 +65,7 @@ export interface DiscoverStartPlugins {
data: DataPublicPluginStart;
share: SharePluginStart;
inspector: any;
visualizations: VisualizationsStart;
}
const innerAngularName = 'app/discover';
const embeddableAngularName = 'app/discoverEmbeddable';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import afterdatachangePng from './afterdatachange.png';
import afterdatachangeandresizePng from './afterdatachangeandresize.png';
import aftercolorchangePng from './aftercolorchange.png';
import changestartupPng from './changestartup.png';
import { setup as visualizationsSetup } from '../../../visualizations/public/np_ready/public/legacy';
import { Vis } from '../../../visualizations/public/np_ready/public/vis';
import {
setup as visualizationsSetup,
start as visualizationsStart,
} from '../../../visualizations/public/np_ready/public/legacy';

import { createRegionMapVisualization } from '../region_map_visualization';
import { createRegionMapTypeDefinition } from '../region_map_type';
Expand Down Expand Up @@ -158,7 +160,7 @@ describe('RegionMapsVisualizationTests', function() {

imageComparator = new ImageComparator();

vis = new Vis(indexPattern, {
vis = new visualizationsStart.Vis(indexPattern, {
type: 'region_map',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import EMS_TILES from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_
import EMS_STYLE_ROAD_MAP_BRIGHT from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_bright';
import EMS_STYLE_ROAD_MAP_DESATURATED from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_desaturated';
import EMS_STYLE_DARK_MAP from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_style_dark';
import { setup as visualizationsSetup } from '../../../visualizations/public/np_ready/public/legacy';
import { Vis } from '../../../visualizations/public/np_ready/public/vis';
import {
setup as visualizationsSetup,
start as visualizationsStart,
} from '../../../visualizations/public/np_ready/public/legacy';

import { createTileMapVisualization } from '../tile_map_visualization';
import { createTileMapTypeDefinition } from '../tile_map_type';
Expand Down Expand Up @@ -124,7 +126,7 @@ describe('CoordinateMapsVisualizationTest', function() {
setupDOM('512px', '512px');

imageComparator = new ImageComparator();
vis = new Vis(indexPattern, {
vis = new visualizationsStart.Vis(indexPattern, {
type: 'tile_map',
});
vis.params = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('metric_vis - createMetricVisTypeDefinition', () => {

// TODO: remove when Vis is converted to typescript. Only importing Vis as type
// @ts-ignore
vis = new Vis(stubIndexPattern, {
vis = new visualizationsStart.Vis(stubIndexPattern, {
type: 'metric',
aggs: [{ id: '1', type: 'top_hits', schema: 'metric', params: { field: 'ip' } }],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import sinon from 'sinon';
import { tabifyAggResponse, npStart } from '../../legacy_imports';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { round } from 'lodash';

import { Vis } from '../../../../visualizations/public';
import { tableVisTypeDefinition } from '../../table_vis_type';
import { setup as visualizationsSetup } from '../../../../visualizations/public/np_ready/public/legacy';
import {
setup as visualizationsSetup,
start as visualizationsStart,
} from '../../../../visualizations/public/np_ready/public/legacy';
import { getAngularModule } from '../../get_inner_angular';
import { initTableVisLegacyModule } from '../../table_vis_legacy_module';
import { tableVisResponseHandler } from '../../table_vis_response_handler';
Expand All @@ -42,10 +43,10 @@ describe('Table Vis - AggTable Directive', function() {
const tabifiedData = {};

const init = () => {
const vis1 = new Vis(indexPattern, 'table');
const vis1 = new visualizationsStart.Vis(indexPattern, 'table');
tabifiedData.metricOnly = tabifyAggResponse(vis1.aggs, fixtures.metricOnly);

const vis2 = new Vis(indexPattern, {
const vis2 = new visualizationsStart.Vis(indexPattern, {
type: 'table',
params: {
showMetricsAtAllLevels: true,
Expand All @@ -64,7 +65,7 @@ describe('Table Vis - AggTable Directive', function() {
metricsAtAllLevels: true,
});

const vis3 = new Vis(indexPattern, {
const vis3 = new visualizationsStart.Vis(indexPattern, {
type: 'table',
aggs: [
{ type: 'avg', schema: 'metric', params: { field: 'bytes' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import expect from '@kbn/expect';
import fixtures from 'fixtures/fake_hierarchical_data';
import { tabifyAggResponse, npStart } from '../../legacy_imports';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { Vis } from '../../../../visualizations/public';
import { getAngularModule } from '../../get_inner_angular';
import { initTableVisLegacyModule } from '../../table_vis_legacy_module';
import { tableVisResponseHandler } from '../../table_vis_response_handler';
import { start as visualizationsStart } from '../../../../visualizations/public/np_ready/public/legacy';

describe('Table Vis - AggTableGroup Directive', function() {
let $rootScope;
Expand All @@ -35,10 +35,10 @@ describe('Table Vis - AggTableGroup Directive', function() {
const tabifiedData = {};

const init = () => {
const vis1 = new Vis(indexPattern, 'table');
const vis1 = new visualizationsStart.Vis(indexPattern, 'table');
tabifiedData.metricOnly = tabifyAggResponse(vis1.aggs, fixtures.metricOnly);

const vis2 = new Vis(indexPattern, {
const vis2 = new visualizationsStart.Vis(indexPattern, {
type: 'pie',
aggs: [
{ type: 'avg', schema: 'metric', params: { field: 'bytes' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import { Vis } from '../../../../visualizations/public/np_ready/public/vis';
import { start as visualizationsStart } from '../../../../../core_plugins/visualizations/public/np_ready/public/legacy';
import { ImageComparator } from 'test_utils/image_comparator';
import { createTagCloudVisualization } from '../tag_cloud_visualization';
import basicdrawPng from './basicdraw.png';
Expand Down Expand Up @@ -76,7 +76,7 @@ describe('TagCloudVisualizationTest', function() {
beforeEach(async function() {
setupDOM('512px', '512px');
imageComparator = new ImageComparator();
vis = new Vis(indexPattern, {
vis = new visualizationsStart.Vis(indexPattern, {
type: 'tagcloud',
params: {
bucket: { accessor: 0, format: {} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import ngMock from 'ng_mock';
import $ from 'jquery';
import { createVegaVisualization } from '../vega_visualization';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import { Vis } from '../../../visualizations/public/np_ready/public/vis';
import { ImageComparator } from 'test_utils/image_comparator';

import vegaliteGraph from '!!raw-loader!./vegalite_graph.hjson';
Expand All @@ -41,7 +40,10 @@ import vegaMapImage256 from './vega_map_image_256.png';
import { VegaParser } from '../data_model/vega_parser';
import { SearchCache } from '../data_model/search_cache';

import { setup as visualizationsSetup } from '../../../visualizations/public/np_ready/public/legacy';
import {
setup as visualizationsSetup,
start as visualizationsStart,
} from '../../../visualizations/public/np_ready/public/legacy';
import { createVegaTypeDefinition } from '../vega_type';
// TODO This is an integration test and thus requires a running platform. When moving to the new platform,
// this test has to be migrated to the newly created integration test environment.
Expand Down Expand Up @@ -106,7 +108,7 @@ describe('VegaVisualizations', () => {
setupDOM('512px', '512px');
imageComparator = new ImageComparator();

vis = new Vis(indexPattern, { type: 'vega' });
vis = new visualizationsStart.Vis(indexPattern, { type: 'vega' });
});

afterEach(function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import expect from '@kbn/expect';
import fixtures from 'fixtures/fake_hierarchical_data';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

import { Vis } from '../../../../../visualizations/public';
import { start as visualizationsStart } from '../../../../../visualizations/public/np_ready/public/legacy';
import { getVis, getMockUiState } from '../lib/fixtures/_vis_fixture';
import { tabifyAggResponse } from '../../../legacy_imports';
import { vislibSlicesResponseHandler } from '../../response_handler';
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('No global chart settings', function() {
responseHandler = vislibSlicesResponseHandler;

let id1 = 1;
stubVis1 = new Vis(indexPattern, {
stubVis1 = new visualizationsStart.Vis(indexPattern, {
type: 'pie',
aggs: rowAgg,
});
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('Vislib PieChart Class Test Suite', function() {
responseHandler = vislibSlicesResponseHandler;

let id = 1;
stubVis = new Vis(indexPattern, {
stubVis = new visualizationsStart.Vis(indexPattern, {
type: 'pie',
aggs: dataAgg,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import _ from 'lodash';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { Vis } from '../..';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { start as visualizations } from '../../legacy';

Expand Down Expand Up @@ -49,7 +48,7 @@ describe('Vis Class', function() {
);

beforeEach(function() {
vis = new Vis(indexPattern, stateFixture);
vis = new visualizations.Vis(indexPattern, stateFixture);
});

const verifyVis = function(vis) {
Expand Down Expand Up @@ -85,7 +84,7 @@ describe('Vis Class', function() {

describe('setState()', function() {
it('should set the state to defaults', function() {
const vis = new Vis(indexPattern);
const vis = new visualizations.Vis(indexPattern);
expect(vis).to.have.property('type');
expect(vis.type).to.eql(visTypes.get('histogram'));
expect(vis).to.have.property('aggs');
Expand All @@ -101,7 +100,7 @@ describe('Vis Class', function() {
expect(vis.isHierarchical()).to.be(true);
});
it('should return false for non-hierarchical vis (like histogram)', function() {
const vis = new Vis(indexPattern);
const vis = new visualizations.Vis(indexPattern);
expect(vis.isHierarchical()).to.be(false);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const createStartContract = (): VisualizationsStart => ({
},
getSavedVisualizationsLoader: jest.fn(),
showNewVisModal: jest.fn(),
Vis: jest.fn(),
});

const createInstance = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
SavedObjectKibanaServicesWithVisualizations,
} from '../../saved_visualizations';
import { SavedVisualizations } from '../../../../kibana/public/visualize/np_ready/types';
import { VisImpl, VisImplConstructor } from './vis_impl';
import { showNewVisModal } from './wizard';
/**
* Interface for this plugin's returned setup/start contracts.
Expand All @@ -57,6 +58,7 @@ export interface VisualizationsStart {
types: TypesStart;
getSavedVisualizationsLoader: () => SavedVisualizations;
showNewVisModal: typeof showNewVisModal;
Vis: VisImplConstructor;
}

export interface VisualizationsSetupDeps {
Expand Down Expand Up @@ -131,6 +133,7 @@ export class VisualizationsPlugin
types,
getSavedVisualizationsLoader: () => this.getSavedVisualizationsLoader(),
showNewVisModal,
Vis: VisImpl,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ export interface VisState {
aggs: IAggConfigs;
}

export declare class VisualizationController {
constructor(element: HTMLElement, vis: Vis);
public render(visData: any, visParams: any, update: { [key in Status]: boolean }): Promise<void>;
public destroy(): void;
public isLoaded?(): Promise<void> | void;
export interface VisualizationController {
render(visData: any, visParams: any, update: { [key in Status]: boolean }): Promise<void>;
destroy(): void;
isLoaded?(): Promise<void> | void;
}
Loading

0 comments on commit 76157e1

Please sign in to comment.