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

Move Lens attribute builder to a package #163422

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a6c664b
Move Lens attribute builder to a package
crespocarlos Aug 8, 2023
fbedfe5
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 8, 2023
aa9ca69
Replace imports with new package
crespocarlos Aug 9, 2023
4be9735
README.md
crespocarlos Aug 9, 2023
0882949
Merge branch 'main' of github.com:elastic/kibana into move-attribute-…
crespocarlos Aug 9, 2023
204eeb0
Merge branch 'main' into move-attribute-builder-to-package
kibanamachine Aug 9, 2023
9106c0c
Fix imports
crespocarlos Aug 9, 2023
1228e4b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 9, 2023
599939f
Fix tsconfig.base.json
crespocarlos Aug 9, 2023
dfce17b
Rename package
crespocarlos Aug 9, 2023
6a3821b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 9, 2023
e876dca
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Aug 9, 2023
1c057b3
Improve API interface
crespocarlos Aug 9, 2023
92ea7bb
Merge branch 'main' of github.com:elastic/kibana into move-attribute-…
crespocarlos Aug 9, 2023
5306147
Fix interfaces
crespocarlos Aug 9, 2023
957bfff
Fix imports
crespocarlos Aug 9, 2023
c608aea
Moving README.md
crespocarlos Aug 10, 2023
1aaf702
Moving README.md
crespocarlos Aug 10, 2023
8855012
Implement proposed changes
crespocarlos Aug 11, 2023
37bf27e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 11, 2023
6fab067
Merge branch 'main' of github.com:elastic/kibana into move-attribute-…
crespocarlos Aug 11, 2023
fdcf3e4
Add Layer dataView support; fix build
crespocarlos Aug 11, 2023
1d25ca7
Fix functional test
crespocarlos Aug 12, 2023
1cbc90a
date_histogram bucket type as default
crespocarlos Aug 12, 2023
182df2a
Merge branch 'main' of github.com:elastic/kibana into move-attribute-…
crespocarlos Aug 14, 2023
bcafce5
Reverting some changes; changing ownership
crespocarlos Aug 14, 2023
8ae9422
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Aug 14, 2023
d57fc31
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Aug 14, 2023
dc59f50
Fix test
crespocarlos Aug 14, 2023
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ src/plugins/vis_types/vega @elastic/kibana-visualizations
src/plugins/vis_types/vislib @elastic/kibana-visualizations
src/plugins/vis_types/xy @elastic/kibana-visualizations
packages/kbn-visualization-ui-components @elastic/kibana-visualizations
packages/kbn-visualization-utils @elastic/kibana-visualizations
src/plugins/visualizations @elastic/kibana-visualizations
x-pack/plugins/watcher @elastic/platform-deployment-management
packages/kbn-web-worker-stub @elastic/kibana-operations
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@
"@kbn/vis-type-vislib-plugin": "link:src/plugins/vis_types/vislib",
"@kbn/vis-type-xy-plugin": "link:src/plugins/vis_types/xy",
"@kbn/visualization-ui-components": "link:packages/kbn-visualization-ui-components",
"@kbn/visualization-utils": "link:packages/kbn-visualization-utils",
"@kbn/visualizations-plugin": "link:src/plugins/visualizations",
"@kbn/watcher-plugin": "link:x-pack/plugins/watcher",
"@loaders.gl/core": "^3.4.7",
Expand Down
3 changes: 3 additions & 0 deletions packages/kbn-visualization-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/visualization-utils

A shared utils package for Lens.
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { DataViewSpec, DataView } from '@kbn/data-plugin/common';

export const DEFAULT_AD_HOC_DATA_VIEW_ID = 'infra_lens_ad_hoc_default';
export const DEFAULT_AD_HOC_DATA_VIEW_ID = 'lens_ad_hoc_default';

