Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Visualization,
VisualizationProps,
VisualizationSuggestion,
Operation,
} from '../types';
import { generateId } from '../id_generator';
import { NativeRenderer } from '../native_renderer';
Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Making this a type guard, makes TS know below that operation can't be null anymore.


return {
type: 'expression',
Expand All @@ -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',
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class Embeddable extends AbstractEmbeddable<LensEmbeddableInput, LensEmbe
initialInput,
{
defaultTitle: savedVis.title,
savedObjectId: savedVis.id!,
savedObjectId: savedVis.id,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ savedObjectId actually allows undefined so no need to non-null assert here.

editable,
// passing edit url and index patterns to the output of this embeddable for
// the container to pick them up and use them to configure filter bar and
Expand Down
81 changes: 39 additions & 42 deletions x-pack/legacy/plugins/lens/public/editor_frame_plugin/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
EmbeddablePlugin,
embeddablePlugin,
} from '../../../../../../src/legacy/core_plugins/embeddable_api/public';
import { ExpressionRenderer } from '../../../../../../src/legacy/core_plugins/data/public';
import { setup as data } from '../../../../../../src/legacy/core_plugins/data/public/legacy';
import { ExpressionFunction } from '../../../../../../src/legacy/core_plugins/interpreter/public';
import { functionsRegistry } from '../../../../../../src/legacy/core_plugins/interpreter/public/registries';
Expand All @@ -40,61 +39,59 @@ export interface InterpreterSetup {
export class EditorFramePlugin {
constructor() {}

private ExpressionRenderer: ExpressionRenderer | null = null;
private readonly datasources: Record<string, Datasource> = {};
private readonly visualizations: Record<string, Visualization> = {};

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(
<I18nProvider>
<EditorFrame
data-test-subj="lnsEditorFrame"
onError={onError}
datasourceMap={this.datasources}
visualizationMap={this.visualizations}
initialDatasourceId={(doc && doc.activeDatasourceId) || firstDatasourceId || null}
initialVisualizationId={
(doc && doc.visualizationType) || firstVisualizationId || null
}
ExpressionRenderer={this.ExpressionRenderer!}
doc={doc}
dateRange={dateRange}
query={query}
onChange={onChange}
/>
</I18nProvider>,
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(
<I18nProvider>
<EditorFrame
data-test-subj="lnsEditorFrame"
onError={onError}
datasourceMap={this.datasources}
visualizationMap={this.visualizations}
initialDatasourceId={(doc && doc.activeDatasourceId) || firstDatasourceId || null}
initialVisualizationId={
(doc && doc.visualizationType) || firstVisualizationId || null
}
ExpressionRenderer={plugins.data.expressions.ExpressionRenderer}
doc={doc}
dateRange={dateRange}
query={query}
onChange={onChange}
/>
</I18nProvider>,
domElement
);
},
unmount() {
if (domElement) {
unmountComponentAtNode(domElement);
}
},
};
};

return {
createInstance: this.createInstance.bind(this),
createInstance,
registerDatasource: (name, datasource) => {
this.datasources[name] = datasource as Datasource<unknown, unknown>;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -35,8 +35,8 @@ export function FieldItem({ field, indexPatternId, highlight }: FieldItemProps)
) : (
<span>
<span>{wrappableName.substr(0, highlightIndex)}</span>
<strong>{wrappableName.substr(highlightIndex, wrappableHighlight!.length)}</strong>
<span>{wrappableName.substr(highlightIndex + wrappableHighlight!.length)}</span>
<strong>{wrappableName.substr(highlightIndex, wrappableHighlight.length)}</strong>
<span>{wrappableName.substr(highlightIndex + wrappableHighlight.length)}</span>
</span>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ export const termsOperation: OperationDefinition<TermsIndexPatternColumn> = {
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,
Expand Down