Skip to content

Commit

Permalink
Merge branch 'main' into revert-fs-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsonpl authored Apr 24, 2024
2 parents afa4b90 + f52db83 commit 11b42bb
Show file tree
Hide file tree
Showing 27 changed files with 981 additions and 127 deletions.
4 changes: 0 additions & 4 deletions config/node.options
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,3 @@

## enable OpenSSL 3 legacy provider
--openssl-legacy-provider

# Enable capturing heap snapshots. See https://nodejs.org/api/cli.html#--heapsnapshot-signalsignal
--heapsnapshot-signal=SIGUSR2
--diagnostic-dir=./data
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ COPY --chown=1000:0 config/serverless.yml /usr/share/kibana/config/serverless.ym
COPY --chown=1000:0 config/serverless.es.yml /usr/share/kibana/config/serverless.es.yml
COPY --chown=1000:0 config/serverless.oblt.yml /usr/share/kibana/config/serverless.oblt.yml
COPY --chown=1000:0 config/serverless.security.yml /usr/share/kibana/config/serverless.security.yml
# Supportability enhancement: enable capturing heap snapshots. See https://nodejs.org/api/cli.html#--heapsnapshot-signalsignal
RUN /usr/bin/echo -e '\n--heapsnapshot-signal=SIGUSR2' >> config/node.options
RUN /usr/bin/echo '--diagnostic-dir=./data' >> config/node.options
ENV PROFILER_SIGNAL=SIGUSR1
{{/serverless}}
{{^opensslLegacyProvider}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,9 @@
animation-duration: $euiAnimSpeedNormal;
animation-timing-function: $euiAnimSlightResistance;
animation-fill-mode: forwards;
}

&-isOpen.embeddableConsole--large {
animation-name: embeddableConsoleOpenPanelLarge;
height: $embeddableConsoleMaxHeight;
bottom: map-get($embeddableConsoleHeights, 'l') * -1;
}

&-isOpen.embeddableConsole--medium {
animation-name: embeddableConsoleOpenPanelMedium;
height: map-get($embeddableConsoleHeights, 'm');
bottom: map-get($embeddableConsoleHeights, 'm') * -1;
}

&-isOpen.embeddableConsole--small {
animation-name: embeddableConsoleOpenPanelSmall;
height: map-get($embeddableConsoleHeights, 's');
bottom: map-get($embeddableConsoleHeights, 's') * -1;
animation-name: embeddableConsoleOpenPanel;
height: var(--embedded-console-height);
bottom: var(--embedded-console-bottom);
}
}

Expand All @@ -80,7 +65,6 @@

&--altViewButton-container {
margin-left: auto;
// padding: $euiSizeS;
}
}

Expand Down Expand Up @@ -132,34 +116,13 @@
}
}

