Skip to content

Commit

Permalink
PullRequest: 289 Fixes oceanbase/odc#1255, Fixes oceanbase/odc#1256
Browse files Browse the repository at this point in the history
Merge branch 'fix/dev-4.2.3-odc-1255-1256 of [email protected]:oceanbase/oceanbase-developer-center.git into dev-4.2.3

https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/289


Signed-off-by: 晓康 <[email protected]>


* Fixes oceanbase/odc#1255, Fixes oceanbase/odc#1256
  • Loading branch information
UnknownAdventurer committed Dec 21, 2023
1 parent 9f266b4 commit 229a92c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/common/network/sql/executeSQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default async function executeSQL(
// 一些场景下不需要弹出SQL确认弹窗
if (!needModal) {
return {
hasLintResults: true,
hasLintResults: lintResultSet?.length > 0,
invalid: true,
executeSuccess: false,
executeResult: [],
Expand Down Expand Up @@ -281,6 +281,7 @@ export default async function executeSQL(
executeResult: results || [],
violatedRules: [],
lintResultSet,
hasLintResults: lintResultSet?.length > 0,
status,
};
}
Expand Down
57 changes: 49 additions & 8 deletions src/page/Workspace/components/SQLPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ export class SQLPage extends Component<IProps, ISQLPageState> {

public handleExecuteSQL = async () => {
const { params } = this.props;
const { hasExecuted } = this.state;

const selectedSQL = this.editor.getSelectionContent();
const sqlToExecute = selectedSQL || params.scriptText;
Expand All @@ -333,9 +332,15 @@ export class SQLPage extends Component<IProps, ISQLPageState> {
false,
selectedSQL ? await utils.getCurrentSelectRange(this.editor) : null,
);
this.setState({
baseOffset: selectedSQL ? range.begin - this.editor?.getSelectionContent()?.length : 0,
});
if (range.begin === range.end) {
this.setState({
baseOffset: selectedSQL ? range.begin - this.editor?.getSelectionContent()?.length : 0,
});
} else if (range.begin < range.end) {
this.setState({
baseOffset: selectedSQL ? range.begin : 0,
});
}
if (result?.hasLintResults) {
this.setState({
resultSetTabActiveKey: sqlLintTabKey,
Expand All @@ -351,8 +356,8 @@ export class SQLPage extends Component<IProps, ISQLPageState> {
sqlChanged: false,
});
}
}; // 执行选中的 SQL

};
// 执行选中的 SQL
public handleExecuteSelectedSQL = async () => {
let selectedSQL = this.editor.getModel().getValueInRange(this.editor.getSelection()); // 如果没有选中,尝试获取当前语句
let begin, end;
Expand Down Expand Up @@ -382,7 +387,32 @@ export class SQLPage extends Component<IProps, ISQLPageState> {
if (!selectedSQL) {
return;
}
await this.executeSQL(selectedSQL, true, { begin, end });
const results = await this.executeSQL(selectedSQL, true, { begin, end });
const range = await utils.getCurrentSelectRange(this.editor);
if (range.begin === range.end) {
this.setState({
baseOffset: range.begin - this.editor?.getSelectionContent()?.length || 0,
});
} else if (range.begin < range.end) {
this.setState({
baseOffset: range.begin || 0,
});
}
if (results?.hasLintResults) {
this.setState({
resultSetTabActiveKey: sqlLintTabKey,
lintResultSet: results?.lintResultSet,
executeOrPreCheckSql: selectedSQL,
sqlChanged: false,
});
} else {
this.setState({
baseOffset: 0,
lintResultSet: null,
executeOrPreCheckSql: selectedSQL,
sqlChanged: false,
});
}
};

public async saveScript() {
Expand Down Expand Up @@ -504,8 +534,16 @@ export class SQLPage extends Component<IProps, ISQLPageState> {
this.getSession()?.params?.delimiter,
value,
);
if (range.begin === range.end) {
this.setState({
baseOffset: range.begin - this.editor?.getSelectionContent()?.length || 0,
});
} else if (range.begin < range.end) {
this.setState({
baseOffset: range.begin || 0,
});
}
this.setState({
baseOffset: selectted ? range.begin - this.editor?.getSelectionContent()?.length : 0,
executeOrPreCheckSql: value,
sqlChanged: false,
});
Expand All @@ -517,6 +555,9 @@ export class SQLPage extends Component<IProps, ISQLPageState> {
message.success(
formatMessage({ id: 'odc.components.SQLPage.SqlCheckPassed' }), //SQL 检查通过
);
this.setState({
baseOffset: 0,
});
return;
}
this.setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ModalStore } from '@/store/modal';
import SessionStore from '@/store/sessionManager/session';
import { groupByPropertyName } from '@/util/utils';
import { Button, Table } from 'antd';
import classNames from 'classnames';
import { useCallback, useEffect, useState } from 'react';
import getColumns from './columns';
import styles from './index.less';
Expand Down Expand Up @@ -66,7 +67,7 @@ const LintResultTable: React.FC<ILintResultTableProps> = ({
return (
<Table
rowKey="row"
className="o-table--no-lr-border"
className={classNames('o-table--no-lr-border', styles.thFilter)}
bordered={true}
columns={columns}
dataSource={dataSource || []}
Expand All @@ -86,12 +87,13 @@ const LintResultTable: React.FC<ILintResultTableProps> = ({
}
: {
position: ['bottomRight'],
pageSize: resultHeight ? Math.floor((resultHeight - 150) / 24) : 0,
hideOnSinglePage: true,
}
}
/>
);
}, [lintResultSet, ctx, baseOffset, dataSource]);
}, [lintResultSet, ctx, baseOffset, dataSource, resultHeight]);
useEffect(() => {
if (Array.isArray(lintResultSet) && lintResultSet?.length) {
const newDataSource = lintResultSet?.map((resultSet, index) => {
Expand All @@ -111,7 +113,7 @@ const LintResultTable: React.FC<ILintResultTableProps> = ({
if (violations?.some((violation) => violation?.level === 2)) {
setDisabled(true);
setTip(LintResultTip.must);
} else if (violations?.every((violation) => violation?.level === 2)) {
} else if (violations?.every((violation) => violation?.level === 0)) {
setDisabled(true);
setTip(LintResultTip.default);
} else {
Expand Down Expand Up @@ -165,6 +167,7 @@ const LintResultTable: React.FC<ILintResultTableProps> = ({
className={styles.table}
style={{
flexGrow: 1,
paddingBottom: 8,
}}
>
<CallbackTable />
Expand Down
6 changes: 3 additions & 3 deletions src/page/Workspace/components/SQLResultSet/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ const getColumns = (
dataIndex: 'sql',
key: 'sql',
ellipsis: {
showTitle: true,
showTitle: false,
},
render: (text) => <Tooltip title={text}>{text}</Tooltip>,
},
{
title: formatMessage({
Expand Down Expand Up @@ -114,8 +115,7 @@ const getColumns = (
title={
sqlChanged
? formatMessage({
id:
'odc.src.page.Workspace.components.SQLResultSet.SQLContentHasBeenModified',
id: 'odc.src.page.Workspace.components.SQLResultSet.SQLContentHasBeenModified',
}) //'SQL内容已修改,已无法定位原问题行,请重新执行SQL语句或发起预检查'
: ''
}
Expand Down
7 changes: 7 additions & 0 deletions src/page/Workspace/components/SQLResultSet/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@
font-family: OBPingFangSC;
}
}
.thFilter {
:global {
.ant-table-filter-column {
padding-right: 8px;
}
}
}
.labelHover {
cursor: pointer;
}

0 comments on commit 229a92c

Please sign in to comment.