From eb116cd25eb200b1d507bce98c3c531b128ba4d6 Mon Sep 17 00:00:00 2001 From: ZhangYu0123 <67053339+ZhangYu0123@users.noreply.github.com> Date: Thu, 23 Feb 2023 14:25:06 +0800 Subject: [PATCH] [chore](ui) execute selected code in sql editor. (#16906) * ui playground support selection sql to execute * ui playground support selection sql to execute --- ui/src/pages/logs/index.tsx | 3 ++- ui/src/pages/playground/content/index.tsx | 14 +++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ui/src/pages/logs/index.tsx b/ui/src/pages/logs/index.tsx index 065b55d510..403a8d056d 100644 --- a/ui/src/pages/logs/index.tsx +++ b/ui/src/pages/logs/index.tsx @@ -40,6 +40,7 @@ export default function Logs(params: any) { container.current.innerHTML = res.data.LogContents.log; } setLogContents(res.data.LogContents); + container.current.scrollTop = container.current.scrollHeight; } } }).catch(err => { @@ -81,7 +82,7 @@ export default function Logs(params: any) {

Log path is: {LogContents.logPath}

{LogContents.showingLast}

-
+
{/* {LogContents.log} */}
diff --git a/ui/src/pages/playground/content/index.tsx b/ui/src/pages/playground/content/index.tsx index 50c69e8b80..d9b0842f2b 100644 --- a/ui/src/pages/playground/content/index.tsx +++ b/ui/src/pages/playground/content/index.tsx @@ -59,7 +59,7 @@ export function AdHocContent(props: any) { () => AdHocAPI.doQuery({ db_name:getDbName().db_name, - body:{stmt:code}, + body:{stmt:getCodeSql()}, }), { manual: true, @@ -67,12 +67,12 @@ export function AdHocContent(props: any) { // const endTime = getTimeNow(); const {db_name, tbl_name} = getDbName(); if (isSuccess(res)) { - res.sqlCode = code; + res.sqlCode = getCodeSql(); res = {...res, db_name, tbl_name} props.history.push({pathname:`/Playground/result/${db_name}-${tbl_name}`,state: res}); runSQLSuccessSubject.next(true); } else { - res.sqlCode = code; + res.sqlCode = getCodeSql(); res = {...res, db_name, tbl_name} props.history.push({pathname:`/Playground/result/${db_name}-${tbl_name}`,state: res}); runSQLSuccessSubject.next(false); @@ -93,6 +93,14 @@ export function AdHocContent(props: any) { return () => subscription.unsubscribe(); }, []); + const getCodeSql = () => { + const sqlCodeSelection = editorInstance.getSelection(); + if (sqlCodeSelection != "") { + return sqlCodeSelection; + } + return code; + }; + const handleChange = (_editor, _data, value) => { setCode(value); };