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

Shape data plugin into standard shim form #42238

Merged
merged 17 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

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

export { ApplyFiltersPopover } from './apply_filters_popover';

// @ts-ignore
export { setupDirective } from './directive';
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,4 @@
* under the License.
*/

import './directive';

export { FilterBar } from './filter_bar';

// @ts-ignore
export { setupDirective } from './directive';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { mapMatchAll } from '../map_match_all';

describe('ui/filter_manager/lib', function () {
describe('filter_manager/lib', function () {
describe('mapMatchAll()', function () {
let filter;

Expand Down
11 changes: 0 additions & 11 deletions src/legacy/core_plugins/data/public/filter/filter_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
* under the License.
*/

import { once } from 'lodash';
import { FilterBar, setupDirective as setupFilterBarDirective } from './filter_bar';
import { ApplyFiltersPopover, setupDirective as setupApplyFiltersDirective } from './apply_filters';
import { IndexPatterns } from '../index_patterns';
import { FilterManager } from './filter_manager';
/**
Expand All @@ -37,14 +34,6 @@ export class FilterService {

return {
filterManager,
ui: {
ApplyFiltersPopover,
FilterBar,
},
loadLegacyDirectives: once(() => {
setupFilterBarDirective();
setupApplyFiltersDirective();
}),
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/data/public/filter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
export { FilterService, FilterSetup } from './filter_service';

export { FilterBar } from './filter_bar';

export { ApplyFiltersPopover } from './apply_filters';
68 changes: 8 additions & 60 deletions src/legacy/core_plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,74 +17,22 @@
* under the License.
*/

// TODO these are imports from the old plugin world.
// Once the new platform is ready, they can get removed
// and handled by the platform itself in the setup method
// of the ExpressionExectorService
// @ts-ignore
import { renderersRegistry } from 'plugins/interpreter/registries';
import { ExpressionsService, ExpressionsSetup } from './expressions';
import { QueryService, QuerySetup } from './query';
import { FilterService, FilterSetup } from './filter';
import { IndexPatternsService, IndexPatternsSetup } from './index_patterns';
// /// Define plugin function
import { DataPlugin as Plugin } from './plugin';

export class DataPlugin {
// Exposed services, sorted alphabetically
private readonly expressions: ExpressionsService;
private readonly filter: FilterService;
private readonly indexPatterns: IndexPatternsService;
private readonly query: QueryService;

constructor() {
this.indexPatterns = new IndexPatternsService();
this.filter = new FilterService();
this.query = new QueryService();
this.expressions = new ExpressionsService();
}

public setup(): DataSetup {
// TODO: this is imported here to avoid circular imports.
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { getInterpreter } = require('plugins/interpreter/interpreter');
const indexPatternsService = this.indexPatterns.setup();
return {
expressions: this.expressions.setup({
interpreter: {
getInterpreter,
renderersRegistry,
},
}),
indexPatterns: indexPatternsService,
filter: this.filter.setup({
indexPatterns: indexPatternsService.indexPatterns,
}),
query: this.query.setup(),
};
}

public stop() {
this.expressions.stop();
this.indexPatterns.stop();
this.filter.stop();
this.query.stop();
}
export function plugin() {
return new Plugin();
}

/** @public */
export interface DataSetup {
expressions: ExpressionsSetup;
indexPatterns: IndexPatternsSetup;
filter: FilterSetup;
query: QuerySetup;
}
// /// Export types & static code

/** @public types */
export { ExpressionRenderer, ExpressionRendererProps, ExpressionRunner } from './expressions';

/** @public types */
export { IndexPattern, StaticIndexPattern, Field } from './index_patterns';
export { Query, QueryBar } from './query';
export { FilterBar } from './filter';
export { IndexPattern, IndexPatterns, StaticIndexPattern, Field } from './index_patterns';
export { Query, QueryBar, QueryBarInput } from './query';
export { FilterBar, ApplyFiltersPopover } from './filter';
export {
FilterManager,
FilterStateManager,
Expand Down
54 changes: 54 additions & 0 deletions src/legacy/core_plugins/data/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
* New Platform Shim
*
* In this file, we import any legacy dependencies we have, and shim them into
* our plugin by manually constructing the values that the new platform will
* eventually be passing to the `setup` method of our plugin definition.
*
* The idea is that our `plugin.ts` can stay "pure" and not contain any legacy
* world code. Then when it comes time to migrate to the new platform, we can
* simply delete this shim file.
*
* We are also calling `setup` here and exporting our public contract so that
* other legacy plugins are able to import from '../core_plugins/data/legacy'
* and receive the response value of the `setup` contract, mimicking the
* data that will eventually be injected by the new platform.
*/

import { npSetup } from 'ui/new_platform';
// @ts-ignore
import { renderersRegistry } from 'plugins/interpreter/registries';
// @ts-ignore
import { getInterpreter } from 'plugins/interpreter/interpreter';
import { LegacyDependenciesPlugin } from './shim/legacy_dependencies_plugin';
import { plugin } from '.';

const dataPlugin = plugin();
const legacyPlugin = new LegacyDependenciesPlugin();

export const setup = dataPlugin.setup(npSetup.core, {
__LEGACY: legacyPlugin.setup(),
interpreter: {
renderersRegistry,
getInterpreter,
},
});
89 changes: 89 additions & 0 deletions src/legacy/core_plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { CoreSetup, CoreStart, Plugin } from '../../../../core/public';
import { ExpressionsService, ExpressionsSetup } from './expressions';
import { QueryService, QuerySetup } from './query';
import { FilterService, FilterSetup } from './filter';
import { IndexPatternsService, IndexPatternsSetup } from './index_patterns';
import { LegacyDependenciesPluginSetup } from './shim/legacy_dependencies_plugin';

/**
* Interface for any dependencies on other plugins' `setup` contracts.
*
* @internal
*/
export interface DataPluginSetupDependencies {
__LEGACY: LegacyDependenciesPluginSetup;
interpreter: any;
}

/**
* Interface for this plugin's returned `setup` contract.
*
* @public
*/
export interface DataSetup {
expressions: ExpressionsSetup;
indexPatterns: IndexPatternsSetup;
filter: FilterSetup;
query: QuerySetup;
}

/**
* Data Plugin - public
*
* This is the entry point for the entire client-side public contract of the plugin.
* If something is not explicitly exported here, you can safely assume it is private
* to the plugin and not considered stable.
*
* All stateful contracts will be injected by the platform at runtime, and are defined
* in the setup/start interfaces. The remaining items exported here are either types,
* or static code.
*/
export class DataPlugin implements Plugin<DataSetup, void, DataPluginSetupDependencies> {
// Exposed services, sorted alphabetically
private readonly expressions: ExpressionsService = new ExpressionsService();
private readonly filter: FilterService = new FilterService();
private readonly indexPatterns: IndexPatternsService = new IndexPatternsService();
private readonly query: QueryService = new QueryService();

public setup(core: CoreSetup, { __LEGACY, interpreter }: DataPluginSetupDependencies): DataSetup {
const indexPatternsService = this.indexPatterns.setup();
return {
expressions: this.expressions.setup({
interpreter,
}),
indexPatterns: indexPatternsService,
filter: this.filter.setup({
indexPatterns: indexPatternsService.indexPatterns,
}),
query: this.query.setup(),
};
}

public start(core: CoreStart) {}

public stop() {
this.expressions.stop();
this.indexPatterns.stop();
this.filter.stop();
this.query.stop();
}
}
8 changes: 2 additions & 6 deletions src/legacy/core_plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { QueryBar, QueryBarInput, fromUser, toUser, getQueryLog } from './query_bar';
import { fromUser, toUser, getQueryLog } from './query_bar';

/**
* Query Service
Expand All @@ -32,10 +32,6 @@ export class QueryService {
toUser,
getQueryLog,
},
ui: {
QueryBar,
QueryBarInput,
},
};
}

Expand All @@ -47,4 +43,4 @@ export class QueryService {
/** @public */
export type QuerySetup = ReturnType<QueryService['setup']>;

export { Query, QueryBar } from './query_bar';
export { Query, QueryBar, QueryBarInput } from './query_bar';
10 changes: 3 additions & 7 deletions src/legacy/core_plugins/data/public/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
* under the License.
*/

import { DataPlugin } from './index';
import { setup } from './legacy';

/**
* We export data here so that users importing from 'plugins/data'
* will automatically receive the response value of the `setup` contract, mimicking
* the data that will eventually be injected by the new platform.
*/
export const data = new DataPlugin().setup();
// for backwards compatibility with 7.3
lizozom marked this conversation as resolved.
Show resolved Hide resolved
export const data = setup;
Loading