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

Restructure vis plugin & export types contracts #43730

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { FiltersService, FiltersSetup } from './filters_service';
export * from './filters_service';
49 changes: 11 additions & 38 deletions src/legacy/core_plugins/visualizations/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,28 @@
* under the License.
*/

import { FiltersService, FiltersSetup } from './filters';
import { TypesService, TypesSetup } from './types';
import { VisualizationsPlugin as Plugin, VisualizationsSetup } from './plugin';

class VisualizationsPlugin {
private readonly filters: FiltersService;
private readonly types: TypesService;

constructor() {
this.filters = new FiltersService();
this.types = new TypesService();
}

public setup() {
return {
filters: this.filters.setup(),
types: this.types.setup(),
};
}

public stop() {
this.filters.stop();
this.types.stop();
}
export function plugin() {
return new Plugin();
}

/**
* We export visualizations here so that users importing from 'plugins/visualizations'
* will automatically receive the response value of the `setup` contract, mimicking
* the data that will eventually be injected by the new platform.
*/
export const visualizations = new VisualizationsPlugin().setup();

/** @public */
export interface VisualizationsSetup {
filters: FiltersSetup;
types: TypesSetup;
}
// Temporarily included here for BWC during the shimming process
export { setup as visualizations } from './legacy';

/** @public types */
export type VisualizationsSetup = VisualizationsSetup;
export {
Vis,
visFactory,
DefaultEditorSize,
VisParams,
VisProvider,
VisState,
// VisualizationController,
// VisType,
VisType,
VisTypeAlias,
VisTypesRegistry,
VisualizationController,
Status,
} from './types';

/** @public static code */
export { DefaultEditorSize, defaultFeedbackMessage, visFactory } from './types';
42 changes: 42 additions & 0 deletions src/legacy/core_plugins/visualizations/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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/visualizations/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';
import { plugin } from '.';

const visualizationsPlugin = plugin();

export const setup = visualizationsPlugin.setup(npSetup.core, {});
73 changes: 73 additions & 0 deletions src/legacy/core_plugins/visualizations/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { Plugin, CoreSetup, CoreStart } from '../../../../core/public';
import { FiltersService, FiltersSetup } from './filters';
import { TypesService, TypesSetup } from './types';

/**
* Interface for any dependencies on other plugins' `setup` contracts.
*
* @internal
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface VisualizationsPluginSetupDependencies {}

/**
* Interface for this plugin's returned `setup` contract.
*
* @public
*/
export interface VisualizationsSetup {
filters: FiltersSetup;
types: TypesSetup;
}

/**
* Visualizations 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 VisualizationsPlugin
implements Plugin<VisualizationsSetup, void, VisualizationsPluginSetupDependencies> {
private readonly filters: FiltersService = new FiltersService();
private readonly types: TypesService = new TypesService();

public setup(core: CoreSetup, { }: VisualizationsPluginSetupDependencies): VisualizationsSetup {
return {
filters: this.filters.setup(),
types: this.types.setup(),
};
}

public start(core: CoreStart) {
// nothing to do here yet
}

public stop() {
this.filters.stop();
this.types.stop();
}
}
17 changes: 1 addition & 16 deletions src/legacy/core_plugins/visualizations/public/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,4 @@
* under the License.
*/

export {
TypesService,
visFactory,
DefaultEditorSize,
// types
TypesSetup,
Vis,
VisParams,
VisProvider,
VisState,
// VisualizationController,
// VisType,
VisTypeAlias,
VisTypesRegistry,
Status,
} from './types_service';
export * from './types_service';
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
*/

// @ts-ignore
import { defaultFeedbackMessage } from 'ui/vis/default_feedback_message';
import { VisProvider } from 'ui/vis/index.js';
// @ts-ignore
import { VisProvider as Vis } from 'ui/vis/index.js';
// @ts-ignore
import { VisFactoryProvider, visFactory } from 'ui/vis/vis_factory';
// @ts-ignore
import { DefaultEditorSize } from 'ui/vis/editor_size';
import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
// @ts-ignore
import { VisFactoryProvider } from 'ui/vis/vis_factory';
import * as types from 'ui/vis/vis';

import { visTypeAliasRegistry, VisTypeAlias } from './vis_type_alias_registry';
Expand All @@ -38,11 +35,12 @@ import { visTypeAliasRegistry, VisTypeAlias } from './vis_type_alias_registry';
export class TypesService {
public setup() {
return {
Vis,
VisFactoryProvider,
VisProvider,
VisTypesRegistryProvider,
defaultFeedbackMessage, // make default in base vis type, or move?
visTypeAliasRegistry,
__LEGACY: {
VisFactoryProvider,
},
};
}

Expand All @@ -51,17 +49,21 @@ export class TypesService {
}
}

/** @public */
export type TypesSetup = ReturnType<TypesService['setup']>;

export { visFactory, DefaultEditorSize };

/** @public types */
export type TypesSetup = ReturnType<TypesService['setup']>;
export type VisTypeAlias = VisTypeAlias;
export type Vis = types.Vis;
export type VisParams = types.VisParams;
export type VisProvider = types.VisProvider;
export type VisState = types.VisState;
// todo: this breaks it // export { VisualizationController, VisType } from 'ui/vis/vis_types/vis_type';
export { VisualizationController, VisType } from 'ui/vis/vis_types/vis_type';
export { VisTypesRegistry } from 'ui/registry/vis_types';
export { Status } from 'ui/vis/update_status';

/** @public static code */
// @ts-ignore
export { DefaultEditorSize } from 'ui/vis/editor_size';
// @ts-ignore Used only by tsvb, vega, input control vis
export { defaultFeedbackMessage } from 'ui/vis/default_feedback_message';
// @ts-ignore
export { visFactory } from 'ui/vis/vis_factory';