@keyframes embeddableConsoleOpenPanelLarge {
0% {
// Accounts for the initial height offset from the top
transform: translateY(calc((#{$embeddableConsoleInitialHeight} * 3) * -1));
}

100% {
transform: translateY(map-get($embeddableConsoleHeights, 'l') * -1);
}
}

@keyframes embeddableConsoleOpenPanelMedium {
0% {
transform: translateY(-$embeddableConsoleInitialHeight);
}

100% {
transform: translateY(map-get($embeddableConsoleHeights, 'm') * -1);
}
}

@keyframes embeddableConsoleOpenPanelSmall {
@keyframes embeddableConsoleOpenPanel {
0% {
transform: translateY(-$embeddableConsoleInitialHeight);
}

100% {
transform: translateY(map-get($embeddableConsoleHeights, 's') * -1);
transform: translateY(var(--embedded-console-bottom));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,3 @@ $embeddableConsoleText: lighten(makeHighContrastColor($euiColorLightestShade, $e
$embeddableConsoleBorderColor: transparentize($euiColorGhost, .8);
$embeddableConsoleInitialHeight: $euiSizeXXL;
$embeddableConsoleMaxHeight: calc(100vh - var(--euiFixedHeadersOffset, 0));

// Pixel heights ensure no blurriness caused by half pixel offsets
$embeddableConsoleHeights: (
s: $euiSize * 30,
m: $euiSize * 50,
l: 100vh,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React, { useCallback, useEffect, useState, useRef } from 'react';
import { EuiResizableButton, useEuiTheme, keys, EuiThemeComputed } from '@elastic/eui';

const CONSOLE_MIN_HEIGHT = 200;

const getMouseOrTouchY = (
e: TouchEvent | MouseEvent | React.MouseEvent | React.TouchEvent
): number => {
// Some Typescript fooling is needed here
const y = (e as TouchEvent).targetTouches
? (e as TouchEvent).targetTouches[0].pageY
: (e as MouseEvent).pageY;
return y;
};

export interface EmbeddedConsoleResizeButtonProps {
consoleHeight: number;
setConsoleHeight: React.Dispatch<React.SetStateAction<number>>;
}

export function getCurrentConsoleMaxSize(euiTheme: EuiThemeComputed<{}>) {
const euiBaseSize = parseInt(euiTheme.size.base, 10);
const winHeight = window.innerHeight;
const bodyStyle = getComputedStyle(document.body);
const headerOffset = parseInt(bodyStyle.getPropertyValue('--euiFixedHeadersOffset') ?? '0px', 10);

// We leave a buffer of baseSize to allow room for the user to hover on the top border for resizing
return Math.max(winHeight - headerOffset - euiBaseSize, CONSOLE_MIN_HEIGHT);
}

export const EmbeddedConsoleResizeButton = ({
consoleHeight,
setConsoleHeight,
}: EmbeddedConsoleResizeButtonProps) => {
const { euiTheme } = useEuiTheme();
const [maxConsoleHeight, setMaxConsoleHeight] = useState<number>(800);
const initialConsoleHeight = useRef(consoleHeight);
const initialMouseY = useRef(0);

useEffect(() => {
function handleResize() {
const newMaxConsoleHeight = getCurrentConsoleMaxSize(euiTheme);
// Calculate and save the console max height. This is the window height minus the header
// offset minuse the base size to allow a small buffer for grabbing the resize button.
if (maxConsoleHeight !== newMaxConsoleHeight) {
setMaxConsoleHeight(newMaxConsoleHeight);
}
if (consoleHeight > newMaxConsoleHeight && newMaxConsoleHeight > CONSOLE_MIN_HEIGHT) {
// When the current console height is greater than the new max height,
// we resize the console to the max height. This will ensure there is not weird
// behavior with the drag resize.
setConsoleHeight(newMaxConsoleHeight);
}
}

handleResize();
window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, [maxConsoleHeight, euiTheme, consoleHeight, setConsoleHeight]);
const onResizeMouseMove = useCallback(
(e: MouseEvent | TouchEvent) => {
const currentMouseY = getMouseOrTouchY(e);
const mouseOffset = (currentMouseY - initialMouseY.current) * -1;
const changedConsoleHeight = initialConsoleHeight.current + mouseOffset;

const newConsoleHeight = Math.min(
Math.max(changedConsoleHeight, CONSOLE_MIN_HEIGHT),
maxConsoleHeight
);

setConsoleHeight(newConsoleHeight);
},
[maxConsoleHeight, setConsoleHeight]
);
const onResizeMouseUp = useCallback(
(e: MouseEvent | TouchEvent) => {
initialMouseY.current = 0;

window.removeEventListener('mousemove', onResizeMouseMove);
window.removeEventListener('mouseup', onResizeMouseUp);
window.removeEventListener('touchmove', onResizeMouseMove);
window.removeEventListener('touchend', onResizeMouseUp);
},
[onResizeMouseMove]
);
const onResizeMouseDown = useCallback(
(e: React.MouseEvent | React.TouchEvent) => {
initialMouseY.current = getMouseOrTouchY(e);
initialConsoleHeight.current = consoleHeight;

// Window event listeners instead of React events are used
// in case the user's mouse leaves the component
window.addEventListener('mousemove', onResizeMouseMove);
window.addEventListener('mouseup', onResizeMouseUp);
window.addEventListener('touchmove', onResizeMouseMove);
window.addEventListener('touchend', onResizeMouseUp);
},
[consoleHeight, onResizeMouseUp, onResizeMouseMove]
);
const onResizeKeyDown = useCallback(
(e: React.KeyboardEvent) => {
const KEYBOARD_OFFSET = 10;

switch (e.key) {
case keys.ARROW_UP:
e.preventDefault(); // Safari+VO will screen reader navigate off the button otherwise
setConsoleHeight((height) => Math.min(height + KEYBOARD_OFFSET, maxConsoleHeight));
break;
case keys.ARROW_DOWN:
e.preventDefault(); // Safari+VO will screen reader navigate off the button otherwise
setConsoleHeight((height) => Math.max(height - KEYBOARD_OFFSET, CONSOLE_MIN_HEIGHT));
}
},
[maxConsoleHeight, setConsoleHeight]
);
const onResizeDoubleClick = useCallback(() => {
if (consoleHeight < maxConsoleHeight) {
setConsoleHeight(maxConsoleHeight);
} else {
setConsoleHeight(maxConsoleHeight / 2);
}
}, [consoleHeight, maxConsoleHeight, setConsoleHeight]);

return (
<EuiResizableButton
indicator="border"
isHorizontal={false}
onMouseDown={onResizeMouseDown}
onTouchStart={onResizeMouseDown}
onKeyDown={onResizeKeyDown}
onDoubleClick={onResizeDoubleClick}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import {
History,
Settings,
Storage,
createStorage,
createHistory,
createSettings,
setStorage,
getStorage,
} from '../../../services';
import { createUsageTracker } from '../../../services/tracker';
import { MetricsTracker, EmbeddableConsoleDependencies } from '../../../types';
Expand Down Expand Up @@ -78,11 +77,7 @@ const loadDependencies = async (

await loadActiveApi(core.http);
const autocompleteInfo = getAutocompleteInfo();
const storage = createStorage({
engine: window.localStorage,
prefix: 'sense:',
});
setStorage(storage);
const storage = getStorage();
const history = createHistory({ storage });
const settings = createSettings({ storage });
const objectStorageClient = localStorageObjectClient.create(storage);
Expand All @@ -107,7 +102,10 @@ const loadDependencies = async (
};

interface ConsoleWrapperProps
extends Omit<EmbeddableConsoleDependencies, 'setDispatch' | 'alternateView'> {
extends Omit<
EmbeddableConsoleDependencies,
'setDispatch' | 'alternateView' | 'setConsoleHeight' | 'getConsoleHeight'
> {
onKeyDown: (this: Window, ev: WindowEventMap['keydown']) => any;
}

Expand Down
Loading

0 comments on commit 11b42bb

Please sign in to comment.