Skip to content

Commit

Permalink
[Lens] Query based annotations (elastic#138753)
Browse files Browse the repository at this point in the history
* ⚗️ Initial code for query based annotations

* 🐛 Solved more conflicts

* ⚗️ More scaffolding layout

* ⚗️ Initial indexpatetrn move into frame

* ⚗️ Make field selection work

* 🚧 Fixed almost all dataViews occurrencies, but changeIndexPattern

* 🚧 More work on change index pattern

* Move lens dataViews state into main state

* 🔥 Remove some old cruft from the code

* 🐛 Fix dataViews layer change

* 🐛 Fix datasourceLayers refs

* 🔥 Remove more old cruft

* 🐛 Fix bug when loading SO

* 🐛 Fix initial existence flag

* 🏷️ Fix type issues

* 🏷️ Fix types and tests

* 🏷️ Fix types issues

* ✅ Fix more tests

* ✅ Fix with new dataViews structure

* ✅ Fix more test mocks

* ✅ More tests fixed

* 🔥 Removed unused prop

* ✅ Down to single broken test suite

* 🏷️ Fix type issue

* 👌 Integrate selector feedback

* ✅ Fix remaining unit tests

* 🏷️ fix type issues

* 🐛 Fix bug when creating dataview in place

* ✨ Update with latest dataview state + fix dataviews picker for annotations

* 🐛 Fix edit + remove field flow

* Update x-pack/plugins/lens/public/visualizations/xy/types.ts

* 📸 Fix snapshot

* 🐛 Fix the dataViews switch bug

* 🔥 remove old cruft

* ♻️ Revert removal from dataviews state branch

* ♻️ Load all at once

* 🔧 working on persistent state + fix new layer bug

* 🔥 remove unused stuff

* 🏷️ Fix some typings

* 🔧 Fix expression issue

* ✅ Add service unit tests

* 👌 Integrated feedback

* ✨ Add migration code for manual annotations

* 🏷️ Fix type issue

* ✅ Add some other unit test

* 🏷️ Fix more type issues

* 🐛 Fix importing issue

* ♻️ Make range default color dependant on opint one

* 🐛 Fix duplicate fields selection in tooltip section

* ✅ Add more unit tests

* ✅ Fix broken test

* 🏷️ Mute ts error for now

* ✅ Fix tests

* 🔥 Reduce plugin weight

* 🐛 prevent layout shift on panel open

* 🐛 Fix extract + inject visualization references

* 🏷️ fix type issues

* ✨ Add dataview reference migration for annotations

* 🔧 Add migration to embedadble

* 🏷️ Fix type export

* 🐛 Fix more conflicts with main

* ✅ Fix tests

* 🏷️ Make textField optional

* ♻️ Refactor query input to be a shared component

* 🐛 Fix missing import

* 🐛 fix more import issues

* 🔥 remove duplicate code

* 🐛 Fix dataView switch bug

* 🏷️ Fix type issue

* annotations with fetching_event_annotations

* portal for kql input fix

* timeField goes for default if not filled

* limit changes

* handle ad-hoc data view references correctly

* fix types

* adjust tests to datatable format (remove isHidden tests as it's filtered before)

* small refactors

* fix loading on dashboard

* empty is invalid (?) tbd

* new tooltip

* emptyDatatable

* ♻️ Flip field + query inputs

* 🏷️ Fix type issue

* ✨ Add field validation for text and tooltip fields

* tooltip for single annotation

* fix tests

* fix for non--timefilter dataview

* fix annotations test - the cause was that we now don't display label for aggregated annotations ever

* use eui elements

* newline problem solved

* ✅ Add more error tests

* 👌 Rename migration state version type

* fix types for expression chart

* 🐛 Fix i18n id

* 🏷️ Fix type issue

* fix hidden all annotations

* ✅ Fix tests after ishidden removal

* 🐛 Revert references migration to an in app solution

Co-authored-by: Joe Reuter <[email protected]>
Co-authored-by: Kibana Machine <[email protected]>
Co-authored-by: Marta Bondyra <[email protected]>
Co-authored-by: Marta Bondyra <[email protected]>
  • Loading branch information
5 people authored and guskovaue committed Sep 12, 2022
1 parent 3f69e0c commit cbe1061
Show file tree
Hide file tree
Showing 118 changed files with 3,357 additions and 961 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pageLoadAssetSize:
eventAnnotation: 19334
screenshotting: 22870
synthetics: 40958
expressionXY: 36000
expressionXY: 38000
kibanaUsageCollection: 16463
kubernetesSecurity: 77234
threatIntelligence: 29195
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ export const createArgsWithLayers = (
},
],
layers: Array.isArray(layers) ? layers : [layers],
annotations: {
type: 'event_annotations_result',
layers: [],
datatable: {
type: 'datatable',
columns: [],
rows: [],
},
},
});

