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

[lens] Draft against 7.x #45459

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,16 @@ module.exports = {
},
},

/**
* Lens overrides
*/
{
files: ['x-pack/legacy/plugins/lens/**/*.ts', 'x-pack/legacy/plugins/lens/**/*.tsx'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
},

/**
* disable jsx-a11y for kbn-ui-framework
*/
Expand Down
79 changes: 79 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# GitHub CODEOWNERS definition
# Identify which groups will be pinged by changes to different parts of the codebase.
# For more info, see https://help.github.com/articles/about-codeowners/

# App
/x-pack/legacy/plugins/lens/ @elastic/kibana-app

# App Architecture
/src/plugins/data/ @elastic/kibana-app-arch
/src/plugins/kibana_utils/ @elastic/kibana-app-arch
/src/plugins/kibana_react/ @elastic/kibana-app-arch

# APM
/x-pack/legacy/plugins/apm/ @elastic/apm-ui

# Beats
/x-pack/legacy/plugins/beats_management/ @elastic/beats

# Canvas
/x-pack/legacy/plugins/canvas/ @elastic/kibana-canvas

# Code
/x-pack/legacy/plugins/code/ @teams/code
/x-pack/test/functional/apps/code/ @teams/code
/x-pack/test/api_integration/apis/code/ @teams/code

# Infrastructure and Logs UI
/x-pack/legacy/plugins/infra/ @elastic/infra-logs-ui

# Machine Learning
/x-pack/legacy/plugins/ml/ @elastic/ml-ui

# Operations
/renovate.json5 @elastic/kibana-operations
/src/dev/ @elastic/kibana-operations
/src/setup_node_env/ @elastic/kibana-operations
/src/optimize/ @elastic/kibana-operations

# Platform
/src/core/ @elastic/kibana-platform
/src/legacy/server/saved_objects/ @elastic/kibana-platform
/src/legacy/ui/public/saved_objects @elastic/kibana-platform
/config/kibana.yml @elastic/kibana-platform
/x-pack/plugins/features/ @elastic/kibana-platform

# Security
/x-pack/legacy/plugins/security/ @elastic/kibana-security
/x-pack/legacy/plugins/spaces/ @elastic/kibana-security
/x-pack/legacy/plugins/encrypted_saved_objects/ @elastic/kibana-security
/src/legacy/server/csp/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security

# Kibana Stack Services
/packages/kbn-analytics/ @elastic/kibana-stack-services
/src/legacy/core_plugins/ui_metric/ @elastic/kibana-stack-services
/x-pack/legacy/plugins/telemetry @elastic/kibana-stack-services
/x-pack/legacy/plugins/alerting @elastic/kibana-stack-services
/x-pack/legacy/plugins/actions @elastic/kibana-stack-services
/x-pack/legacy/plugins/task_manager @elastic/kibana-stack-services

# Design
**/*.scss @elastic/kibana-design

# Elasticsearch UI
/src/legacy/core_plugins/console/ @elastic/es-ui
/src/plugins/es_ui_shared/ @elastic/es-ui
/x-pack/legacy/plugins/console_extensions/ @elastic/es-ui
/x-pack/legacy/plugins/cross_cluster_replication/ @elastic/es-ui
/x-pack/legacy/plugins/index_lifecycle_management/ @elastic/es-ui
/x-pack/legacy/plugins/index_management/ @elastic/es-ui
/x-pack/legacy/plugins/license_management/ @elastic/es-ui
/x-pack/legacy/plugins/remote_clusters/ @elastic/es-ui
/x-pack/legacy/plugins/rollup/ @elastic/es-ui
/x-pack/legacy/plugins/searchprofiler/ @elastic/es-ui
/x-pack/legacy/plugins/snapshot_restore/ @elastic/es-ui
/x-pack/legacy/plugins/watcher/ @elastic/es-ui

# Kibana TSVB external contractors
/src/legacy/core_plugins/metrics/ @elastic/kibana-tsvb-external
2 changes: 1 addition & 1 deletion packages/kbn-interpreter/src/common/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

export { Registry } from './lib/registry';

export { fromExpression, toExpression, Ast } from './lib/ast';
export { fromExpression, toExpression, Ast, ExpressionFunctionAST } from './lib/ast';
15 changes: 14 additions & 1 deletion packages/kbn-interpreter/src/common/lib/ast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@
* under the License.
*/

export type Ast = unknown;
export type ExpressionArgAST = string | boolean | number | Ast;

export interface ExpressionFunctionAST {
type: 'function';
function: string;
arguments: {
[key: string]: ExpressionArgAST[];
};
}

export interface Ast {
type: 'expression';
chain: ExpressionFunctionAST[];
}

export declare function fromExpression(expression: string): Ast;
export declare function toExpression(astObj: Ast, type?: string): string;
3 changes: 2 additions & 1 deletion src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function stubbedLogstashFields() {
['area', 'geo_shape', true, true ],
['hashed', 'murmur3', false, true ],
['geo.coordinates', 'geo_point', true, true ],
['extension', 'keyword', true, true ],
['extension', 'text', true, true],
['extension.keyword', 'keyword', true, true, {}, 'extension', 'multi' ],
['machine.os', 'text', true, true ],
['machine.os.raw', 'keyword', true, true, {}, 'machine.os', 'multi' ],
['geo.src', 'keyword', true, true ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { IExpressionLoader, ExpressionLoader } from './lib/loader';
// Accept all options of the runner as props except for the
// dom element which is provided by the component itself
export interface ExpressionRendererProps extends IExpressionLoaderParams {
className: 'string';
className: string;
expression: string | ExpressionAST;
/**
* If an element is specified, but the response of the expression run can't be rendered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { setInspector, setInterpreter } from './services';
import { execute } from './lib/execute';
import { loader } from './lib/loader';
import { render } from './lib/render';
import { IInterpreter } from './lib/_types';
import { createRenderer } from './expression_renderer';

import { Start as IInspector } from '../../../../../plugins/inspector/public';
Expand All @@ -40,7 +41,9 @@ export class ExpressionsService {
// eslint-disable-next-line
const { getInterpreter } = require('../../../interpreter/public/interpreter');
getInterpreter()
.then(setInterpreter)
.then(({ interpreter }: { interpreter: IInterpreter }) => {
setInterpreter(interpreter);
})
.catch((e: Error) => {
throw new Error('interpreter is not initialized');
});
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/data/public/expressions/lib/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export interface IInterpreterRenderHandlers {
event: (event: event) => void;
}

export interface IInterpreterRenderFunction {
export interface IInterpreterRenderFunction<T = unknown> {
name: string;
displayName: string;
help: string;
validate: () => void;
reuseDomNode: boolean;
render: (domNode: Element, data: unknown, handlers: IInterpreterRenderHandlers) => void;
render: (domNode: Element, data: T, handlers: IInterpreterRenderHandlers) => void | Promise<void>;
}

export interface IInterpreter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,5 +353,4 @@ export class QueryBarUI extends Component<Props, State> {
}
}

// @ts-ignore
export const QueryBar = injectI18n(QueryBarUI);
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class VisualizeListingTableUi extends Component {
editItem={capabilities.get().visualize.save ? this.props.editItem : null}
tableColumns={this.getTableColumns()}
listingLimit={this.props.listingLimit}
selectable={item => item.canDelete}
initialFilter={''}
noItemsFragment={this.getNoItemsMessage()}
entityName={
Expand Down
1 change: 1 addition & 0 deletions src/legacy/plugin_discovery/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface LegacyPluginOptions {
icon: string;
euiIconType: string;
order: number;
listed: boolean;
}>;
apps: any;
hacks: string[];
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export * from './expressions';
export * from './query';
20 changes: 20 additions & 0 deletions src/plugins/data/common/query/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export * from './types';
2 changes: 2 additions & 0 deletions x-pack/.i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"xpack.indexLifecycleMgmt": "legacy/plugins/index_lifecycle_management",
"xpack.infra": "legacy/plugins/infra",
"xpack.kueryAutocomplete": "legacy/plugins/kuery_autocomplete",
"xpack.lens": "legacy/plugins/lens",
"xpack.licensing": "plugins/licensing",
"xpack.licenseMgmt": "legacy/plugins/license_management",
"xpack.maps": "legacy/plugins/maps",
"xpack.ml": "legacy/plugins/ml",
Expand Down
2 changes: 2 additions & 0 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { snapshotRestore } from './legacy/plugins/snapshot_restore';
import { actions } from './legacy/plugins/actions';
import { alerting } from './legacy/plugins/alerting';
import { advancedUiActions } from './legacy/plugins/advanced_ui_actions';
import { lens } from './legacy/plugins/lens';

module.exports = function (kibana) {
return [
Expand Down Expand Up @@ -83,6 +84,7 @@ module.exports = function (kibana) {
ossTelemetry(kibana),
fileUpload(kibana),
encryptedSavedObjects(kibana),
lens(kibana),
snapshotRestore(kibana),
actions(kibana),
alerting(kibana),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore - Interpreter not typed yet
import { fromExpression, toExpression } from '@kbn/interpreter/common';
import { fromExpression, toExpression, Ast } from '@kbn/interpreter/common';
import { get } from 'lodash';
import React from 'react';
import ReactDOM from 'react-dom';
Expand Down Expand Up @@ -58,7 +57,7 @@ export const dropdownFilter: RendererFactory<Config> = () => ({
if (commitValue === '%%CANVAS_MATCH_ALL%%') {
handlers.setFilter('');
} else {
const newFilterAST = {
const newFilterAST: Ast = {
type: 'expression',
chain: [
{
Expand Down
14 changes: 14 additions & 0 deletions x-pack/legacy/plugins/lens/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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;
* you may not use this file except in compliance with the Elastic License.
*/

export const PLUGIN_ID = 'lens';

export const BASE_APP_URL = '/app/lens';
export const BASE_API_URL = '/api/lens';

export function getEditPath(id: string) {
return `${BASE_APP_URL}#/edit/${encodeURIComponent(id)}`;
}
7 changes: 7 additions & 0 deletions x-pack/legacy/plugins/lens/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from './constants';
99 changes: 99 additions & 0 deletions x-pack/legacy/plugins/lens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as Joi from 'joi';
import { resolve } from 'path';
import { LegacyPluginInitializer } from 'src/legacy/types';
import KbnServer, { Server } from 'src/legacy/server/kbn_server';
import { CoreSetup } from 'src/core/server';
import mappings from './mappings.json';
import { PLUGIN_ID, getEditPath, BASE_API_URL } from './common';
import { lensServerPlugin } from './server';

const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations';

export const lens: LegacyPluginInitializer = kibana => {
return new kibana.Plugin({
id: PLUGIN_ID,
configPrefix: `xpack.${PLUGIN_ID}`,
require: ['kibana', 'elasticsearch', 'xpack_main', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),

uiExports: {
app: {
title: NOT_INTERNATIONALIZED_PRODUCT_NAME,
description: 'Explore and visualize data.',
main: `plugins/${PLUGIN_ID}/index`,
listed: false,
},
embeddableFactories: ['plugins/lens/register_embeddable'],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings,
visTypes: ['plugins/lens/register_vis_type_alias'],
savedObjectsManagement: {
lens: {
defaultSearchField: 'title',
isImportableAndExportable: true,
getTitle: (obj: { attributes: { title: string } }) => obj.attributes.title,
getInAppUrl: (obj: { id: string }) => ({
path: getEditPath(obj.id),
uiCapabilitiesPath: 'lens.show',
}),
},
},
},

config: () => {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},

init(server: Server) {
const kbnServer = (server as unknown) as KbnServer;

server.plugins.xpack_main.registerFeature({
id: PLUGIN_ID,
name: NOT_INTERNATIONALIZED_PRODUCT_NAME,
app: [PLUGIN_ID, 'kibana'],
catalogue: [PLUGIN_ID],
privileges: {
all: {
api: [PLUGIN_ID],
catalogue: [PLUGIN_ID],
savedObject: {
all: [],
read: [],
},
ui: ['save', 'show'],
},
read: {
api: [PLUGIN_ID],
catalogue: [PLUGIN_ID],
savedObject: {
all: [],
read: [],
},
ui: ['show'],
},
},
});

// Set up with the new platform plugin lifecycle API.
const plugin = lensServerPlugin();
plugin.setup(({
http: {
...kbnServer.newPlatform.setup.core.http,
createRouter: () => kbnServer.newPlatform.setup.core.http.createRouter(BASE_API_URL),
},
} as unknown) as CoreSetup);

server.events.on('stop', () => {
plugin.stop();
});
},
});
};
Loading