This is an automated email from the ASF dual-hosted git repository.
vogievetsky pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 73bab2f0205 Add option to copy query results directly to clipboard
(#14889)
73bab2f0205 is described below
commit 73bab2f0205c7f718c34bebd3bc87422defa6e44
Author: Sam Wheating <[email protected]>
AuthorDate: Tue Sep 19 10:25:39 2023 -0700
Add option to copy query results directly to clipboard (#14889)
* Add option to copy query results to clipboard
* Refactor, allow copying in all formats
---------
Co-authored-by: Sam Wheating <[email protected]>
---
web-console/src/utils/download.ts | 24 ++++++++++++++--------
.../execution-summary-panel.tsx | 9 ++++++++
2 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/web-console/src/utils/download.ts
b/web-console/src/utils/download.ts
index 41c558edc02..aebf5f14f63 100644
--- a/web-console/src/utils/download.ts
+++ b/web-console/src/utils/download.ts
@@ -20,7 +20,7 @@ import type { QueryResult } from '@druid-toolkit/query';
import FileSaver from 'file-saver';
import * as JSONBig from 'json-bigint-native';
-import { stringifyValue } from './general';
+import { copyAndAlert, stringifyValue } from './general';
export function downloadUrl(url: string, filename: string) {
// Create a link and set the URL using `createObjectURL`
@@ -74,11 +74,7 @@ export function downloadFile(text: string, type: string,
filename: string): void
FileSaver.saveAs(blob, filename);
}
-export function downloadQueryResults(
- queryResult: QueryResult,
- filename: string,
- format: string,
-): void {
+function queryResultsToString(queryResult: QueryResult, format: string):
string {
let lines: string[] = [];
let separator = '';
@@ -103,7 +99,19 @@ export function downloadQueryResults(
return JSONBig.stringify(outputObject);
});
}
+ return lines.join('\n');
+}
+
+export function downloadQueryResults(
+ queryResult: QueryResult,
+ filename: string,
+ format: string,
+): void {
+ const resultString: string = queryResultsToString(queryResult, format);
+ downloadFile(resultString, format, filename);
+}
- const lineBreak = '\n';
- downloadFile(lines.join(lineBreak), format, filename);
+export function copyQueryResultsToClipboard(queryResult: QueryResult, format:
string): void {
+ const resultString: string = queryResultsToString(queryResult, format);
+ copyAndAlert(resultString, 'Query results copied to clipboard');
}
diff --git
a/web-console/src/views/workbench-view/execution-summary-panel/execution-summary-panel.tsx
b/web-console/src/views/workbench-view/execution-summary-panel/execution-summary-panel.tsx
index 9d1030133b2..720711500b6 100644
---
a/web-console/src/views/workbench-view/execution-summary-panel/execution-summary-panel.tsx
+++
b/web-console/src/views/workbench-view/execution-summary-panel/execution-summary-panel.tsx
@@ -24,6 +24,7 @@ import React, { useState } from 'react';
import type { Execution } from '../../../druid-models';
import {
+ copyQueryResultsToClipboard,
downloadQueryResults,
formatDurationHybrid,
formatInteger,
@@ -68,6 +69,10 @@ export const ExecutionSummaryPanel = React.memo(function
ExecutionSummaryPanel(
downloadQueryResults(queryResult, `results-${execution.id}.${format}`,
format);
};
+ const handleCopy = (format: string) => {
+ copyQueryResultsToClipboard(queryResult, format);
+ };
+
buttons.push(
<Button
key="results"
@@ -101,6 +106,10 @@ export const ExecutionSummaryPanel = React.memo(function
ExecutionSummaryPanel(
<MenuItem text="CSV" onClick={() => handleDownload('csv')} />
<MenuItem text="TSV" onClick={() => handleDownload('tsv')} />
<MenuItem text="JSON (new line delimited)" onClick={() =>
handleDownload('json')} />
+ <MenuDivider title="Copy to clipboard as..." />
+ <MenuItem text="CSV" onClick={() => handleCopy('csv')} />
+ <MenuItem text="TSV" onClick={() => handleCopy('tsv')} />
+ <MenuItem text="JSON (new line delimited)" onClick={() =>
handleCopy('json')} />
</Menu>
}
position={Position.BOTTOM_RIGHT}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]