Skip to content

Commit 3e46060

Browse files
sulemanofcchaoselasticmachine
authored
[Vis: Default editor] EUIficate and Reactify the sidebar (#49864)
* EUIficate the sidebar * Create a state reducer and a state context * Create an editor context and actions * Improve types * Apply aggs reordering * Fix functionality * Improve types * Fix sub_agg changes * Remove legacy dependencies * Watch dirty state * Fix dirty state changes * Update actions and reducers * Handle keyboard submit * Apply editor form validation * Remove fancy forms * Update validation * Use embeddable instead of visualize loader * Add auto apply behavior * Remove legacy styles * Remove the sidebar * Restrict responsive to the bottom_bar * Upgrade @elastic/eui to v14.10.0 * Replace EuiBottomBar with EuiControlBar * Get rid of mutations in control vis * Revert "Upgrade @elastic/eui to v14.10.0" This reverts commit 2cd86c5. * Replace bottom bar with a control panel for sidebar * Replace selectors * Use editor resizer * Apply selectors * Change selectors * Fix sub agg change values * Add collapse button * Fix tests * Get rid of editor editor_state_context, simplify the code * Fix jest tests, update snapshots * Fix types * Moving collapse button to right of index pattern * Tweaks bottom buttons * Moved Vega buttons so they don’t scroll away * Fix responsiveness * Resolve UI comments * Fix console resizer * Update dev docs * Bail out of additional render in metrics and axes * Apply performance optimizations for metrics and axis panel * Remove unused translations * Use debounce when autoapply enabled Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 92b5f78 commit 3e46060

File tree

115 files changed

+2218
-2206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+2218
-2206
lines changed

docs/developer/visualize/development-create-visualization.asciidoc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ This is the sidebar editor you see in many of the Kibana visualizations. You can
208208

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

214214
["source","js"]
215215
-----------
@@ -220,12 +220,9 @@ These can be either an AngularJS template or React component.
220220
description: 'Cool new chart',
221221
editor: 'default',
222222
editorConfig: {
223-
optionsTemplate: '<my-custom-options-directive></my-custom-options-directive>' // or
224223
optionsTemplate: MyReactComponent // or if multiple tabs are required:
225-
optionsTabs: [
226-
{ title: 'tab 1', template: '<div>....</div> },
227-
{ title: 'tab 2', template: '<my-custom-options-directive></my-custom-options-directive>' },
228-
{ title: 'tab 3', template: MyReactComponent }
224+
optionTabs: [
225+
{ title: 'tab 3', editor: MyReactComponent }
229226
]
230227
}
231228
}

src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/__snapshots__/split_panel.test.tsx.snap

Lines changed: 30 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/components/resizer.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@
1818
*/
1919

2020
import React from 'react';
21+
import { EuiIcon } from '@elastic/eui';
22+
import { i18n } from '@kbn/i18n';
2123

22-
type ResizerMouseEvent = React.MouseEvent<HTMLDivElement, MouseEvent>;
24+
export type ResizerMouseEvent = React.MouseEvent<HTMLButtonElement, MouseEvent>;
25+
export type ResizerKeyDownEvent = React.KeyboardEvent<HTMLButtonElement>;
2326

2427
export interface Props {
28+
onKeyDown: (eve: ResizerKeyDownEvent) => void;
2529
onMouseDown: (eve: ResizerMouseEvent) => void;
30+
className?: string;
2631
}
2732

28-
/**
29-
* TODO: This component uses styling constants from public UI - should be removed, next iteration should incl. horizontal and vertical resizers.
30-
*/
3133
export function Resizer(props: Props) {
3234
return (
33-
<div {...props} className="conApp__resizer" data-test-subj="splitPanelResizer">
34-
&#xFE19;
35-
</div>
35+
<button
36+
{...props}
37+
data-test-subj="splitPanelResizer"
38+
aria-label={i18n.translate('console.splitPanel.adjustPanelSizeAriaLabel', {
39+
defaultMessage: 'Press left/right to adjust panels size',
40+
})}
41+
>
42+
<EuiIcon type="grabHorizontal" />
43+
</button>
3644
);
3745
}

src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/containers/panel.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,26 @@ import { usePanelContext } from '../context';
2222

2323
export interface Props {
2424
children: ReactNode[] | ReactNode;
25-
initialWidth?: string;
25+
className?: string;
26+
27+
/**
28+
* initial width of the panel in percents
29+
*/
30+
initialWidth?: number;
2631
style?: CSSProperties;
2732
}
2833

29-
export function Panel({ children, initialWidth = '100%', style = {} }: Props) {
30-
const [width, setWidth] = useState(initialWidth);
34+
export function Panel({ children, className, initialWidth = 100, style = {} }: Props) {
35+
const [width, setWidth] = useState(`${initialWidth}%`);
3136
const { registry } = usePanelContext();
3237
const divRef = useRef<HTMLDivElement>(null);
3338

3439
useEffect(() => {
3540
registry.registerPanel({
36-
initialWidth,
41+
width: initialWidth,
3742
setWidth(value) {
3843
setWidth(value + '%');
44+
this.width = value;
3945
},
4046
getWidth() {
4147
return divRef.current!.getBoundingClientRect().width;
@@ -44,7 +50,7 @@ export function Panel({ children, initialWidth = '100%', style = {} }: Props) {
4450
}, [initialWidth, registry]);
4551

4652
return (
47-
<div ref={divRef} style={{ ...style, width, display: 'flex' }}>
53+
<div className={className} ref={divRef} style={{ ...style, width, display: 'flex' }}>
4854
{children}
4955
</div>
5056
);

src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/containers/panel_container.tsx

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
* under the License.
1818
*/
1919

20-
import React, { Children, ReactNode, useRef, useState } from 'react';
20+
import React, { Children, ReactNode, useRef, useState, useCallback } from 'react';
2121

22+
import { keyCodes } from '@elastic/eui';
2223
import { PanelContextProvider } from '../context';
23-
import { Resizer } from '../components/resizer';
24+
import { Resizer, ResizerMouseEvent, ResizerKeyDownEvent } from '../components/resizer';
2425
import { PanelRegistry } from '../registry';
2526

2627
export interface Props {
2728
children: ReactNode;
29+
className?: string;
30+
resizerClassName?: string;
2831
onPanelWidthChange?: (arrayOfPanelWidths: number[]) => any;
2932
}
3033

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

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

40-
export function PanelsContainer({ children, onPanelWidthChange }: Props) {
43+
export function PanelsContainer({
44+
children,
45+
className,
46+
onPanelWidthChange,
47+
resizerClassName,
48+
}: Props) {
4149
const [firstChild, secondChild] = Children.toArray(children);
4250

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

59+
const handleMouseDown = useCallback(
60+
(event: ResizerMouseEvent) => {
61+
setState({
62+
...state,
63+
isDragging: true,
64+
currentResizerPos: event.clientX,
65+
});
66+
},
67+
[state]
68+
);
69+
70+
const handleKeyDown = useCallback(
71+
(ev: ResizerKeyDownEvent) => {
72+
const { keyCode } = ev;
73+
74+
if (keyCode === keyCodes.LEFT || keyCode === keyCodes.RIGHT) {
75+
ev.preventDefault();
76+
77+
const { current: registry } = registryRef;
78+
const [left, right] = registry.getPanels();
79+
80+
const leftPercent = left.width - (keyCode === keyCodes.LEFT ? 1 : -1);
81+
const rightPercent = right.width - (keyCode === keyCodes.RIGHT ? 1 : -1);
82+
83+
left.setWidth(leftPercent);
84+
right.setWidth(rightPercent);
85+
86+
if (onPanelWidthChange) {
87+
onPanelWidthChange([leftPercent, rightPercent]);
88+
}
89+
}
90+
},
91+
[onPanelWidthChange]
92+
);
93+
5194
const childrenWithResizer = [
5295
firstChild,
5396
<Resizer
5497
key={'resizer'}
55-
onMouseDown={event => {
56-
event.preventDefault();
57-
setState({
58-
...state,
59-
isDragging: true,
60-
currentResizerPos: event.clientX,
61-
});
62-
}}
98+
className={resizerClassName}
99+
onKeyDown={handleKeyDown}
100+
onMouseDown={handleMouseDown}
63101
/>,
64102
secondChild,
65103
];
66104

67105
return (
68106
<PanelContextProvider registry={registryRef.current}>
69107
<div
108+
className={className}
70109
ref={containerRef}
71110
style={{ display: 'flex', height: '100%', width: '100%' }}
72111
onMouseMove={event => {

src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/registry.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
export interface PanelController {
2121
setWidth: (percent: number) => void;
2222
getWidth: () => number;
23-
initialWidth: string;
23+
width: number;
2424
}
2525

2626
export class PanelRegistry {
@@ -35,6 +35,6 @@ export class PanelRegistry {
3535
}
3636

3737
getPanels() {
38-
return this.panels.map(panel => ({ ...panel }));
38+
return this.panels;
3939
}
4040
}

src/legacy/core_plugins/console/public/np_ready/application/components/split_panel/split_panel.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ describe('Split panel', () => {
6565

6666
const panelContainer = mount(
6767
<PanelsContainer onPanelWidthChange={onWidthChange}>
68-
<Panel initialWidth={'50%'}>{testComponentA}</Panel>
69-
<Panel initialWidth={'50%'}>{testComponentB}</Panel>
68+
<Panel initialWidth={50}>{testComponentA}</Panel>
69+
<Panel initialWidth={50}>{testComponentB}</Panel>
7070
</PanelsContainer>
7171
);
7272

src/legacy/core_plugins/console/public/np_ready/application/containers/editor/editor.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ export const Editor = ({ loading }: Props) => {
5555
if (!currentTextObject) return null;
5656

5757
return (
58-
<PanelsContainer onPanelWidthChange={onPanelWidthChange}>
58+
<PanelsContainer onPanelWidthChange={onPanelWidthChange} resizerClassName="conApp__resizer">
5959
<Panel
6060
style={{ height: '100%', position: 'relative', minWidth: PANEL_MIN_WIDTH }}
61-
initialWidth={firstPanelWidth + '%'}
61+
initialWidth={firstPanelWidth}
6262
>
6363
{loading ? (
6464
<EditorContentSpinner />
@@ -68,7 +68,7 @@ export const Editor = ({ loading }: Props) => {
6868
</Panel>
6969
<Panel
7070
style={{ height: '100%', position: 'relative', minWidth: PANEL_MIN_WIDTH }}
71-
initialWidth={secondPanelWidth + '%'}
71+
initialWidth={secondPanelWidth}
7272
>
7373
{loading ? <EditorContentSpinner /> : <EditorOutput />}
7474
</Panel>

src/legacy/core_plugins/input_control_vis/public/components/editor/__snapshots__/controls_tab.test.tsx.snap

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)