Skip to content

Commit

Permalink
[Lens][Event annotations] Move logic into packages (elastic#161500)
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon authored and Devon Thomson committed Aug 1, 2023
1 parent d0aa8aa commit a6fdda7
Show file tree
Hide file tree
Showing 198 changed files with 840 additions and 628 deletions.
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ packages/kbn-eslint-plugin-eslint @elastic/kibana-operations
packages/kbn-eslint-plugin-imports @elastic/kibana-operations
packages/kbn-eslint-plugin-telemetry @elastic/actionable-observability
x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin @elastic/kibana-security
packages/kbn-event-annotation-common @elastic/kibana-visualizations
packages/kbn-event-annotation-components @elastic/kibana-visualizations
src/plugins/event_annotation @elastic/kibana-visualizations
x-pack/test/plugin_api_integration/plugins/event_log @elastic/response-ops
x-pack/plugins/event_log @elastic/response-ops
Expand Down Expand Up @@ -762,7 +764,7 @@ src/plugins/vis_types/timeseries @elastic/kibana-visualizations
src/plugins/vis_types/vega @elastic/kibana-visualizations
src/plugins/vis_types/vislib @elastic/kibana-visualizations
src/plugins/vis_types/xy @elastic/kibana-visualizations
src/plugins/visualization_ui_components @elastic/kibana-visualizations
packages/kbn-visualization-ui-components @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
10 changes: 8 additions & 2 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"expressionShape": "src/plugins/expression_shape",
"expressionTagcloud": "src/plugins/chart_expressions/expression_tagcloud",
"eventAnnotation": "src/plugins/event_annotation",
"eventAnnotationCommon": "packages/kbn-event-annotation-common",
"eventAnnotationComponents": "packages/kbn-event-annotation-components",
"fieldFormats": "src/plugins/field_formats",
"files": "src/plugins/files",
"filesManagement": "src/plugins/files_management",
Expand Down Expand Up @@ -72,7 +74,11 @@
"kibanaOverview": "src/plugins/kibana_overview",
"lists": "packages/kbn-securitysolution-list-utils/src",
"exceptionList-components": "packages/kbn-securitysolution-exception-list-components/src",
"management": ["src/legacy/core_plugins/management", "src/plugins/management", "packages/kbn-management"],
"management": [
"src/legacy/core_plugins/management",
"src/plugins/management",
"packages/kbn-management"
],
"monaco": "packages/kbn-monaco/src",
"navigation": "src/plugins/navigation",
"newsfeed": "src/plugins/newsfeed",
Expand Down Expand Up @@ -113,7 +119,7 @@
"visTypeVislib": "src/plugins/vis_types/vislib",
"visTypeXy": "src/plugins/vis_types/xy",
"visualizations": "src/plugins/visualizations",
"visualizationUiComponents": "src/plugins/visualization_ui_components",
"visualizationUiComponents": "packages/kbn-visualization-ui-components",
"unifiedSearch": "src/plugins/unified_search",
"unifiedFieldList": "packages/kbn-unified-field-list",
"unifiedHistogram": "src/plugins/unified_histogram"
Expand Down
4 changes: 0 additions & 4 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,6 @@ The plugin exposes the static DefaultEditorController class to consume.
|WARNING: Missing README.
|{kib-repo}blob/{branch}/src/plugins/visualization_ui_components/README.md[visualizationUiComponents]
|A series of UI components pulled out of Lens to make them available outside Lens.
|===
[discrete]
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@
"@kbn/es-types": "link:packages/kbn-es-types",
"@kbn/es-ui-shared-plugin": "link:src/plugins/es_ui_shared",
"@kbn/eso-plugin": "link:x-pack/test/encrypted_saved_objects_api_integration/plugins/api_consumer_plugin",
"@kbn/event-annotation-common": "link:packages/kbn-event-annotation-common",
"@kbn/event-annotation-components": "link:packages/kbn-event-annotation-components",
"@kbn/event-annotation-plugin": "link:src/plugins/event_annotation",
"@kbn/event-log-fixture-plugin": "link:x-pack/test/plugin_api_integration/plugins/event_log",
"@kbn/event-log-plugin": "link:x-pack/plugins/event_log",
Expand Down Expand Up @@ -750,7 +752,7 @@
"@kbn/vis-type-vega-plugin": "link:src/plugins/vis_types/vega",
"@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:src/plugins/visualization_ui_components",
"@kbn/visualization-ui-components": "link:packages/kbn-visualization-ui-components",
"@kbn/visualizations-plugin": "link:src/plugins/visualizations",
"@kbn/watcher-plugin": "link:x-pack/plugins/watcher",
"@loaders.gl/core": "^2.3.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/kbn-coloring/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"name": "@kbn/coloring",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": false
}
3 changes: 3 additions & 0 deletions packages/kbn-event-annotation-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/event-annotation-common

A few core annotation-related types and utilities that are available in both server and browser contexts.
52 changes: 52 additions & 0 deletions packages/kbn-event-annotation-common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.
*/

export const AvailableAnnotationIcons = {
ASTERISK: 'asterisk',
ALERT: 'alert',
BELL: 'bell',
BOLT: 'bolt',
BUG: 'bug',
CIRCLE: 'circle',
EDITOR_COMMENT: 'editorComment',
FLAG: 'flag',
HEART: 'heart',
MAP_MARKER: 'mapMarker',
PIN_FILLED: 'pinFilled',
STAR_EMPTY: 'starEmpty',
STAR_FILLED: 'starFilled',
TAG: 'tag',
TRIANGLE: 'triangle',
} as const;

export const EVENT_ANNOTATION_GROUP_TYPE = 'event-annotation-group';

