-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
TypeScript cleanup in visualizations plugin #78428
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,15 @@ | |
* under the License. | ||
*/ | ||
|
||
import { ExpressionAstExpression } from 'src/plugins/expressions'; | ||
import { SavedObject } from '../../../plugins/saved_objects/public'; | ||
import { | ||
AggConfigOptions, | ||
SearchSourceFields, | ||
TimefilterContract, | ||
} from '../../../plugins/data/public'; | ||
import { SerializedVis, Vis, VisParams } from './vis'; | ||
import { ExprVis } from './expressions/vis'; | ||
|
||
export { Vis, SerializedVis, VisParams }; | ||
|
||
|
@@ -35,7 +37,7 @@ export interface VisualizationController { | |
|
||
export type VisualizationControllerConstructor = new ( | ||
el: HTMLElement, | ||
vis: Vis | ||
vis: ExprVis | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ It seems there is currently two very similar Vis classes around |
||
) => VisualizationController; | ||
|
||
export interface SavedVisState { | ||
|
@@ -71,4 +73,7 @@ export interface VisToExpressionAstParams { | |
abortSignal?: AbortSignal; | ||
} | ||
|
||
export type VisToExpressionAst = (vis: Vis, params: VisToExpressionAstParams) => string; | ||
export type VisToExpressionAst = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ This was completely wrongly typed :-) This function was never supposed to return a |
||
vis: Vis, | ||
params: VisToExpressionAstParams | ||
) => ExpressionAstExpression; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ import { VisToExpressionAst, VisualizationControllerConstructor } from '../types | |
import { TriggerContextMapping } from '../../../ui_actions/public'; | ||
import { Adapters } from '../../../inspector/public'; | ||
|
||
export interface BaseVisTypeOptions { | ||
interface CommonBaseVisTypeOptions { | ||
name: string; | ||
title: string; | ||
description?: string; | ||
|
@@ -31,7 +31,6 @@ export interface BaseVisTypeOptions { | |
image?: string; | ||
stage?: 'experimental' | 'beta' | 'production'; | ||
options?: Record<string, any>; | ||
visualization: VisualizationControllerConstructor | undefined; | ||
visConfig?: Record<string, any>; | ||
editor?: any; | ||
editorConfig?: Record<string, any>; | ||
|
@@ -42,9 +41,20 @@ export interface BaseVisTypeOptions { | |
setup?: unknown; | ||
useCustomNoDataScreen?: boolean; | ||
inspectorAdapters?: Adapters | (() => Adapters); | ||
toExpressionAst?: VisToExpressionAst; | ||
} | ||
|
||
interface ExpressionBaseVisTypeOptions extends CommonBaseVisTypeOptions { | ||
toExpressionAst: VisToExpressionAst; | ||
visualization?: undefined; | ||
} | ||
|
||
interface VisualizationBaseVisTypeOptions extends CommonBaseVisTypeOptions { | ||
toExpressionAst?: undefined; | ||
visualization: VisualizationControllerConstructor | undefined; | ||
} | ||
|
||
export type BaseVisTypeOptions = ExpressionBaseVisTypeOptions | VisualizationBaseVisTypeOptions; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Properly splitted this up into two types. It either needs to have a |
||
|
||
export class BaseVisType { | ||
name: string; | ||
title: string; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,8 @@ | |
|
||
import { IconType } from '@elastic/eui'; | ||
import { visTypeAliasRegistry, VisTypeAlias } from './vis_type_alias_registry'; | ||
// @ts-ignore | ||
import { BaseVisType } from './base_vis_type'; | ||
// @ts-ignore | ||
import { ReactVisType } from './react_vis_type'; | ||
import { BaseVisType, BaseVisTypeOptions } from './base_vis_type'; | ||
import { ReactVisType, ReactVisTypeOptions } from './react_vis_type'; | ||
import { TriggerContextMapping } from '../../../ui_actions/public'; | ||
|
||
export interface VisType { | ||
|
@@ -71,17 +69,17 @@ export class TypesService { | |
return { | ||
/** | ||
* registers a visualization type | ||
* @param {VisType} config - visualization type definition | ||
* @param config - visualization type definition | ||
*/ | ||
createBaseVisualization: (config: any) => { | ||
createBaseVisualization: (config: BaseVisTypeOptions): void => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ This is the most important part of this PR, since it finally puts the proper typings for the visualization registry into the public API we expose. |
||
const vis = new BaseVisType(config); | ||
registerVisualization(() => vis); | ||
}, | ||
/** | ||
* registers a visualization which uses react for rendering | ||
* @param {VisType} config - visualization type definition | ||
* @param config - visualization type definition | ||
*/ | ||
createReactVisualization: (config: any) => { | ||
createReactVisualization: (config: ReactVisTypeOptions): void => { | ||
const vis = new ReactVisType(config); | ||
registerVisualization(() => vis); | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Since the type is propertly passed through now, this is colling with Visualizatins
isLoaded()
function, so I rename this for now.