export class DataViewCache {
private static instance: DataViewCache;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import 'jest-canvas-mock';
Expand All @@ -19,7 +20,7 @@ import {
} from './visualization_types';
import type { FormulaPublicApi, GenericIndexPatternColumn } from '@kbn/lens-plugin/public';
import { ReferenceBasedIndexPatternColumn } from '@kbn/lens-plugin/public/datasources/form_based/operations/definitions/column_types';
import type { FormulaConfig } from '../types';
import type { FormulaConfig } from './types';

const mockDataView = {
id: 'mock-id',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type {
LensAttributes,
LensVisualizationState,
Chart,
VisualizationAttributesBuilder,
} from '../types';
} from './types';
import { DataViewCache } from './data_view_cache';
import { getAdhocDataView } from './utils';

export class LensAttributesBuilder<T extends Chart<LensVisualizationState>>
implements VisualizationAttributesBuilder
{
private dataViewCache: DataViewCache;
constructor(private state: { visualization: T }) {
constructor(private lens: { visualization: T }) {
this.dataViewCache = DataViewCache.getInstance();
}

build(): LensAttributes {
const { visualization } = this.state;
const { visualization } = this.lens;
return {
title: visualization.getTitle(),
visualizationType: visualization.getVisualizationType(),
Expand All @@ -34,9 +36,12 @@ export class LensAttributesBuilder<T extends Chart<LensVisualizationState>>
},
},
internalReferences: visualization.getReferences(),
// EmbeddableComponent receive filters.
filters: [],
// EmbeddableComponent receive query.
query: { language: 'kuery', query: '' },
visualization: visualization.getVisualizationState(),
// Getting the spec from a data view is a heavy operation, that's why the result is cached.
adHocDataViews: getAdhocDataView(this.dataViewCache.getSpec(visualization.getDataView())),
},
};
Expand Down
76 changes: 76 additions & 0 deletions packages/kbn-visualization-utils/attribute_builder/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { SavedObjectReference } from '@kbn/core/server';
import type { DataView } from '@kbn/data-views-plugin/common';
import type {
FormBasedPersistedState,
MetricVisualizationState,
PersistedIndexPatternLayer,
TypedLensByValueInput,
XYState,
FormulaPublicApi,
XYLayerConfig,
} from '@kbn/lens-plugin/public';
export type LensAttributes = TypedLensByValueInput['attributes'];

// Attributes
export type LensVisualizationState = XYState | MetricVisualizationState;

export interface VisualizationAttributesBuilder {
build(): LensAttributes;
}

// Column
export interface ChartColumn {
getData(
id: string,
baseLayer: PersistedIndexPatternLayer,
dataView: DataView
): PersistedIndexPatternLayer;
getFormulaConfig(): FormulaConfig;
}

// Layer
export type LensLayerConfig = XYLayerConfig | MetricVisualizationState;

export interface ChartLayer<TLayerConfig extends LensLayerConfig> {
getName(): string | undefined;
getLayer(
layerId: string,
accessorId: string,
dataView: DataView
): FormBasedPersistedState['layers'];
getReference(layerId: string, dataView: DataView): SavedObjectReference[];
getLayerConfig(layerId: string, acessorId: string): TLayerConfig;
}

// Chart
export interface Chart<TVisualizationState extends LensVisualizationState> {
getTitle(): string;
getVisualizationType(): string;
getLayers(): FormBasedPersistedState['layers'];
getVisualizationState(): TVisualizationState;
getReferences(): SavedObjectReference[];
getDataView(): DataView;
}
export interface ChartConfig<
TLayer extends ChartLayer<LensLayerConfig> | Array<ChartLayer<LensLayerConfig>>
> {
dataView: DataView;
layers: TLayer;
title?: string;
}

// Formula
type LensFormula = Parameters<FormulaPublicApi['insertOrReplaceFormulaColumn']>[1];
export type FormulaConfig = Omit<LensFormula, 'format' | 'formula'> & {
color?: string;
format: NonNullable<LensFormula['format']>;
value: string;
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import {

import type {
DateHistogramIndexPatternColumn,
PersistedIndexPatternLayer,
TermsIndexPatternColumn,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { XYChart } from './xy_chart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { FormulaPublicApi, PersistedIndexPatternLayer } from '@kbn/lens-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { FormulaConfig, ChartColumn } from '../../../../types';
import type { FormulaConfig, ChartColumn } from '../../../types';

export class FormulaColumn implements ChartColumn {
constructor(private formulaConfig: FormulaConfig, private formulaAPI: FormulaPublicApi) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { PersistedIndexPatternLayer } from '@kbn/lens-plugin/public';
import type { ReferenceBasedIndexPatternColumn } from '@kbn/lens-plugin/public/datasources/form_based/operations/definitions/column_types';
import type { FormulaConfig, ChartColumn } from '../../../../types';
import type { FormulaConfig, ChartColumn } from '../../../types';

export class ReferenceLineColumn implements ChartColumn {
constructor(private formulaConfig: FormulaConfig) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { MetricLayer, type MetricLayerOptions } from './metric_layer';
export { XYDataLayer, type XYLayerOptions } from './xy_data_layer';
export { XYReferenceLinesLayer } from './xy_reference_lines_layer';

export { FormulaColumn as FormulaDataColumn } from './column/formula';
export { ReferenceLineColumn } from './column/reference_line';
export { FormulaColumn as FormulaDataColumn } from './columns/formula';
export { ReferenceLineColumn } from './columns/reference_line';
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { SavedObjectReference } from '@kbn/core/server';
Expand All @@ -13,9 +14,9 @@ import type {
MetricVisualizationState,
PersistedIndexPatternLayer,
} from '@kbn/lens-plugin/public';
import type { ChartColumn, ChartLayer, FormulaConfig } from '../../../types';
import type { ChartColumn, ChartLayer, FormulaConfig } from '../../types';
import { getDefaultReferences, getHistogramColumn } from '../../utils';
import { FormulaColumn } from './column/formula';
import { FormulaColumn } from './columns/formula';

const HISTOGRAM_COLUMN_NAME = 'x_date_histogram';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { SavedObjectReference } from '@kbn/core/server';
Expand All @@ -14,9 +15,9 @@ import type {
XYDataLayerConfig,
SeriesType,
} from '@kbn/lens-plugin/public';
import type { ChartColumn, ChartLayer, FormulaConfig } from '../../../types';
import type { ChartColumn, ChartLayer, FormulaConfig } from '../../types';
import { getDefaultReferences, getHistogramColumn, getTopValuesColumn } from '../../utils';
import { FormulaColumn } from './column/formula';
import { FormulaColumn } from './columns/formula';

const BREAKDOWN_COLUMN_NAME = 'aggs_breakdown';
const HISTOGRAM_COLUMN_NAME = 'x_date_histogram';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { SavedObjectReference } from '@kbn/core/server';
Expand All @@ -12,9 +13,9 @@ import type {
PersistedIndexPatternLayer,
XYReferenceLineLayerConfig,
} from '@kbn/lens-plugin/public';
import type { ChartColumn, ChartLayer, FormulaConfig } from '../../../types';
import type { ChartColumn, ChartLayer, FormulaConfig } from '../../types';
import { getDefaultReferences } from '../../utils';
import { ReferenceLineColumn } from './column/reference_line';
import { ReferenceLineColumn } from './columns/reference_line';

interface XYReferenceLinesLayerConfig {
data: FormulaConfig[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { FormBasedPersistedState, MetricVisualizationState } from '@kbn/lens-plugin/public';
import type { SavedObjectReference } from '@kbn/core/server';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { Chart, ChartConfig, ChartLayer } from '../types';
import { DEFAULT_LAYER_ID } from '../utils';

import type { Chart, ChartConfig, ChartLayer } from '../../types';

const ACCESSOR = 'metric_formula_accessor';

export class MetricChart implements Chart<MetricVisualizationState> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { FormBasedPersistedState, XYLayerConfig, XYState } from '@kbn/lens-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { SavedObjectReference } from '@kbn/core/server';
import type { Chart, ChartConfig, ChartLayer } from '../types';
import { DEFAULT_LAYER_ID } from '../utils';
import type { Chart, ChartConfig, ChartLayer } from '../../types';

const ACCESSOR = 'formula_accessor';

Expand Down
Loading