Skip to content

Commit b376c50

Browse files
committed
sql execution error message
1 parent 6f70edc commit b376c50

11 files changed

Lines changed: 60 additions & 46 deletions

File tree

chat2db-client/src/blocks/SQLExecute/index.less

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,12 @@
4141
}
4242
}
4343
}
44+
45+
.noData {
46+
height: 100%;
47+
display: flex;
48+
flex-direction: column;
49+
justify-content: center;
50+
align-items: center;
51+
font-size: 12px;
52+
}

chat2db-client/src/blocks/SQLExecute/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { v4 as uuidV4 } from 'uuid';
1515
import { isNumber } from 'lodash';
1616
import { Spin } from 'antd';
1717
import { useUpdateEffect } from '@/hooks/useUpdateEffect';
18+
import i18n from '@/i18n';
19+
import EmptyImg from '@/assets/img/empty.svg';
1820
interface IProps {
1921
className?: string;
2022
isActive: boolean;
@@ -163,6 +165,15 @@ const SQLExecute = memo<IProps>((props) => {
163165
setTableLoading(false);
164166
};
165167

168+
const renderEmpty = () => {
169+
return (
170+
<div className={styles.noData}>
171+
<img src={EmptyImg} />
172+
<p>{i18n('common.text.noData')}</p>
173+
</div>
174+
);
175+
};
176+
166177
return (
167178
<div className={classnames(styles.box)}>
168179
<DraggableContainer layout="column" className={styles.boxRightCenter}>
@@ -201,10 +212,10 @@ const SQLExecute = memo<IProps>((props) => {
201212
<div className={styles.tableLoading}>
202213
<Spin />
203214
<div className={styles.stopExecuteSql} onClick={stopExecuteSql}>
204-
取消请求
215+
{i18n('common.button.cancelRequest')}
205216
</div>
206217
</div>
207-
) : (
218+
) : resultData?.length ? (
208219
<SearchResult
209220
onTabEdit={handleResultTabEdit}
210221
onExecute={handleExecuteSQLbyConfigChanged}
@@ -213,6 +224,8 @@ const SQLExecute = memo<IProps>((props) => {
213224
resultConfig={resultConfig}
214225
manageResultDataList={resultData}
215226
/>
227+
) : (
228+
renderEmpty()
216229
)}
217230
</div>
218231
</DraggableContainer>

chat2db-client/src/components/ExecuteSQL/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DatabaseTypeCode } from '@/constants';
1212
interface IProps {
1313
className?: string;
1414
initSql: string;
15+
initError?: string;
1516
databaseType: DatabaseTypeCode;
1617
databaseName: string;
1718
dataSourceId: number;
@@ -24,6 +25,7 @@ export default memo<IProps>((props) => {
2425
const {
2526
className,
2627
initSql,
28+
initError,
2729
databaseType,
2830
databaseName,
2931
dataSourceId,
@@ -38,6 +40,7 @@ export default memo<IProps>((props) => {
3840

3941
useEffect(() => {
4042
setAppendValue(initSql);
43+
setExecuteSqlResult(initError || null);
4144
}, []);
4245

4346
const handleFormatSql = () => {

chat2db-client/src/components/MyNotification/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface IProps {
2020
/** 请求的接口 */
2121
requestUrl: string;
2222
/** 请求的参数 */
23-
requestParams: string;
23+
requestParams?: string;
2424
}
2525

2626
function MyNotification() {
@@ -79,7 +79,8 @@ function MyNotification() {
7979
}, []);
8080

8181
function renderModalTitle() {
82-
return <div className={styles.modalTitle}>{`${props?.errorCode}${props?.errorMessage} `}</div>;
82+
const list = [props?.errorCode, props?.errorMessage];
83+
return <div className={styles.modalTitle}>{list.filter((t) => t).join(':')}</div>;
8384
}
8485

8586
function copyError() {
@@ -92,13 +93,16 @@ function MyNotification() {
9293
}
9394

9495
function renderModalFooter() {
95-
return (
96-
<div className={styles.modalFooter} onClick={copyError}>
97-
<Iconfont code="&#xeb4e;" />
98-
{i18n('common.button.copyError')}
99-
<span className={styles.copyErrorTips}>{i18n('common.button.copyErrorTips')}</span>
100-
</div>
101-
);
96+
if (props?.requestParams) {
97+
return (
98+
<div className={styles.modalFooter} onClick={copyError}>
99+
<Iconfont code="&#xeb4e;" />
100+
{i18n('common.button.copyError')}
101+
<span className={styles.copyErrorTips}>{i18n('common.button.copyErrorTips')}</span>
102+
</div>
103+
);
104+
}
105+
return false;
102106
}
103107

104108
return (

chat2db-client/src/components/SearchResult/TableBox/index.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,7 @@
201201
overflow: hidden;
202202
height: 60vh;
203203
}
204+
205+
.errorDetail {
206+
white-space: normal;
207+
}

chat2db-client/src/components/SearchResult/TableBox/index.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useMemo, useState } from 'react';
2-
import { Button, Dropdown, Input, MenuProps, message, Modal, Space } from 'antd';
2+
import { Dropdown, Input, MenuProps, message, Modal, Space } from 'antd';
33
import { BaseTable, ArtColumn, useTablePipeline, features, SortItem } from 'ali-react-table';
44
import styled from 'styled-components';
55
import classnames from 'classnames';
@@ -19,7 +19,7 @@ import MyPagination from '../Pagination';
1919
import styles from './index.less';
2020
import sqlService, { IExportParams, IExecuteSqlParams } from '@/service/sql';
2121
import { downloadFile } from '@/utils/common';
22-
import lodash from 'lodash';
22+
import lodash, { set } from 'lodash';
2323

2424
interface ITableProps {
2525
className?: string;
@@ -79,6 +79,7 @@ export default function TableBox(props: ITableProps) {
7979
const [curOperationRowNo, setCurOperationRowNo] = useState<string | null>(null);
8080
const [updateData, setUpdateData] = useState<IUpdateData[] | []>([]);
8181
const [updateDataSql, setUpdateDataSql] = useState<string>('');
82+
const [initError, setInitError] = useState<string>('');
8283
const [viewUpdateDataSql, setViewUpdateDataSql] = useState<boolean>(false);
8384
const tableBoxRef = React.useRef<HTMLDivElement>(null);
8485

@@ -467,15 +468,11 @@ export default function TableBox(props: ITableProps) {
467468
if (res.success) {
468469
message.success(i18n('common.text.successfulExecution'));
469470
setUpdateData([]);
471+
// 在执行一遍sql,刷新数据?// TODO:
470472
} else {
471-
// window._notificationApi({
472-
// requestUrl: eventualUrl,
473-
// requestParams: JSON.stringify(params),
474-
// errorCode,
475-
// errorMessage,
476-
// errorDetail,
477-
// solutionLink,
478-
// });
473+
setUpdateDataSql(res.originalSql);
474+
setViewUpdateDataSql(true);
475+
setInitError(res.message);
479476
}
480477
});
481478
};
@@ -649,16 +646,18 @@ export default function TableBox(props: ITableProps) {
649646
<Modal
650647
width="60vw"
651648
maskClosable={false}
652-
title={i18n('editTable.title.sqlPreview')}
649+
title={initError ? i18n('common.button.executionError') : i18n('editTable.title.sqlPreview')}
653650
open={viewUpdateDataSql}
654651
footer={false}
655652
destroyOnClose={true}
656653
onCancel={() => {
657654
setViewUpdateDataSql(false);
658655
setUpdateDataSql('');
656+
setInitError('');
659657
}}
660658
>
661659
<ExecuteSQL
660+
initError={initError}
662661
initSql={updateDataSql}
663662
databaseName={props.executeSqlParams?.databaseName}
664663
dataSourceId={props.executeSqlParams?.dataSourceId}

chat2db-client/src/components/SearchResult/index.less

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@
4040
margin: -15px;
4141
}
4242

43-
.noData {
44-
height: 100%;
45-
display: flex;
46-
flex-direction: column;
47-
justify-content: center;
48-
align-items: center;
49-
font-size: 12px;
50-
}
51-
5243
.cursorStateIndicator {
5344
margin: 0 auto;
5445
max-width: 80%;

chat2db-client/src/components/SearchResult/index.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import StateIndicator from '@/components/StateIndicator';
66
import { IManageResultData, IResultConfig } from '@/typings';
77
import TableBox from './TableBox';
88
import styles from './index.less';
9-
import i18n from '@/i18n';
10-
import EmptyImg from '@/assets/img/empty.svg';
119

1210
interface IProps {
1311
className?: string;
@@ -90,18 +88,9 @@ export default memo<IProps>((props) => {
9088
});
9189
}, [resultDataList]);
9290

93-
const renderEmpty = () => {
94-
return (
95-
<div className={styles.noData}>
96-
<img src={EmptyImg} />
97-
<p>{i18n('common.text.noData')}</p>
98-
</div>
99-
);
100-
};
101-
10291
return (
10392
<div className={classnames(className, styles.searchResult)}>
104-
{tabsList.length ? (
93+
{tabsList.length && (
10594
<TabsNew
10695
hideAdd
10796
className={styles.tabs}
@@ -110,8 +99,6 @@ export default memo<IProps>((props) => {
11099
activeKey={currentTab}
111100
items={tabsList}
112101
/>
113-
) : (
114-
renderEmpty()
115102
)}
116103
</div>
117104
);

chat2db-client/src/i18n/en-us/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@ export default {
8787
'common.text.action': 'Action',
8888
'common.button.add': 'Add',
8989
'common.text.errorMessage': 'Error Message',
90+
'common.button.cancelRequest': 'Cancel Request',
91+
'common.button.executionError': 'Execution Error',
9092

9193
};

chat2db-client/src/i18n/zh-cn/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,7 @@ export default {
8585
'common.text.action': '操作',
8686
'common.button.add': '添加',
8787
'common.text.errorMessage': '错误信息',
88+
'common.button.cancelRequest': '取消请求',
89+
'common.button.executionError': '执行错误',
8890

8991
};

0 commit comments

Comments
 (0)