export {
defaultAnnotationColor,
defaultAnnotationRangeColor,
defaultAnnotationLabel,
getDefaultManualAnnotation,
getDefaultQueryAnnotation,
createCopiedAnnotation,
isRangeAnnotationConfig,
isManualPointAnnotationConfig,
isQueryAnnotationConfig,
} from './util';

export type {
EventAnnotationGroupContent,
AvailableAnnotationIcon,
PointStyleProps,
EventAnnotationConfig,
EventAnnotationGroupConfig,
RangeStyleProps,
ManualAnnotationType,
PointInTimeEventAnnotationConfig,
RangeEventAnnotationConfig,
QueryPointEventAnnotationConfig,
} from './types';
13 changes: 13 additions & 0 deletions packages/kbn-event-annotation-common/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-event-annotation-common'],
};
5 changes: 5 additions & 0 deletions packages/kbn-event-annotation-common/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/event-annotation-common",
"owner": "@elastic/kibana-visualizations"
}
7 changes: 7 additions & 0 deletions packages/kbn-event-annotation-common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/event-annotation-common",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0",
"sideEffects": false
}
23 changes: 23 additions & 0 deletions packages/kbn-event-annotation-common/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts",
],
"exclude": [
"target/**/*"
],
"kbn_references": [
"@kbn/data-plugin",
"@kbn/content-management-table-list-view-table",
"@kbn/visualization-ui-components",
"@kbn/ui-theme",
"@kbn/i18n",
]
}
89 changes: 89 additions & 0 deletions packages/kbn-event-annotation-common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 { $Values } from 'utility-types';
import { DataViewSpec, KibanaQueryOutput } from '@kbn/data-plugin/common';
import { UserContentCommonSchema } from '@kbn/content-management-table-list-view-table';
import type { LineStyle } from '@kbn/visualization-ui-components';
import { AvailableAnnotationIcons } from '.';

export type AvailableAnnotationIcon = $Values<typeof AvailableAnnotationIcons>;

export type PointStyleProps = StyleSharedProps & {
icon?: AvailableAnnotationIcon;
lineWidth?: number;
lineStyle?: LineStyle;
textVisibility?: boolean;
};

export type PointInTimeEventAnnotationConfig = {
id: string;
type: ManualAnnotationType;
key: {
type: 'point_in_time';
timestamp: string;
};
} & PointStyleProps;

export type Fill = 'inside' | 'outside' | 'none';
export type ManualAnnotationType = 'manual';
export type QueryAnnotationType = 'query';
export type KeyType = 'point_in_time' | 'range';

interface StyleSharedProps {
label: string;
color?: string;
isHidden?: boolean;
}

export type RangeStyleProps = StyleSharedProps & {
outside?: boolean;
};

export type RangeEventAnnotationConfig = {
type: ManualAnnotationType;
id: string;
key: {
type: 'range';
timestamp: string;
endTimestamp: string;
};
} & RangeStyleProps;

export type StyleProps = PointStyleProps & RangeStyleProps;

export type QueryPointEventAnnotationConfig = {
id: string;
type: QueryAnnotationType;
filter: KibanaQueryOutput;
timeField?: string;
textField?: string;
extraFields?: string[];
key: {
type: 'point_in_time';
};
} & PointStyleProps;

export type EventAnnotationConfig =
| PointInTimeEventAnnotationConfig
| RangeEventAnnotationConfig
| QueryPointEventAnnotationConfig;

export interface EventAnnotationGroupConfig {
annotations: EventAnnotationConfig[];
indexPatternId: string;
ignoreGlobalFilters: boolean;
title: string;
description: string;
tags: string[];
dataViewSpec?: DataViewSpec;
}

export type EventAnnotationGroupContent = UserContentCommonSchema & {
attributes: { indexPatternId: string; dataViewSpec?: DataViewSpec };
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* Side Public License, v 1.
*/
import { euiLightVars } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import {
EventAnnotationConfig,
RangeEventAnnotationConfig,
PointInTimeEventAnnotationConfig,
QueryPointEventAnnotationConfig,
} from '../../common';
} from './types';

export const defaultAnnotationColor = euiLightVars.euiColorAccent;
// Do not compute it live as dependencies will add tens of Kbs to the plugin
export const defaultAnnotationRangeColor = `#F04E981A`; // defaultAnnotationColor with opacity 0.1
Expand All @@ -33,3 +35,57 @@ export const isQueryAnnotationConfig = (
): annotation is QueryPointEventAnnotationConfig => {
return Boolean(annotation && annotation.type === 'query');
};

export const createCopiedAnnotation = (
newId: string,
timestamp: string,
source?: EventAnnotationConfig
): EventAnnotationConfig => {
if (!source) {
return getDefaultManualAnnotation(newId, timestamp);
}
return {
...source,
id: newId,
};
};

export const defaultAnnotationLabel = i18n.translate(
'eventAnnotationCommon.manualAnnotation.defaultAnnotationLabel',
{
defaultMessage: 'Event',
}
);

export const getDefaultManualAnnotation = (
id: string,
timestamp: string
): EventAnnotationConfig => ({
label: defaultAnnotationLabel,
type: 'manual',
key: {
type: 'point_in_time',
timestamp,
},
icon: 'triangle',
id,
});

export const getDefaultQueryAnnotation = (
id: string,
fieldName: string,
timeField: string
): EventAnnotationConfig => ({
filter: {
type: 'kibana_query',
query: `${fieldName}: *`,
language: 'kuery',
},
timeField,
type: 'query',
key: {
type: 'point_in_time',
},
id,
label: `${fieldName}: *`,
});
3 changes: 3 additions & 0 deletions packages/kbn-event-annotation-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/event-annotation-components

A collection of static components used for interacting with event annotations.
Loading

0 comments on commit a6fdda7

Please sign in to comment.