From 729bcba7acd7fa4bccd1fd7769bfeb03d29b4011 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Mon, 28 Sep 2020 22:19:28 -0700 Subject: [PATCH] Web console: Display compaction status (#10438) * init compaction status * % compacted * final UI tweaks * extracted utils, added tests * add tests to general foramt functions --- .../src/components/json-input/json-input.tsx | 13 +- .../components/more-button/more-button.tsx | 23 +- .../compaction-dialog.spec.tsx.snap | 24 ++ .../compaction-dialog/compaction-dialog.tsx | 3 +- web-console/src/utils/compaction.spec.ts | 87 ++++++ web-console/src/utils/compaction.ts | 68 +++++ web-console/src/utils/general.spec.ts | 35 +++ web-console/src/utils/general.tsx | 4 + web-console/src/utils/index.tsx | 1 + .../datasource-view.spec.tsx.snap | 51 +++- .../views/datasource-view/datasource-view.tsx | 282 +++++++++++++----- .../query-view/query-input/query-input.tsx | 2 +- 12 files changed, 504 insertions(+), 89 deletions(-) create mode 100644 web-console/src/utils/compaction.spec.ts create mode 100644 web-console/src/utils/compaction.ts diff --git a/web-console/src/components/json-input/json-input.tsx b/web-console/src/components/json-input/json-input.tsx index f1dd512ac17..eba062091d5 100644 --- a/web-console/src/components/json-input/json-input.tsx +++ b/web-console/src/components/json-input/json-input.tsx @@ -80,12 +80,11 @@ export const JsonInput = React.memo(function JsonInput(props: JsonInputProps) { const aceEditor = useRef(); useEffect(() => { - if (!deepEqual(value, internalValue.value)) { - setInternalValue({ - value, - stringified: stringifyJson(value), - }); - } + if (deepEqual(value, internalValue.value)) return; + setInternalValue({ + value, + stringified: stringifyJson(value), + }); }, [value]); const internalValueError = internalValue.error; @@ -149,8 +148,8 @@ export const JsonInput = React.memo(function JsonInput(props: JsonInputProps) { const rc = extractRowColumnFromHjsonError(internalValueError); if (!rc) return; + aceEditor.current.focus(); // Grab the focus aceEditor.current.getSelection().moveCursorTo(rc.row, rc.column); - aceEditor.current.focus(); // Grab the focus also }} > {internalValueError.message} diff --git a/web-console/src/components/more-button/more-button.tsx b/web-console/src/components/more-button/more-button.tsx index 7a161b7e497..4bcef07225f 100644 --- a/web-console/src/components/more-button/more-button.tsx +++ b/web-console/src/components/more-button/more-button.tsx @@ -18,14 +18,19 @@ import { Button, Menu, Popover, Position } from '@blueprintjs/core'; import { IconNames } from '@blueprintjs/icons'; -import React from 'react'; +import React, { useState } from 'react'; + +type OpenState = 'open' | 'alt-open'; export interface MoreButtonProps { - children: React.ReactNode; + children: React.ReactNode | React.ReactNode[]; + altExtra?: React.ReactNode; } export const MoreButton = React.memo(function MoreButton(props: MoreButtonProps) { - const { children } = props; + const { children, altExtra } = props; + + const [openState, setOpenState] = useState(); let childCount = 0; // Sadly React.Children.count does not ignore nulls correctly @@ -36,8 +41,18 @@ export const MoreButton = React.memo(function MoreButton(props: MoreButtonProps) return ( {children}} + isOpen={Boolean(openState)} + content={ + + {children} + {openState === 'alt-open' && altExtra} + + } position={Position.BOTTOM_LEFT} + onInteraction={(nextOpenState, e: any) => { + if (!e) return; // For some reason this function is always called twice once with e and once without + setOpenState(nextOpenState ? (e.altKey ? 'alt-open' : 'open') : undefined); + }} >