Skip to content
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
6 changes: 1 addition & 5 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import { NativeRenderer } from '../native_renderer';
export function App({ editorFrame }: { editorFrame: EditorFrameInstance }) {
return (
<I18nProvider>
<div>
<h1>Lens</h1>

<NativeRenderer render={editorFrame.mount} nativeProps={undefined} />
</div>
<NativeRenderer className="lnsPage" render={editorFrame.mount} nativeProps={undefined} />
</I18nProvider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiPage, EuiPageSideBar, EuiPageBody } from '@elastic/eui';
import { RootDragDropProvider } from '../../drag_drop';

export interface FrameLayoutProps {
Expand All @@ -18,15 +18,16 @@ export interface FrameLayoutProps {
export function FrameLayout(props: FrameLayoutProps) {
return (
<RootDragDropProvider>
<EuiFlexGroup>
{/* TODO style this and add workspace prop and loading flags */}
<EuiFlexItem grow={null}>{props.dataPanel}</EuiFlexItem>
<EuiFlexItem grow={5}>{props.workspacePanel}</EuiFlexItem>
<EuiFlexItem grow={null}>
<EuiPage className="lnsPage">
<EuiPageSideBar className="lnsSidebar">{props.dataPanel}</EuiPageSideBar>
<EuiPageBody className="lnsPageBody" restrictWidth={false}>
{props.workspacePanel}
</EuiPageBody>
<EuiPageSideBar className="lnsSidebar lnsSidebar--right">
{props.configPanel}
{props.suggestionsPanel}
</EuiFlexItem>
</EuiFlexGroup>
</EuiPageSideBar>
</EuiPage>
</RootDragDropProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,76 @@
@import './workspace_panel.scss';

.lnsPage {
padding: 0;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
}

.lnsSidebar {
@include euiScrollBar;
overflow: hidden auto;
padding: $euiSize;
margin: 0;
flex: 1 0 18%;
min-width: ($euiSize * 16);
height: 100%;
display: flex;
flex-direction: column;
}

.lnsSidebar--right {
min-width: ($euiSize * 18);
}

.lnsPageBody {
@include euiScrollBar;
padding-top: $euiSize;
padding-bottom: $euiSize;
overflow: hidden auto;

&:first-child {
padding-left: $euiSize;
}

.lnsPageContent {
padding: 0;
display: flex;
flex-direction: column;

.lnsPageContentHeader {
padding: $euiSize;
border-bottom: $euiBorderThin;
margin-bottom: 0;
}

.lnsPageContentBody {
flex-grow: 1;
padding: $euiSizeXL;
display: flex;
align-items: stretch;
justify-content: stretch;

> * {
flex: 1 1 100%;
display: flex;
align-items: center;
justify-content: center;
overflow-x: hidden;
}
}
}
}

.lnsExpressionOutput {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
overflow-x: hidden;
}

@import './suggestion_panel.scss';

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { WorkspacePanel, WorkspacePanelProps } from './workspace_panel';
import { mountWithIntl as mount } from 'test_utils/enzyme_helpers';
import { ReactWrapper } from 'enzyme';
import { DragDrop } from '../../drag_drop';

const waitForPromises = () => new Promise(resolve => setTimeout(resolve));

Expand Down Expand Up @@ -318,7 +319,7 @@ Object {
},
]);

instance.childAt(0).prop('onDrop')({
instance.find(DragDrop).prop('onDrop')!({
name: '@timestamp',
type: 'date',
searchable: false,
Expand Down Expand Up @@ -378,7 +379,7 @@ Object {
},
]);

instance.childAt(0).prop('onDrop')({
instance.find(DragDrop).prop('onDrop')!({
name: '@timestamp',
type: 'date',
searchable: false,
Expand All @@ -396,7 +397,7 @@ Object {
});

it("should do nothing when the visualization can't use the suggestions", () => {
instance.childAt(0).prop('onDrop')({
instance.find(DragDrop).prop('onDrop')!({
name: '@timestamp',
type: 'date',
searchable: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useState, useEffect, useMemo } from 'react';
import React, { useState, useEffect, useMemo, useContext } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCodeBlock, EuiSpacer } from '@elastic/eui';
import {
EuiCodeBlock,
EuiSpacer,
EuiPageContent,
EuiPageContentHeader,
EuiPageContentHeaderSection,
EuiTitle,
EuiPageContentBody,
} from '@elastic/eui';

import { toExpression } from '@kbn/interpreter/common';
import { ExpressionRenderer } from '../../../../../../../src/legacy/core_plugins/data/public';
import { Action } from './state_management';
import { Datasource, Visualization, DatasourcePublicAPI } from '../../types';
import { DragDrop } from '../../drag_drop';
import { DragDrop, DragContext } from '../../drag_drop';
import { getSuggestions, toSwitchAction } from './suggestion_helpers';
import { buildExpression } from './expression_helpers';

Expand All @@ -37,6 +45,7 @@ export function WorkspacePanel({
dispatch,
ExpressionRenderer: ExpressionRendererComponent,
}: WorkspacePanelProps) {
const dragDropContext = useContext(DragContext);
function onDrop(item: unknown) {
const datasourceSuggestions = activeDatasource.getDatasourceSuggestionsForField(
datasourceState,
Expand Down Expand Up @@ -138,7 +147,7 @@ export function WorkspacePanel({
} else {
return (
<ExpressionRendererComponent
className="lnsChartWrapper"
className="lnsExpressionOutput"
expression={expression!}
onRenderFailure={(e: unknown) => {
setExpressionError(e);
Expand All @@ -149,8 +158,19 @@ export function WorkspacePanel({
}

return (
<DragDrop draggable={false} droppable={true} onDrop={onDrop}>
{renderVisualization()}
</DragDrop>
<EuiPageContent className="lnsPageContent">
<EuiPageContentHeader className="lnsPageContentHeader">
<EuiPageContentHeaderSection>
<EuiTitle size="xs">
<h2>New Visualization</h2>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text should be localized.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m waiting for your save/load PR here, @chrisdavies As soon as that one is merged, we can show the actual name instead

</EuiTitle>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiPageContentBody className="lnsPageContentBody">
<DragDrop draggable={false} droppable={Boolean(dragDropContext.dragging)} onDrop={onDrop}>
{renderVisualization()}
</DragDrop>
</EuiPageContentBody>
</EuiPageContent>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ describe('native_renderer', () => {
expect(containerElement.nodeName).toBe('DIV');
});

it('should pass regular html attributes to the wrapping element', () => {
const renderSpy = jest.fn();
const testProps = { a: 'abc' };

renderAndTriggerHooks(
<NativeRenderer
render={renderSpy}
nativeProps={testProps}
className="testClass"
data-test-subj="container"
/>,
mountpoint
);
const containerElement: HTMLElement = mountpoint.firstElementChild! as HTMLElement;
expect(containerElement.className).toBe('testClass');
expect(containerElement.dataset.testSubj).toBe('container');
});

it('should render a specified element as container', () => {
const renderSpy = jest.fn();
const testProps = { a: 'abc' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import React, { HTMLAttributes } from 'react';

export interface NativeRendererProps<T> {
export interface NativeRendererProps<T> extends HTMLAttributes<HTMLDivElement> {
render: (domElement: Element, props: T) => void;
nativeProps: T;
tag?: string;
Expand All @@ -20,8 +20,9 @@ export interface NativeRendererProps<T> {
*
* @param props
*/
export function NativeRenderer<T>({ render, nativeProps, tag }: NativeRendererProps<T>) {
export function NativeRenderer<T>({ render, nativeProps, tag, ...rest }: NativeRendererProps<T>) {
return React.createElement(tag || 'div', {
...rest,
ref: el => el && render(el, nativeProps),
});
}