export function sampleArgs() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 { Datatable, ExpressionFunctionDefinition } from '@kbn/expressions-plugin/common';
import { ExtendedAnnotationLayerConfigResult } from '../types';
import { strings } from '../i18n';
import { EXTENDED_ANNOTATION_LAYER } from '../constants';

export interface EventAnnotationResultArgs {
layers?: ExtendedAnnotationLayerConfigResult[];
datatable: Datatable;
}

export interface EventAnnotationResultResult {
type: 'event_annotations_result';
layers: ExtendedAnnotationLayerConfigResult[];
datatable: Datatable;
}

export function eventAnnotationsResult(): ExpressionFunctionDefinition<
'event_annotations_result',
null,
EventAnnotationResultArgs,
EventAnnotationResultResult
> {
return {
name: 'event_annotations_result',
aliases: [],
type: 'event_annotations_result',
inputTypes: ['null'],
help: strings.getAnnotationLayerFnHelp(),
args: {
layers: {
types: [EXTENDED_ANNOTATION_LAYER],
multi: true,
help: strings.getAnnotationLayerFnHelp(),
},
datatable: {
types: ['datatable'],
help: strings.getAnnotationLayerFnHelp(),
},
},
fn: (input, args) => {
return {
...args,
type: 'event_annotations_result',
layers: args.layers || [],
datatable: args.datatable || {},
};
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
* Side Public License, v 1.
*/

import type { Datatable, ExpressionFunctionDefinition } from '@kbn/expressions-plugin/common';
import type { ExpressionFunctionDefinition } from '@kbn/expressions-plugin/common';
import { LayerTypes, EXTENDED_ANNOTATION_LAYER } from '../constants';
import { ExtendedAnnotationLayerConfigResult, ExtendedAnnotationLayerArgs } from '../types';
import { strings } from '../i18n';

export function extendedAnnotationLayerFunction(): ExpressionFunctionDefinition<
typeof EXTENDED_ANNOTATION_LAYER,
Datatable,
null,
ExtendedAnnotationLayerArgs,
ExtendedAnnotationLayerConfigResult
> {
return {
name: EXTENDED_ANNOTATION_LAYER,
aliases: [],
type: EXTENDED_ANNOTATION_LAYER,
inputTypes: ['datatable'],
inputTypes: ['null'],
help: strings.getAnnotationLayerFnHelp(),
args: {
simpleView: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
EXTENDED_DATA_LAYER,
REFERENCE_LINE_LAYER,
LAYERED_XY_VIS,
EXTENDED_ANNOTATION_LAYER,
REFERENCE_LINE,
} from '../constants';
import { commonXYArgs } from './common_xy_args';
Expand All @@ -26,12 +25,18 @@ export const layeredXyVisFunction: LayeredXyVisFn = {
args: {
...commonXYArgs,
layers: {
types: [EXTENDED_DATA_LAYER, REFERENCE_LINE_LAYER, EXTENDED_ANNOTATION_LAYER, REFERENCE_LINE],
types: [EXTENDED_DATA_LAYER, REFERENCE_LINE_LAYER, REFERENCE_LINE],
help: i18n.translate('expressionXY.layeredXyVis.layers.help', {
defaultMessage: 'Layers of visual series',
}),
multi: true,
},
annotations: {
types: ['event_annotations_result'],
help: i18n.translate('expressionXY.layeredXyVis.annotations.help', {
defaultMessage: 'Annotations',
}),
},
splitColumnAccessor: {
types: ['vis_dimension', 'string'],
help: strings.getSplitColumnAccessorHelp(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('xyVis', () => {
const { layerId, layerType, table, type, ...restLayerArgs } = sampleLayer;
const result = await xyVisFunction.fn(
data,
{ ...rest, ...restLayerArgs, referenceLines: [], annotationLayers: [] },
{ ...rest, ...restLayerArgs, referenceLines: [] },
createMockExecutionContext()
);

Expand Down Expand Up @@ -53,7 +53,6 @@ describe('xyVis', () => {
...{ ...sampleLayer, markSizeAccessor: 'b' },
markSizeRatio: 0,
referenceLines: [],
annotationLayers: [],
},
createMockExecutionContext()
)
Expand All @@ -67,7 +66,6 @@ describe('xyVis', () => {
...{ ...sampleLayer, markSizeAccessor: 'b' },
markSizeRatio: 101,
referenceLines: [],
annotationLayers: [],
},
createMockExecutionContext()
)
Expand All @@ -86,7 +84,6 @@ describe('xyVis', () => {
...restLayerArgs,
minTimeBarInterval: '1q',
referenceLines: [],
annotationLayers: [],
},
createMockExecutionContext()
)
Expand All @@ -105,7 +102,6 @@ describe('xyVis', () => {
...restLayerArgs,
minTimeBarInterval: '1h',
referenceLines: [],
annotationLayers: [],
},
createMockExecutionContext()
)
Expand All @@ -124,7 +120,6 @@ describe('xyVis', () => {
...restLayerArgs,
addTimeMarker: true,
referenceLines: [],
annotationLayers: [],
},
createMockExecutionContext()
)
Expand All @@ -144,7 +139,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

splitRowAccessor,
},
createMockExecutionContext()
Expand All @@ -165,7 +160,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

splitColumnAccessor,
},
createMockExecutionContext()
Expand All @@ -185,7 +180,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

markSizeRatio: 5,
},
createMockExecutionContext()
Expand All @@ -207,7 +202,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

seriesType: 'bar',
showLines: true,
},
Expand All @@ -230,7 +225,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

isHistogram: true,
xScaleType: 'time',
xAxisConfig: {
Expand All @@ -257,7 +252,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

xAxisConfig: {
type: 'xAxisConfig',
extent: {
Expand Down Expand Up @@ -287,7 +282,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

xAxisConfig: {
type: 'xAxisConfig',
extent: { type: 'axisExtentConfig', mode: 'dataBounds' },
Expand All @@ -308,7 +303,7 @@ describe('xyVis', () => {
...rest,
...restLayerArgs,
referenceLines: [],
annotationLayers: [],

isHistogram: true,
xAxisConfig: {
type: 'xAxisConfig',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { XyVisFn } from '../types';
import { XY_VIS, REFERENCE_LINE, ANNOTATION_LAYER } from '../constants';
import { XY_VIS, REFERENCE_LINE } from '../constants';
import { strings } from '../i18n';
import { commonXYArgs } from './common_xy_args';
import { commonDataLayerArgs } from './common_data_layer_args';
Expand Down Expand Up @@ -39,11 +39,6 @@ export const xyVisFunction: XyVisFn = {
help: strings.getReferenceLinesHelp(),
multi: true,
},
annotationLayers: {
types: [ANNOTATION_LAYER],
help: strings.getAnnotationLayerHelp(),
multi: true,
},
splitColumnAccessor: {
types: ['vis_dimension', 'string'],
help: strings.getSplitColumnAccessorHelp(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {

const {
referenceLines = [],
annotationLayers = [],
// data_layer args
seriesType,
accessors,
Expand Down Expand Up @@ -101,7 +100,6 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
const layers: XYLayerConfig[] = [
...appendLayerIds(dataLayers, 'dataLayers'),
...appendLayerIds(referenceLines, 'referenceLines'),
...appendLayerIds(annotationLayers, 'annotationLayers'),
];

logDatatable(data, layers, handlers, args.splitColumnAccessor, args.splitRowAccessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type {
DataLayerConfig,
FittingFunction,
AxisExtentConfig,
CollectiveConfig,
MergedAnnotation,
LegendConfigResult,
AxesSettingsConfig,
XAxisConfigResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ export interface XYArgs extends DataLayerArgs {
emphasizeFitting?: boolean;
valueLabels: ValueLabelMode;
referenceLines: ReferenceLineConfigResult[];
annotationLayers: AnnotationLayerConfigResult[];
fittingFunction?: FittingFunction;
fillOpacity?: number;
hideEndzones?: boolean;
Expand All @@ -233,12 +232,21 @@ export interface XYArgs extends DataLayerArgs {
showTooltip: boolean;
}

export interface ExpressionAnnotationsLayers {
layers: AnnotationLayerConfigResult[];
datatable: Datatable;
}
export type ExpressionAnnotationResult = ExpressionAnnotationsLayers & {
type: 'event_annotations_result';
};

export interface LayeredXYArgs {
legend: LegendConfigResult;
endValue?: EndValue;
emphasizeFitting?: boolean;
valueLabels: ValueLabelMode;
layers?: XYExtendedLayerConfigResult[];
annotations?: ExpressionAnnotationResult;
fittingFunction?: FittingFunction;
fillOpacity?: number;
hideEndzones?: boolean;
Expand Down Expand Up @@ -279,6 +287,7 @@ export interface XYProps {
orderBucketsBySum?: boolean;
showTooltip: boolean;
singleTable?: boolean;
annotations?: ExpressionAnnotationResult;
}

export interface AnnotationLayerArgs {
Expand Down Expand Up @@ -326,7 +335,6 @@ export type XYExtendedLayerConfig =
export type XYExtendedLayerConfigResult =
| ExtendedDataLayerConfigResult
| ReferenceLineLayerConfigResult
| ExtendedAnnotationLayerConfigResult
| ReferenceLineConfigResult;

export interface ExtendedReferenceLineDecorationConfig extends ReferenceLineArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export interface XYRender {
value: XYChartProps;
}

export interface CollectiveConfig extends Omit<ManualPointEventAnnotationArgs, 'icon'> {
export interface MergedAnnotation extends Omit<ManualPointEventAnnotationArgs, 'icon'> {
timebucket: number;
position: 'bottom';
icon?: AvailableAnnotationIcon | string;
customTooltipDetails?: AnnotationTooltipFormatter | undefined;
customTooltipDetails: AnnotationTooltipFormatter;
isGrouped: boolean;
}
Loading

0 comments on commit cbe1061

Please sign in to comment.