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] Remove <NativeRenderer /> #161521

Merged
merged 3 commits into from
Jul 11, 2023
Merged
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
3 changes: 0 additions & 3 deletions x-pack/examples/third_party_vis_lens_example/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"developerExamples",
"expressions",
"fieldFormats"
],
"requiredBundles": [
"kibanaReact"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

import React from 'react';
import { EuiFormRow, EuiColorPicker } from '@elastic/eui';
import { render } from 'react-dom';
import { Ast } from '@kbn/interpreter';
import { ThemeServiceStart } from '@kbn/core/public';
import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { Visualization, OperationMetadata } from '@kbn/lens-plugin/public';
import { layerTypes } from '@kbn/lens-plugin/public';
import type { RotatingNumberState } from '../common/types';
Expand Down Expand Up @@ -166,19 +164,16 @@ export const getRotatingNumberVisualization = ({
return { ...prevState, accessor: undefined };
},

renderDimensionEditor(domElement, props) {
render(
<KibanaThemeProvider theme$={theme.theme$}>
<EuiFormRow label="Pick a color">
<EuiColorPicker
onChange={(newColor) => {
props.setState({ ...props.state, color: newColor });
}}
color={props.state.color}
/>
</EuiFormRow>
</KibanaThemeProvider>,
domElement
DimensionEditorComponent(props) {
return (
<EuiFormRow label="Pick a color">
<EuiColorPicker
onChange={(newColor) => {
props.setState({ ...props.state, color: newColor });
}}
color={props.state.color}
/>
</EuiFormRow>
);
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"kbn_references": [
"@kbn/core",
"@kbn/expressions-plugin",
"@kbn/kibana-react-plugin",
"@kbn/data-views-plugin",
"@kbn/field-formats-plugin",
"@kbn/lens-plugin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ describe('LensEditConfigurationFlyout', () => {
const { instance } = await prepareAndMountComponent(props);
expect(instance.find(VisualizationToolbar).prop('activeVisualization')).toMatchInlineSnapshot(`
Object {
"DimensionEditorComponent": [MockFunction],
"appendLayer": [MockFunction],
"clearLayer": [MockFunction],
"getConfiguration": [MockFunction] {
Expand Down Expand Up @@ -414,7 +415,6 @@ describe('LensEditConfigurationFlyout', () => {
"initialize": [MockFunction],
"removeDimension": [MockFunction],
"removeLayer": [MockFunction],
"renderDimensionEditor": [MockFunction],
"setDimension": [MockFunction],
"switchVisualizationType": [MockFunction],
"toExpression": [MockFunction],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { createMockedDragDropContext } from '../../mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import {
dataViewPluginMocks,
Expand Down Expand Up @@ -408,9 +407,6 @@ describe('FormBased Data Panel', () => {
dataViews,
}),
setState: jest.fn(),
dragDropContext: createMockedDragDropContext({
dragging: { id: '1', humanData: { label: 'Label' } },
}),
dateRange: { fromDate: '2019-01-01', toDate: '2020-01-01' },
frame: getFrameAPIMock({
indexPatterns: indexPatterns as unknown as DataViewsState['indexPatterns'],
Expand Down
209 changes: 49 additions & 160 deletions x-pack/plugins/lens/public/datasources/form_based/form_based.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/

import React from 'react';
import { render } from 'react-dom';
import { I18nProvider } from '@kbn/i18n-react';
import type { CoreStart, SavedObjectReference } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { TimeRange } from '@kbn/es-query';
Expand All @@ -16,7 +14,6 @@ import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import { flatten, isEqual } from 'lodash';
import type { DataViewsPublicPluginStart, DataView } from '@kbn/data-views-plugin/public';
import type { IndexPatternFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public';
import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public';
import { DataPublicPluginStart, UI_SETTINGS } from '@kbn/data-plugin/public';
import { VisualizeFieldContext } from '@kbn/ui-actions-plugin/public';
import { ChartsPluginSetup } from '@kbn/charts-plugin/public';
Expand All @@ -25,7 +22,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public';
import { EuiButton } from '@elastic/eui';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import { ChildDragDropProvider, type DraggingIdentifier } from '@kbn/dom-drag-drop';
import { type DraggingIdentifier } from '@kbn/dom-drag-drop';
import { DimensionTrigger } from '@kbn/visualization-ui-components/public';
import memoizeOne from 'memoize-one';
import type {
Expand Down Expand Up @@ -191,7 +188,7 @@ export function getFormBasedDatasource({
dataViewFieldEditor: IndexPatternFieldEditorStart;
uiActions: UiActionsStart;
}) {
const { uiSettings, settings } = core;
const { uiSettings } = core;

const DATASOURCE_ID = 'formBased';
const ALIAS_IDS = ['indexpattern'];
Expand Down Expand Up @@ -452,68 +449,27 @@ export function getFormBasedDatasource({
searchSessionId
),

renderLayerSettings(domElement, props) {
render(
<KibanaThemeProvider theme$={core.theme.theme$}>
<I18nProvider>
<KibanaContextProvider
services={{
...core,
data,
dataViews,
fieldFormats,
charts,
unifiedSearch,
share,
}}
>
<LayerSettingsPanel {...props} />
</KibanaContextProvider>
</I18nProvider>
</KibanaThemeProvider>,
domElement
);
LayerSettingsComponent(props) {
return <LayerSettingsPanel {...props} />;
},

renderDataPanel(domElement: Element, props: DatasourceDataPanelProps<FormBasedPrivateState>) {
const { onChangeIndexPattern, dragDropContext, ...otherProps } = props;
DataPanelComponent(props: DatasourceDataPanelProps<FormBasedPrivateState>) {
const { onChangeIndexPattern, ...otherProps } = props;
const layerFields = formBasedDatasource?.getSelectedFields?.(props.state);

render(
<KibanaThemeProvider theme$={core.theme.theme$}>
<I18nProvider>
<KibanaContextProvider
services={{
...core,
data,
dataViews,
fieldFormats,
charts,
unifiedSearch,
share,
}}
>
<ChildDragDropProvider value={dragDropContext}>
<FormBasedDataPanel
data={data}
dataViews={dataViews}
fieldFormats={fieldFormats}
charts={charts}
indexPatternFieldEditor={dataViewFieldEditor}
{...otherProps}
core={core}
uiActions={uiActions}
onIndexPatternRefresh={onRefreshIndexPattern}
layerFields={layerFields}
/>
</ChildDragDropProvider>
</KibanaContextProvider>
</I18nProvider>
</KibanaThemeProvider>,
domElement
return (
<FormBasedDataPanel
data={data}
dataViews={dataViews}
fieldFormats={fieldFormats}
charts={charts}
indexPatternFieldEditor={dataViewFieldEditor}
{...otherProps}
core={core}
uiActions={uiActions}
onIndexPatternRefresh={onRefreshIndexPattern}
layerFields={layerFields}
/>
);
},

uniqueLabels(state: FormBasedPrivateState, indexPatternsMap: IndexPatternMap) {
const layers = state.layers;
const columnLabelMap = {} as Record<string, string>;
Expand All @@ -540,115 +496,48 @@ export function getFormBasedDatasource({
return columnLabelMap;
},

renderDimensionTrigger: (
domElement: Element,
props: DatasourceDimensionTriggerProps<FormBasedPrivateState>
) => {
DimensionTriggerComponent: (props: DatasourceDimensionTriggerProps<FormBasedPrivateState>) => {
const columnLabelMap = formBasedDatasource.uniqueLabels(props.state, props.indexPatterns);
const uniqueLabel = columnLabelMap[props.columnId];
const formattedLabel = wrapOnDot(uniqueLabel);

render(
<KibanaThemeProvider theme$={core.theme.theme$}>
<I18nProvider>
<KibanaContextProvider
services={{
appName: 'lens',
storage,
uiSettings,
settings,
data,
fieldFormats,
savedObjects: core.savedObjects,
docLinks: core.docLinks,
unifiedSearch,
}}
>
<DimensionTrigger id={props.columnId} label={formattedLabel} />
</KibanaContextProvider>
</I18nProvider>
</KibanaThemeProvider>,
domElement
);
return <DimensionTrigger id={props.columnId} label={formattedLabel} />;
},

renderDimensionEditor: (
domElement: Element,
props: DatasourceDimensionEditorProps<FormBasedPrivateState>
) => {
DimensionEditorComponent: (props: DatasourceDimensionEditorProps<FormBasedPrivateState>) => {
const columnLabelMap = formBasedDatasource.uniqueLabels(props.state, props.indexPatterns);

render(
<KibanaThemeProvider theme$={core.theme.theme$}>
<I18nProvider>
<KibanaContextProvider
services={{
appName: 'lens',
storage,
uiSettings,
settings,
data,
fieldFormats,
savedObjects: core.savedObjects,
docLinks: core.docLinks,
http: core.http,
unifiedSearch,
}}
>
<FormBasedDimensionEditor
uiSettings={uiSettings}
storage={storage}
fieldFormats={fieldFormats}
http={core.http}
data={data}
unifiedSearch={unifiedSearch}
dataViews={dataViews}
uniqueLabel={columnLabelMap[props.columnId]}
notifications={core.notifications}
{...props}
/>
</KibanaContextProvider>
</I18nProvider>
</KibanaThemeProvider>,
domElement
return (
<FormBasedDimensionEditor
uiSettings={uiSettings}
storage={storage}
fieldFormats={fieldFormats}
http={core.http}
data={data}
unifiedSearch={unifiedSearch}
dataViews={dataViews}
uniqueLabel={columnLabelMap[props.columnId]}
notifications={core.notifications}
{...props}
/>
);
},

renderLayerPanel: (
domElement: Element,
props: DatasourceLayerPanelProps<FormBasedPrivateState>
) => {
LayerPanelComponent: (props: DatasourceLayerPanelProps<FormBasedPrivateState>) => {
const { onChangeIndexPattern, ...otherProps } = props;
render(
<KibanaThemeProvider theme$={core.theme.theme$}>
<I18nProvider>
<KibanaContextProvider
services={{
...core,
data,
dataViews,
fieldFormats,
charts,
unifiedSearch,
share,
}}
>
<LayerPanel
onChangeIndexPattern={(indexPatternId) => {
triggerActionOnIndexPatternChange({
indexPatternId,
state: props.state,
layerId: props.layerId,
uiActions,
});
onChangeIndexPattern(indexPatternId, DATASOURCE_ID, props.layerId);
}}
{...otherProps}
/>
</KibanaContextProvider>
</I18nProvider>
</KibanaThemeProvider>,
domElement
return (
<LayerPanel
onChangeIndexPattern={(indexPatternId) => {
triggerActionOnIndexPatternChange({
indexPatternId,
state: props.state,
layerId: props.layerId,
uiActions,
});
onChangeIndexPattern(indexPatternId, DATASOURCE_ID, props.layerId);
}}
{...otherProps}
/>
);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';

import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { createIndexPatternServiceMock } from '../../mocks/data_views_service_mock';
import { createMockFramePublicAPI, createMockedDragDropContext } from '../../mocks';
import { createMockFramePublicAPI } from '../../mocks';
import { DataViewsState } from '../../state_management';

const fieldsFromQuery = [
Expand Down Expand Up @@ -184,7 +184,6 @@ describe('TextBased Query Languages Data Panel', () => {
])
),
},
dragDropContext: createMockedDragDropContext(),
core,
dateRange: {
fromDate: 'now-7d',
Expand Down
Loading