Skip to content

Commit

Permalink
[chore](ui) execute selected code in sql editor. (#16906)
Browse files Browse the repository at this point in the history
* ui playground support selection sql to execute

* ui playground support selection sql to execute
  • Loading branch information
ZhangYu0123 authored Feb 23, 2023
1 parent c2cc75d commit eb116cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion ui/src/pages/logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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>
Expand Down
14 changes: 11 additions & 3 deletions ui/src/pages/playground/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ export function AdHocContent(props: any) {
() =>
AdHocAPI.doQuery({
db_name:getDbName().db_name,
body:{stmt:code},
body:{stmt:getCodeSql()},
}),
{
manual: true,
onSuccess: res => {
// 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);
Expand All @@ -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);
};
Expand Down

0 comments on commit eb116cd

Please sign in to comment.