[chore](ui) execute selected code in sql editor. (#16906)

* ui playground support selection sql to execute

* ui playground support selection sql to execute
This commit is contained in:
ZhangYu0123
2023-02-23 14:25:06 +08:00
committed by GitHub
parent c2cc75d741
commit eb116cd25e
2 changed files with 13 additions and 4 deletions

View File

@ -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) {
<p>Log path is: {LogContents.logPath}</p>
<p>{LogContents.showingLast}</p>
</Paragraph>
<div ref={container} style={{background: '#f9f9f9', padding: '20px'}}>
<div ref={container} style={{background: '#f9f9f9', padding: '20px', overflowY: 'scroll', height: '800px'}}>
{/* {LogContents.log} */}
</div>
<BackTop></BackTop>

View File

@ -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);
};