Skip to content

Commit

Permalink
[lens] Add more complete initial state
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Apr 30, 2019
1 parent 8d685d4 commit 63c5b3c
Show file tree
Hide file tree
Showing 15 changed files with 448 additions and 54 deletions.
4 changes: 2 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { translations } from './plugins/translations';
import { upgradeAssistant } from './plugins/upgrade_assistant';
import { uptime } from './plugins/uptime';
import { ossTelemetry } from './plugins/oss_telemetry';
import { visualizationEditor } from './plugins/visualization_editor';
import { visualizationLens } from './plugins/visualization_lens';

module.exports = function (kibana) {
return [
Expand Down Expand Up @@ -76,6 +76,6 @@ module.exports = function (kibana) {
upgradeAssistant(kibana),
uptime(kibana),
ossTelemetry(kibana),
visualizationEditor(kibana),
visualizationLens(kibana),
];
};
36 changes: 0 additions & 36 deletions x-pack/plugins/visualization_editor/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const PLUGIN_ID = 'visualization_editor';
export const PLUGIN_ID = 'visualization_lens';
73 changes: 73 additions & 0 deletions x-pack/plugins/visualization_lens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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 { Server } from 'hapi';
import { resolve } from 'path';

import { PLUGIN_ID } from './common';

const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations';

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

uiExports: {
app: {
title: NOT_INTERNATIONALIZED_PRODUCT_NAME,
description: 'Explore and visualize data.',
main: `plugins/${PLUGIN_ID}/app`,
icon: 'plugins/kibana/assets/visualize.svg',
euiIconType: 'visualizeApp',
order: 8950, // Uptime is 8900
},
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
},

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

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

export { editorFrame } from './public';
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"author": "Elastic",
"name": "visualization_editor",
"name": "visualization_lens",
"version": "7.0.0",
"private": true,
"license": "Elastic-License",
"devDependencies": {},
"dependencies": {
"@elastic/charts": "^3.11.0"
"@elastic/charts": "^4.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,42 @@
*/

import { I18nProvider } from '@kbn/i18n/react';
import React from 'react';
import { IScope } from 'angular';
import React, { useCallback } from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import chrome from 'ui/chrome';

import { PLUGIN_ID } from '../common';

// TODO: Convert this to the "new platform" way of doing UI
function App($scope: any, $element: Element[]) {
const el = $element[0];
import { editorFrame } from '.';

$scope.$on('$destroy', () => unmountComponentAtNode(el));
// Side effect of loading this is to register
import './indexpattern_datasource';

function Lens() {
const renderFrame = useCallback(node => {
if (node !== null) {
editorFrame.render(node);
}
}, []);

return render(
return (
<I18nProvider>
<h1>Visualization Editor</h1>
</I18nProvider>,
el
<div>
<h1>Lens</h1>

<div ref={renderFrame} />
</div>
</I18nProvider>
);
}

// TODO: Convert this to the "new platform" way of doing UI
function App($scope: IScope, $element: JQLite) {
const el = $element[0];
$scope.$on('$destroy', () => unmountComponentAtNode(el));

return render(<Lens />, el);
}

chrome.setRootController(PLUGIN_ID, App);
70 changes: 70 additions & 0 deletions x-pack/plugins/visualization_lens/public/editor_frame.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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 React, { useCallback } from 'react';
import { render } from 'react-dom';
import { Datasource, Visualization, EditorFrameAPI } from './types';

function EditorFrameComponent(props: {
datasources: Array<Datasource<unknown>>;
visualizations: Array<Visualization<unknown>>;
}) {
const renderDatasource = (datasource: Datasource<unknown>) => {
return useCallback(
node => {
datasource.renderDataPanel({
domElement: node,
});
},
[datasource]
);
};

return (
<div>
<h2>Editor Frame</h2>

{props.datasources.map((datasource, index) => (
<div key={index} ref={renderDatasource(datasource)} />
))}
</div>
);
}

class EditorFrame {
constructor() {}

private datasources: Array<Datasource<unknown>> = [];
private visualizations: Array<Visualization<unknown>> = [];

public setup(): EditorFrameAPI {
return {
render: (domElement: Element) => {
render(
<EditorFrameComponent
datasources={this.datasources}
visualizations={this.visualizations}
/>,
domElement
);
},
registerDatasource: (datasource: Datasource<unknown>) => {
this.datasources.push(datasource);
},
registerVisualization: (visualization: Visualization<unknown>) => {
this.visualizations.push(visualization);
},
};
}

public stop() {
return {};
}
}

export { EditorFrame };

export const editorFrame = new EditorFrame().setup();
8 changes: 8 additions & 0 deletions x-pack/plugins/visualization_lens/public/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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 './editor_frame';
export * from './types';
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.
*/

// TODO: Figure out how to separate this out into another plugin
import { editorFrame } from '../../';

import { indexPatternDatasource } from './indexpattern';

editorFrame.registerDatasource(indexPatternDatasource);

export * from './indexpattern';
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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 React from 'react';
import { render } from 'react-dom';
import { Datasource, Operation, DataType } from '../';

interface IndexPatternPrivateState {
query: object;
}

class IndexPatternDatasource implements Datasource<IndexPatternPrivateState> {
private state?: IndexPatternPrivateState;

constructor(state?: IndexPatternPrivateState) {
if (state) {
this.state = state;
}
}

toExpression() {
return '';
}

renderDataPanel({ domElement }: { domElement: Element }) {
render(<div>Index Pattern Data Source</div>, domElement);
}

getPublicAPI() {
return {
getTableSpec: () => [],
getOperationForColumnId: () => ({
id: '',
// User-facing label for the operation
label: '',
dataType: 'string' as DataType,
// A bucketed operation has many values the same
isBucketed: false,
}),

// Called by dimension
getDimensionPanelComponent: (props: any) => (
domElement: Element,
operations: Operation[]
) => {},

removeColumnInTableSpec: (columnId: string) => [],
moveColumnTo: (columnId: string, targetIndex: number) => {},
duplicateColumn: (columnId: string) => [],
};
}

getDatasourceSuggestionsForField() {
return [];
}

getDatasourceSuggestionsFromCurrentState() {
return [];
}
}

export { IndexPatternDatasource };

export const indexPatternDatasource = new IndexPatternDatasource();
Loading

0 comments on commit 63c5b3c

Please sign in to comment.