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

[Vis: Default editor] EUIficate and Reactify the sidebar #49864

Merged
merged 83 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
3a39ece
EUIficate the sidebar
sulemanof Oct 23, 2019
abb59f0
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Oct 29, 2019
fcd0c40
Create a state reducer and a state context
sulemanof Oct 31, 2019
c1bd92c
Create an editor context and actions
sulemanof Nov 1, 2019
d50871e
Improve types
sulemanof Nov 1, 2019
c8c4a85
Apply aggs reordering
sulemanof Nov 4, 2019
a691bd6
Fix functionality
sulemanof Nov 5, 2019
cb76cf0
Improve types
sulemanof Nov 6, 2019
62b7eb6
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 6, 2019
a46ec08
Fix sub_agg changes
sulemanof Nov 11, 2019
78b88bd
Remove legacy dependencies
sulemanof Nov 11, 2019
8041626
Watch dirty state
sulemanof Nov 11, 2019
4609e9c
Fix dirty state changes
sulemanof Nov 11, 2019
0afe33e
Update actions and reducers
sulemanof Nov 12, 2019
0b9ddc0
Handle keyboard submit
sulemanof Nov 12, 2019
78ccb5e
Apply editor form validation
sulemanof Nov 12, 2019
d6729ab
Remove fancy forms
sulemanof Nov 13, 2019
920374d
Update validation
sulemanof Nov 13, 2019
ad30aa8
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 13, 2019
a2adf55
Use embeddable instead of visualize loader
sulemanof Nov 14, 2019
39db9e6
Add auto apply behavior
sulemanof Nov 14, 2019
df6cd61
Remove legacy styles
sulemanof Nov 14, 2019
883a315
Remove the sidebar
sulemanof Nov 14, 2019
66400b4
Restrict responsive to the bottom_bar
sulemanof Nov 14, 2019
2cd86c5
Upgrade @elastic/eui to v14.10.0
sulemanof Nov 15, 2019
e586b2e
Replace EuiBottomBar with EuiControlBar
sulemanof Nov 15, 2019
e90f153
Get rid of mutations in control vis
sulemanof Nov 15, 2019
b1ec097
Revert "Upgrade @elastic/eui to v14.10.0"
sulemanof Nov 16, 2019
d743353
Replace bottom bar with a control panel for sidebar
sulemanof Nov 16, 2019
6a36ad9
Replace selectors
sulemanof Nov 18, 2019
6762f8b
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 19, 2019
b7909cd
Use editor resizer
sulemanof Nov 20, 2019
7dbf84e
Apply selectors
sulemanof Nov 20, 2019
8bc5ad1
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 20, 2019
989e80b
Change selectors
sulemanof Nov 20, 2019
48eb626
Fix sub agg change values
sulemanof Nov 21, 2019
b13b76c
Add collapse button
sulemanof Nov 22, 2019
c833615
Fix tests
sulemanof Nov 22, 2019
9f471bc
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 25, 2019
2ecca75
Get rid of editor editor_state_context, simplify the code
sulemanof Nov 25, 2019
32c49e1
Fix jest tests, update snapshots
sulemanof Nov 25, 2019
993d457
Fix types
sulemanof Nov 25, 2019
db4ad8c
Moving collapse button to right of index pattern
Nov 25, 2019
4aeff08
Tweaks bottom buttons
Nov 25, 2019
fd950d7
Moved Vega buttons so they don’t scroll away
Nov 25, 2019
c201f31
Fix responsiveness
Nov 25, 2019
46f71a0
Resolve UI comments
sulemanof Nov 26, 2019
262ac9a
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 26, 2019
06c5ab3
Fix console resizer
sulemanof Nov 26, 2019
9c1f2da
Update state handling
sulemanof Nov 27, 2019
d77c05a
Small fixes
sulemanof Nov 27, 2019
e30e2c0
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Nov 27, 2019
c1a78d6
Update imports
sulemanof Nov 27, 2019
c3798a6
Minor fixes
sulemanof Nov 28, 2019
4e73c47
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Dec 2, 2019
ebe0607
Revert changes
sulemanof Dec 2, 2019
ae7aa2a
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Dec 3, 2019
b00a939
Fix infinite render in rollup
sulemanof Dec 3, 2019
0090f96
Merge branch 'master' into EUIfication/sidebar
sulemanof Dec 16, 2019
9af7f93
Fix merge conflicts
sulemanof Dec 16, 2019
3fc4959
Fix styles
sulemanof Dec 16, 2019
3bfbaae
Minor fixes
sulemanof Dec 17, 2019
e01ec51
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Dec 20, 2019
3701228
Update input_control_vis_type due to merge conflicts
sulemanof Dec 20, 2019
239ab81
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Dec 23, 2019
2f6449d
Fix merge conflicts
sulemanof Dec 26, 2019
e965ad8
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Dec 26, 2019
8a82137
Fix types after shimming
sulemanof Dec 26, 2019
c0b0db9
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Dec 27, 2019
3f003a8
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Jan 9, 2020
d4e8eec
Fix merge conflicts in tests
sulemanof Jan 9, 2020
d695c1b
Fix tests
sulemanof Jan 9, 2020
67ab891
Update dev docs
sulemanof Jan 9, 2020
1b19809
Merge branch 'master' into EUIfication/sidebar
elasticmachine Jan 12, 2020
de027f5
Apply some memoizations
sulemanof Jan 13, 2020
590c967
Bail out of additional render in metrics and axes
sulemanof Jan 14, 2020
2d52c0d
Apply performance optimizations for metrics and axis panel
sulemanof Jan 14, 2020
84e874b
Fix comments
sulemanof Jan 14, 2020
b3c3422
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Jan 14, 2020
6ba4465
Remove unused translations
sulemanof Jan 15, 2020
9c895d1
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Jan 15, 2020
f9345c3
Use debounce when autoapply enabled
sulemanof Jan 15, 2020
f4a60ae
Merge remote-tracking branch 'upstream/master' into EUIfication/sidebar
sulemanof Jan 17, 2020
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 @@ -208,8 +208,8 @@ This is the sidebar editor you see in many of the Kibana visualizations. You can

