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] Implement basic editor frame state handling #36443

Merged
merged 35 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6d6f304
add nativerenderer component
flash1293 May 7, 2019
44894df
use native renderer in app and editor frame
flash1293 May 7, 2019
943fca8
remove prop types
flash1293 May 7, 2019
731e264
add unit test and fix linting issues
flash1293 May 8, 2019
cc1a0db
rename test suite
flash1293 May 8, 2019
18f9d83
rename prop and adjust shallow comparison function
flash1293 May 9, 2019
60cd891
add documentation
flash1293 May 9, 2019
0eb1f31
move native renderer to top level directory
flash1293 May 9, 2019
0f652c3
Merge remote-tracking branch 'upstream/feature/lens' into lens/native…
flash1293 May 10, 2019
a21b0ea
add test, fix linting error and improve shallow equal comparison
flash1293 May 10, 2019
34e9328
Merge remote-tracking branch 'upstream/feature/lens' into lens/native…
flash1293 May 10, 2019
b124f88
Merge branch 'feature/lens' into lens/native-renderer
flash1293 May 10, 2019
36de942
Implement basic editor frame state handling
wylieconlon May 3, 2019
7445372
Merge remote-tracking branch 'upstream/feature/lens' into lens/native…
flash1293 May 10, 2019
0395e9a
Merge branch 'feature/lens' into lens/editor-state
flash1293 May 10, 2019
8147aaa
fix linting errors
flash1293 May 10, 2019
4baf6b1
fix native renderer tests
flash1293 May 10, 2019
d33576e
Merge branch 'lens/native-renderer' into lens/editor-state
flash1293 May 10, 2019
033a632
re structure editor frame
flash1293 May 10, 2019
345e20f
fix tests
flash1293 May 10, 2019
48203dd
move layout to a separate component
flash1293 May 10, 2019
dece47f
Merge remote-tracking branch 'upstream/feature/lens' into lens/native…
flash1293 May 12, 2019
7469315
Merge branch 'lens/native-renderer' into lens/editor-state
flash1293 May 12, 2019
ee6fdbc
clean up and improve typings
flash1293 May 12, 2019
396cf1c
add tests for plugin itself
flash1293 May 12, 2019
5a21a43
Merge branch 'feature/lens' into lens/native-renderer
flash1293 May 12, 2019
c383c3e
Merge branch 'lens/native-renderer' into lens/editor-state
flash1293 May 12, 2019
d776b54
Merge branch 'feature/lens' into lens/editor-state
flash1293 May 20, 2019
f05024b
resolve conflicts
flash1293 May 20, 2019
fe1356e
Merge branch 'feature/lens' into lens/editor-state
flash1293 May 21, 2019
a562914
Merge branch 'feature/lens' into lens/editor-state
flash1293 May 21, 2019
3d055ee
adress review and restructure state
flash1293 May 21, 2019
7c3a2c8
align naming
flash1293 May 21, 2019
849f3a1
add comment
flash1293 May 21, 2019
21c8756
only save single visualization state
flash1293 May 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions x-pack/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import { I18nProvider } from '@kbn/i18n/react';
import React from 'react';

import { EditorFrameSetup } from '../types';
import { EditorFrameInstance } from '../types';
import { NativeRenderer } from '../native_renderer';

export function App({ editorFrame }: { editorFrame: EditorFrameSetup }) {
export function App({ editorFrame }: { editorFrame: EditorFrameInstance }) {
return (
<I18nProvider>
<div>
<h1>Lens</h1>

<NativeRenderer render={editorFrame.render} nativeProps={undefined} />
<NativeRenderer render={editorFrame.mount} nativeProps={undefined} />
</div>
</I18nProvider>
);
Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/lens/public/app_plugin/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { editorFrameSetup, editorFrameStop } from '../editor_frame_plugin';
import { indexPatternDatasourceSetup, indexPatternDatasourceStop } from '../indexpattern_plugin';
import { xyVisualizationSetup, xyVisualizationStop } from '../xy_visualization_plugin';
import { App } from './app';
import { EditorFrameInstance } from '../types';

export class AppPlugin {
private instance: EditorFrameInstance | null = null;

constructor() {}

setup() {
Expand All @@ -23,10 +26,17 @@ export class AppPlugin {
editorFrame.registerDatasource('indexpattern', indexPattern);
editorFrame.registerVisualization('xy', xyVisualization);

return <App editorFrame={editorFrame} />;
this.instance = editorFrame.createInstance({});

return <App editorFrame={this.instance} />;
}

stop() {
if (this.instance) {
this.instance.unmount();
}

// TODO this will be handled by the plugin platform itself
indexPatternDatasourceStop();
xyVisualizationStop();
editorFrameStop();
Expand Down
118 changes: 0 additions & 118 deletions x-pack/plugins/lens/public/editor_frame_plugin/editor_frame.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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, { useMemo } from 'react';
import { EuiSelect } from '@elastic/eui';
import { NativeRenderer } from '../../native_renderer';
import { Action } from './state_management';
import { Visualization, DatasourcePublicAPI } from '../../types';

interface ConfigPanelWrapperProps {
visualizationState: unknown;
visualizationMap: Record<string, Visualization>;
activeVisualizationId: string | null;
dispatch: (action: Action) => void;
datasourcePublicAPI: DatasourcePublicAPI;
}

export function ConfigPanelWrapper(props: ConfigPanelWrapperProps) {
const setVisualizationState = useMemo(
() => (newState: unknown) => {
props.dispatch({
type: 'UPDATE_VISUALIZATION_STATE',
newState,
});
},
[props.dispatch]
);

return (
<>
<EuiSelect
data-test-subj="visualization-switch"
options={Object.keys(props.visualizationMap).map(visualizationId => ({
value: visualizationId,
text: visualizationId,
}))}
value={props.activeVisualizationId || undefined}
onChange={e => {
props.dispatch({
type: 'SWITCH_VISUALIZATION',
newVisualizationId: e.target.value,
// TODO we probably want to have a separate API to "force" a visualization switch
// which isn't a result of a picked suggestion
initialState: props.visualizationMap[e.target.value].initialize(),
});
}}
/>
{props.activeVisualizationId && (
<NativeRenderer
render={props.visualizationMap[props.activeVisualizationId].renderConfigPanel}
nativeProps={{
state: props.visualizationState,
setState: setVisualizationState,
datasource: props.datasourcePublicAPI,
}}
/>
)}
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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, { useMemo } from 'react';
import { EuiSelect } from '@elastic/eui';
import { DatasourceDataPanelProps, Datasource } from '../..';
import { NativeRenderer } from '../../native_renderer';
import { Action } from './state_management';

interface DataPanelWrapperProps {
datasourceState: unknown;
datasourceMap: Record<string, Datasource>;
activeDatasource: string | null;
datasourceIsLoading: boolean;
dispatch: (action: Action) => void;
}

export function DataPanelWrapper(props: DataPanelWrapperProps) {
const setDatasourceState = useMemo(
() => (newState: unknown) => {
props.dispatch({
type: 'UPDATE_DATASOURCE_STATE',
newState,
});
},
[props.dispatch]
);

const datasourceProps: DatasourceDataPanelProps = {
state: props.datasourceState,
setState: setDatasourceState,
};

return (
<>
<EuiSelect
data-test-subj="datasource-switch"
options={Object.keys(props.datasourceMap).map(datasourceId => ({
value: datasourceId,
text: datasourceId,
}))}
value={props.activeDatasource || undefined}
onChange={e => {
props.dispatch({ type: 'SWITCH_DATASOURCE', newDatasourceId: e.target.value });
}}
/>
{props.activeDatasource && !props.datasourceIsLoading && (
<NativeRenderer
render={props.datasourceMap[props.activeDatasource].renderDataPanel}
nativeProps={datasourceProps}
/>
)}
</>
);
}