diff --git a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.tsx b/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.tsx index 79333ee7f820e..d9f49dc8b7de0 100644 --- a/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.tsx +++ b/x-pack/legacy/plugins/lens/public/datatable_visualization_plugin/visualization.tsx @@ -15,6 +15,7 @@ import { Visualization, VisualizationProps, VisualizationSuggestion, + Operation, } from '../types'; import { generateId } from '../id_generator'; import { NativeRenderer } from '../native_renderer'; @@ -180,7 +181,7 @@ export const datatableVisualization: Visualization< const datasource = frame.datasourceLayers[layer.layerId]; const operations = layer.columns .map(columnId => ({ columnId, operation: datasource.getOperationForColumnId(columnId) })) - .filter(o => o.operation); + .filter((o): o is { columnId: string; operation: Operation } => !!o.operation); return { type: 'expression', @@ -200,7 +201,7 @@ export const datatableVisualization: Visualization< columnIds: operations.map(o => o.columnId), labels: operations.map( o => - o.operation!.label || + o.operation.label || i18n.translate('xpack.lens.datatable.na', { defaultMessage: 'N/A', }) diff --git a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx index 318cff621a9d9..728676b2ea869 100644 --- a/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx +++ b/x-pack/legacy/plugins/lens/public/editor_frame_plugin/embeddable/embeddable.tsx @@ -63,7 +63,7 @@ export class Embeddable extends AbstractEmbeddable = {}; private readonly visualizations: Record = {}; - private createInstance(): EditorFrameInstance { - let domElement: Element; - return { - mount: (element, { doc, onError, dateRange, query, onChange }) => { - domElement = element; - const firstDatasourceId = Object.keys(this.datasources)[0]; - const firstVisualizationId = Object.keys(this.visualizations)[0]; - - render( - - - , - domElement - ); - }, - unmount() { - if (domElement) { - unmountComponentAtNode(domElement); - } - }, - }; - } - public setup(_core: CoreSetup | null, plugins: EditorFrameSetupPlugins): EditorFrameSetup { plugins.interpreter.functionsRegistry.register(() => mergeTables); - this.ExpressionRenderer = plugins.data.expressions.ExpressionRenderer; plugins.embeddables.addEmbeddableFactory( new EmbeddableFactory( plugins.chrome, - this.ExpressionRenderer, + plugins.data.expressions.ExpressionRenderer, plugins.data.indexPatterns.indexPatterns ) ); + const createInstance = (): EditorFrameInstance => { + let domElement: Element; + return { + mount: (element, { doc, onError, dateRange, query, onChange }) => { + domElement = element; + const firstDatasourceId = Object.keys(this.datasources)[0]; + const firstVisualizationId = Object.keys(this.visualizations)[0]; + + render( + + + , + domElement + ); + }, + unmount() { + if (domElement) { + unmountComponentAtNode(domElement); + } + }, + }; + }; + return { - createInstance: this.createInstance.bind(this), + createInstance, registerDatasource: (name, datasource) => { this.datasources[name] = datasource as Datasource; }, diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx index e3a3802320aaa..6911212094f65 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/field_item.tsx @@ -20,11 +20,11 @@ function wrapOnDot(str?: string) { // u200B is a non-width white-space character, which allows // the browser to efficiently word-wrap right after the dot // without us having to draw a lot of extra DOM elements, etc - return str ? str.replace(/\./g, '.\u200B') : undefined; + return str ? str.replace(/\./g, '.\u200B') : ''; } export function FieldItem({ field, indexPatternId, highlight }: FieldItemProps) { - const wrappableName = wrapOnDot(field.name)!; + const wrappableName = wrapOnDot(field.name); const wrappableHighlight = wrapOnDot(highlight); const highlightIndex = wrappableHighlight ? wrappableName.toLowerCase().indexOf(wrappableHighlight.toLowerCase()) @@ -35,8 +35,8 @@ export function FieldItem({ field, indexPatternId, highlight }: FieldItemProps) ) : ( {wrappableName.substr(0, highlightIndex)} - {wrappableName.substr(highlightIndex, wrappableHighlight!.length)} - {wrappableName.substr(highlightIndex + wrappableHighlight!.length)} + {wrappableName.substr(highlightIndex, wrappableHighlight.length)} + {wrappableName.substr(highlightIndex + wrappableHighlight.length)} ); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operation_definitions/terms.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operation_definitions/terms.tsx index 6964e9fb89f3b..2b912f827fe11 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operation_definitions/terms.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_plugin/operation_definitions/terms.tsx @@ -59,16 +59,19 @@ export const termsOperation: OperationDefinition = { return []; }, buildColumn({ suggestedPriority, columns, field }) { + if (!field) { + throw new Error('Invariant error: terms operation requires field'); + } const existingMetricColumn = Object.entries(columns) .filter(([_columnId, column]) => column && isSortableByColumn(column)) .map(([id]) => id)[0]; return { - label: ofName(field ? field.name : ''), - dataType: field!.type as DataType, + label: ofName(field.name), + dataType: field.type as DataType, operationType: 'terms', suggestedPriority, - sourceField: field ? field.name : '', + sourceField: field.name, isBucketed: true, params: { size: DEFAULT_SIZE,