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] Basic layouting #39587

Merged
merged 10 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export type ExpressionRendererProps = Pick<
* this callback is called with the given result.
*/
onRenderFailure?: (result: Result) => void;
className?: string;
};

export type ExpressionRenderer = React.FC<ExpressionRendererProps>;

export const createRenderer = (run: ExpressionRunner): ExpressionRenderer => ({
expression,
onRenderFailure,
className,
...options
}: ExpressionRendererProps) => {
const mountpoint: React.MutableRefObject<null | HTMLDivElement> = useRef(null);
Expand All @@ -63,6 +65,7 @@ export const createRenderer = (run: ExpressionRunner): ExpressionRenderer => ({

return (
<div
className={className}
ref={el => {
mountpoint.current = el;
}}
Expand Down
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
@@ -0,0 +1,73 @@
.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;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're adding overflow: hidden here, please also add a scrollbar to the data panel- without a scrollbar it's cutting off labels both horizontally and vertically.
Screenshot 2019-06-25 12 42 25


.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;
}
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
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 @@ -317,7 +318,7 @@ Object {
},
]);

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

instance.childAt(0).prop('onDrop')({
instance.find(DragDrop).prop('onDrop')!({
name: '@timestamp',
type: 'date',
searchable: false,
Expand All @@ -392,7 +393,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 @@ -137,6 +146,7 @@ export function WorkspacePanel({
} else {
return (
<ExpressionRendererComponent
className="lnsExpressionOutput"
expression={expression!}
onRenderFailure={(e: unknown) => {
setExpressionError(e);
Expand All @@ -147,8 +157,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
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
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>
);
}
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/lens/public/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

@import './drag_drop/drag_drop.scss';
@import './xy_visualization_plugin/xy_expression.scss';
@import './indexpattern_plugin/indexpattern';
@import './indexpattern_plugin/indexpattern';
@import './editor_frame_plugin/editor_frame/editor_frame.scss';
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),
});
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.lnsChart {
// TODO style this dependent on the screen height (see POC)
height: 500px;
height: 100%;
}