You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2021/06/14 07:07:57 UTC

[GitHub] [druid] jgoz commented on a change in pull request #11357: Web console: Remove support for IE11 and other older browsers

jgoz commented on a change in pull request #11357:
URL: https://github.com/apache/druid/pull/11357#discussion_r649612141



##########
File path: web-console/src/views/query-view/run-button/run-button.tsx
##########
@@ -59,127 +57,123 @@ export interface RunButtonProps {
   onPrettier: () => void;
 }
 
-@HotkeysTarget
-export class RunButton extends React.PureComponent<RunButtonProps> {
-  public renderHotkeys() {
-    return (
-      <Hotkeys>
-        <Hotkey
-          allowInInput
-          global
-          combo="ctrl + enter"
-          label="run on click"
-          onKeyDown={this.handleRun}
-        />
-      </Hotkeys>
-    );
-  }
+const RunButtonExtraMenu = (props: RunButtonProps) => {
+  const {
+    runeMode,
+    onExplain,
+    queryContext,
+    onQueryContextChange,
+    onEditContext,
+    onHistory,
+    onPrettier,
+  } = props;
+
+  const useCache = getUseCache(queryContext);
+  const useApproximateCountDistinct = getUseApproximateCountDistinct(queryContext);
+  const useApproximateTopN = getUseApproximateTopN(queryContext);
+  const numContextKeys = Object.keys(queryContext).length;
+
+  return (
+    <Menu>
+      <MenuItem
+        icon={IconNames.HELP}
+        text={runeMode ? 'Native query documentation' : 'DruidSQL documentation'}
+        href={getLink(runeMode ? 'DOCS_RUNE' : 'DOCS_SQL')}
+        target="_blank"
+      />
+      <MenuItem icon={IconNames.HISTORY} text="Query history" onClick={onHistory} />
+      {!runeMode && onExplain && (
+        <MenuItem icon={IconNames.CLEAN} text="Explain SQL query" onClick={onExplain} />
+      )}
+      {runeMode && (
+        <MenuItem icon={IconNames.ALIGN_LEFT} text="Prettify JSON" onClick={onPrettier} />
+      )}
+      <MenuItem
+        icon={IconNames.PROPERTIES}
+        text="Edit context"
+        onClick={onEditContext}
+        label={numContextKeys ? pluralIfNeeded(numContextKeys, 'key') : undefined}
+      />
+      <MenuDivider />
+      {!runeMode && (
+        <>
+          <MenuCheckbox
+            checked={useApproximateCountDistinct}
+            text="Use approximate COUNT(DISTINCT)"
+            onChange={() => {
+              onQueryContextChange(
+                setUseApproximateCountDistinct(queryContext, !useApproximateCountDistinct),
+              );
+            }}
+          />
+          <MenuCheckbox
+            checked={useApproximateTopN}
+            text="Use approximate TopN"
+            onChange={() => {
+              onQueryContextChange(setUseApproximateTopN(queryContext, !useApproximateTopN));
+            }}
+          />
+        </>
+      )}
+      <MenuCheckbox
+        checked={useCache}
+        text="Use cache"
+        onChange={() => {
+          onQueryContextChange(setUseCache(queryContext, !useCache));
+        }}
+      />
+    </Menu>
+  );
+};
+
+export const RunButton = React.memo(function RunButton(props: RunButtonProps) {
+  const { runeMode, onRun, loading } = props;
 
-  private readonly handleRun = () => {
-    const { onRun } = this.props;
+  const handleRun = React.useCallback(() => {
     if (!onRun) return;
     onRun();
-  };
+  }, [onRun]);
 
-  renderExtraMenu() {
-    const {
-      runeMode,
-      onExplain,
-      queryContext,
-      onQueryContextChange,
-      onEditContext,
-      onHistory,
-      onPrettier,
-    } = this.props;
+  const hotkeys = React.useMemo(() => {
+    return [
+      {
+        allowInInput: true,
+        global: true,
+        combo: 'ctrl + enter',
+        label: 'run on click',
+        onKeyDown: handleRun,
+      },
+    ];
+  }, [handleRun]);
 
-    const useCache = getUseCache(queryContext);
-    const useApproximateCountDistinct = getUseApproximateCountDistinct(queryContext);
-    const useApproximateTopN = getUseApproximateTopN(queryContext);
-    const numContextKeys = Object.keys(queryContext).length;
+  const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeys);

Review comment:
       Yeah that makes total sense

##########
File path: web-console/src/views/query-view/run-button/run-button.tsx
##########
@@ -59,127 +57,123 @@ export interface RunButtonProps {
   onPrettier: () => void;
 }
 
-@HotkeysTarget
-export class RunButton extends React.PureComponent<RunButtonProps> {
-  public renderHotkeys() {
-    return (
-      <Hotkeys>
-        <Hotkey
-          allowInInput
-          global
-          combo="ctrl + enter"
-          label="run on click"
-          onKeyDown={this.handleRun}
-        />
-      </Hotkeys>
-    );
-  }
+const RunButtonExtraMenu = (props: RunButtonProps) => {
+  const {
+    runeMode,
+    onExplain,
+    queryContext,
+    onQueryContextChange,
+    onEditContext,
+    onHistory,
+    onPrettier,
+  } = props;
+
+  const useCache = getUseCache(queryContext);
+  const useApproximateCountDistinct = getUseApproximateCountDistinct(queryContext);
+  const useApproximateTopN = getUseApproximateTopN(queryContext);
+  const numContextKeys = Object.keys(queryContext).length;
+
+  return (
+    <Menu>
+      <MenuItem
+        icon={IconNames.HELP}
+        text={runeMode ? 'Native query documentation' : 'DruidSQL documentation'}
+        href={getLink(runeMode ? 'DOCS_RUNE' : 'DOCS_SQL')}
+        target="_blank"
+      />
+      <MenuItem icon={IconNames.HISTORY} text="Query history" onClick={onHistory} />
+      {!runeMode && onExplain && (
+        <MenuItem icon={IconNames.CLEAN} text="Explain SQL query" onClick={onExplain} />
+      )}
+      {runeMode && (
+        <MenuItem icon={IconNames.ALIGN_LEFT} text="Prettify JSON" onClick={onPrettier} />
+      )}
+      <MenuItem
+        icon={IconNames.PROPERTIES}
+        text="Edit context"
+        onClick={onEditContext}
+        label={numContextKeys ? pluralIfNeeded(numContextKeys, 'key') : undefined}
+      />
+      <MenuDivider />
+      {!runeMode && (
+        <>
+          <MenuCheckbox
+            checked={useApproximateCountDistinct}
+            text="Use approximate COUNT(DISTINCT)"
+            onChange={() => {
+              onQueryContextChange(
+                setUseApproximateCountDistinct(queryContext, !useApproximateCountDistinct),
+              );
+            }}
+          />
+          <MenuCheckbox
+            checked={useApproximateTopN}
+            text="Use approximate TopN"
+            onChange={() => {
+              onQueryContextChange(setUseApproximateTopN(queryContext, !useApproximateTopN));
+            }}
+          />
+        </>
+      )}
+      <MenuCheckbox
+        checked={useCache}
+        text="Use cache"
+        onChange={() => {
+          onQueryContextChange(setUseCache(queryContext, !useCache));
+        }}
+      />
+    </Menu>
+  );
+};
+
+export const RunButton = React.memo(function RunButton(props: RunButtonProps) {
+  const { runeMode, onRun, loading } = props;
 
-  private readonly handleRun = () => {
-    const { onRun } = this.props;
+  const handleRun = React.useCallback(() => {
     if (!onRun) return;
     onRun();
-  };
+  }, [onRun]);
 
-  renderExtraMenu() {
-    const {
-      runeMode,
-      onExplain,
-      queryContext,
-      onQueryContextChange,
-      onEditContext,
-      onHistory,
-      onPrettier,
-    } = this.props;
+  const hotkeys = React.useMemo(() => {
+    return [
+      {
+        allowInInput: true,
+        global: true,
+        combo: 'ctrl + enter',
+        label: 'run on click',

Review comment:
       Done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org