[[development-default-editor]]
==== `default` editor controller
The default editor controller receives an `optionsTemplate` or `optionsTabs` parameter.
These can be either an AngularJS template or React component.
The default editor controller receives an `optionsTemplate` or `optionTabs` parameter.
These tabs should be React components.

["source","js"]
-----------
Expand All @@ -220,12 +220,9 @@ These can be either an AngularJS template or React component.
description: 'Cool new chart',
editor: 'default',
editorConfig: {
optionsTemplate: '<my-custom-options-directive></my-custom-options-directive>' // or
optionsTemplate: MyReactComponent // or if multiple tabs are required:
optionsTabs: [
{ title: 'tab 1', template: '<div>....</div> },
{ title: 'tab 2', template: '<my-custom-options-directive></my-custom-options-directive>' },
{ title: 'tab 3', template: MyReactComponent }
optionTabs: [
{ title: 'tab 3', editor: MyReactComponent }
]
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,28 @@
*/

import React from 'react';
import { EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

type ResizerMouseEvent = React.MouseEvent<HTMLDivElement, MouseEvent>;
export type ResizerMouseEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
export type ResizerKeyDownEvent = React.KeyboardEvent<HTMLButtonElement>;

export interface Props {
onKeyDown: (eve: ResizerKeyDownEvent) => void;
onMouseDown: (eve: ResizerMouseEvent) => void;
className?: string;
}

/**
* TODO: This component uses styling constants from public UI - should be removed, next iteration should incl. horizontal and vertical resizers.
*/
export function Resizer(props: Props) {
return (
<div {...props} className="conApp__resizer" data-test-subj="splitPanelResizer">
&#xFE19;
</div>
<button
{...props}
data-test-subj="splitPanelResizer"
aria-label={i18n.translate('console.splitPanel.adjustPanelSizeAriaLabel', {
defaultMessage: 'Press left/right to adjust panels size',
})}
>
<EuiIcon type="grabHorizontal" />
</button>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,26 @@ import { usePanelContext } from '../context';

export interface Props {
children: ReactNode[] | ReactNode;
initialWidth?: string;
className?: string;

/**
* initial width of the panel in percents
*/
initialWidth?: number;
style?: CSSProperties;
}

export function Panel({ children, initialWidth = '100%', style = {} }: Props) {
const [width, setWidth] = useState(initialWidth);
export function Panel({ children, className, initialWidth = 100, style = {} }: Props) {
const [width, setWidth] = useState(`${initialWidth}%`);
const { registry } = usePanelContext();
const divRef = useRef<HTMLDivElement>(null);

useEffect(() => {
registry.registerPanel({
initialWidth,
width: initialWidth,
setWidth(value) {
setWidth(value + '%');
this.width = value;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is super confusing - there is panel.width which relates to the last set width and there is panel.getWidth which returns the actual width of the dom element. Why do we need both?

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've added panel.width to handle the panel resizing with keyboard (simply increase or decrease on 1%). But resizing with the mouse has more calculations which need the actual size of panel in pixels.

},
getWidth() {
return divRef.current!.getBoundingClientRect().width;
Expand All @@ -44,7 +50,7 @@ export function Panel({ children, initialWidth = '100%', style = {} }: Props) {
}, [initialWidth, registry]);

return (
<div ref={divRef} style={{ ...style, width, display: 'flex' }}>
<div className={className} ref={divRef} style={{ ...style, width, display: 'flex' }}>
{children}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
* under the License.
*/

import React, { Children, ReactNode, useRef, useState } from 'react';
import React, { Children, ReactNode, useRef, useState, useCallback } from 'react';

import { keyCodes } from '@elastic/eui';
import { PanelContextProvider } from '../context';
import { Resizer } from '../components/resizer';
import { Resizer, ResizerMouseEvent, ResizerKeyDownEvent } from '../components/resizer';
import { PanelRegistry } from '../registry';

export interface Props {
children: ReactNode;
className?: string;
resizerClassName?: string;
onPanelWidthChange?: (arrayOfPanelWidths: number[]) => any;
}

Expand All @@ -37,7 +40,12 @@ const initialState: State = { isDragging: false, currentResizerPos: -1 };

const pxToPercent = (proportion: number, whole: number) => (proportion / whole) * 100;

export function PanelsContainer({ children, onPanelWidthChange }: Props) {
export function PanelsContainer({
children,
className,
onPanelWidthChange,
resizerClassName,
}: Props) {
const [firstChild, secondChild] = Children.toArray(children);

const registryRef = useRef(new PanelRegistry());
Expand All @@ -48,25 +56,56 @@ export function PanelsContainer({ children, onPanelWidthChange }: Props) {
return containerRef.current!.getBoundingClientRect().width;
};

const handleMouseDown = useCallback(
(event: ResizerMouseEvent) => {
setState({
...state,
isDragging: true,
currentResizerPos: event.clientX,
});
},
[state]
);

const handleKeyDown = useCallback(
(ev: ResizerKeyDownEvent) => {
const { keyCode } = ev;

if (keyCode === keyCodes.LEFT || keyCode === keyCodes.RIGHT) {
ev.preventDefault();

const { current: registry } = registryRef;
const [left, right] = registry.getPanels();

const leftPercent = left.width - (keyCode === keyCodes.LEFT ? 1 : -1);
const rightPercent = right.width - (keyCode === keyCodes.RIGHT ? 1 : -1);

left.setWidth(leftPercent);
right.setWidth(rightPercent);

if (onPanelWidthChange) {
onPanelWidthChange([leftPercent, rightPercent]);
}
}
},
[onPanelWidthChange]
);

const childrenWithResizer = [
firstChild,
<Resizer
key={'resizer'}
onMouseDown={event => {
event.preventDefault();
setState({
...state,
isDragging: true,
currentResizerPos: event.clientX,
});
}}
className={resizerClassName}
onKeyDown={handleKeyDown}
onMouseDown={handleMouseDown}
/>,
secondChild,
];

return (
<PanelContextProvider registry={registryRef.current}>
<div
className={className}
ref={containerRef}
style={{ display: 'flex', height: '100%', width: '100%' }}
onMouseMove={event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
export interface PanelController {
setWidth: (percent: number) => void;
getWidth: () => number;
initialWidth: string;
width: number;
}

export class PanelRegistry {
Expand All @@ -35,6 +35,6 @@ export class PanelRegistry {
}

getPanels() {
return this.panels.map(panel => ({ ...panel }));
return this.panels;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ describe('Split panel', () => {

const panelContainer = mount(
<PanelsContainer onPanelWidthChange={onWidthChange}>
<Panel initialWidth={'50%'}>{testComponentA}</Panel>
<Panel initialWidth={'50%'}>{testComponentB}</Panel>
<Panel initialWidth={50}>{testComponentA}</Panel>
<Panel initialWidth={50}>{testComponentB}</Panel>
</PanelsContainer>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ export const Editor = ({ loading }: Props) => {
if (!currentTextObject) return null;

return (
<PanelsContainer onPanelWidthChange={onPanelWidthChange}>
<PanelsContainer onPanelWidthChange={onPanelWidthChange} resizerClassName="conApp__resizer">
<Panel
style={{ height: '100%', position: 'relative', minWidth: PANEL_MIN_WIDTH }}
initialWidth={firstPanelWidth + '%'}
initialWidth={firstPanelWidth}
>
{loading ? (
<EditorContentSpinner />
Expand All @@ -68,7 +68,7 @@ export const Editor = ({ loading }: Props) => {
</Panel>
<Panel
style={{ height: '100%', position: 'relative', minWidth: PANEL_MIN_WIDTH }}
initialWidth={secondPanelWidth + '%'}
initialWidth={secondPanelWidth}
>
{loading ? <EditorContentSpinner /> : <EditorOutput />}
</Panel>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading