Skip to content

Commit e8e200e

Browse files
committed
MONGODB
1 parent 2627140 commit e8e200e

10 files changed

Lines changed: 60 additions & 44 deletions

File tree

chat2db-client/src/blocks/Tree/hooks/useGetRightClickMenu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ export const useGetRightClickMenu = (props: IProps) => {
242242
databaseType: treeNodeData.extraParams!.databaseType!,
243243
databaseName: treeNodeData.extraParams?.databaseName,
244244
schemaName: treeNodeData.extraParams?.schemaName,
245+
tableName: treeNodeData.name,
245246
sql: 'select * from ' + databaseName,
246247
},
247248
});

chat2db-client/src/components/ConnectionEdit/config/dataSource.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,11 +2070,10 @@ export const dataSourceFormConfigs: IConnectionConfig[] = [
20702070
],
20712071
pattern: /mongodb:\/\/(.*):(\d+)(\/(\w+))?/,
20722072
template: 'mongodb://{host}:{port}/{database}',
2073+
excludes: [OperationColumn.ViewDDL, OperationColumn.CreateTable,OperationColumn.EditTable]
20732074
},
20742075
ssh: sshConfig,
2075-
extendInfo: [
2076-
2077-
],
2076+
extendInfo: [],
20782077
type: DatabaseTypeCode.MONGODB
20792078
},
20802079
];

chat2db-client/src/components/ConnectionEdit/config/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export type IConnectionConfig = {
3939
pattern: RegExp;
4040
template: string;
4141
excludes?: OperationColumn[];
42-
4342
},
4443
driver?: {
4544
items: IFormItem[];

chat2db-client/src/components/ConsoleEditor/components/OperationLine/index.tsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22
import i18n from '@/i18n';
3-
import { Button } from 'antd';
3+
import { Button, Popover } from 'antd';
44
import { IBoundInfo } from '@/typings/workspace';
55
import styles from './index.less';
66
import Iconfont from '@/components/Iconfont';
77
import SelectBoundInfo from '../SelectBoundInfo';
88
import { formatSql } from '@/utils/sql';
9+
import { osNow } from '@/utils';
910

1011
interface IProps {
1112
boundInfo: IBoundInfo;
@@ -16,6 +17,19 @@ interface IProps {
1617
hasSaveBtn: boolean;
1718
}
1819

20+
const keyboardKey = (function () {
21+
if (osNow().isMac) {
22+
return {
23+
command: 'Cmd',
24+
Shift: 'Shift',
25+
};
26+
}
27+
return {
28+
command: 'Ctrl',
29+
Shift: 'Shift',
30+
};
31+
})();
32+
1933
const OperationLine = (props: IProps) => {
2034
const { boundInfo, saveConsole, editorRef, hasSaveBtn, executeSQL, setBoundInfo } = props;
2135

@@ -37,18 +51,22 @@ const OperationLine = (props: IProps) => {
3751
return (
3852
<div className={styles.consoleOptionsWrapper}>
3953
<div className={styles.consoleOptionsLeft}>
40-
<Button type="primary" className={styles.runButton} onClick={() => executeSQL()}>
41-
<Iconfont code="&#xe637;" />
42-
{i18n('common.button.execute')}
43-
</Button>
44-
{hasSaveBtn && (
45-
<Button
46-
type="default"
47-
className={styles.saveButton}
48-
onClick={() => saveConsole(editorRef?.current?.getAllContent())}
49-
>
50-
{i18n('common.button.save')}
54+
<Popover mouseEnterDelay={0.8} content={[keyboardKey.command, 'R'].join('+')} trigger="hover">
55+
<Button type="primary" className={styles.runButton} onClick={() => executeSQL()}>
56+
<Iconfont code="&#xe637;" />
57+
{i18n('common.button.execute')}
5158
</Button>
59+
</Popover>
60+
{hasSaveBtn && (
61+
<Popover mouseEnterDelay={0.8} content={[keyboardKey.command, 'S'].join('+')} trigger="hover">
62+
<Button
63+
type="default"
64+
className={styles.saveButton}
65+
onClick={() => saveConsole(editorRef?.current?.getAllContent())}
66+
>
67+
{i18n('common.button.save')}
68+
</Button>
69+
</Popover>
5270
)}
5371
<Button type="default" onClick={handleSQLFormat}>
5472
{i18n('common.button.format')}

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,13 @@ export default function TableBox(props: ITableProps) {
295295
setCurOperationRowNo(null);
296296
// 当前聚焦或者编辑的单元格的数据
297297
setEditingData(value);
298+
// 如果数据不支持修改,则该单元格不支持编辑
299+
if (!queryResultData.canEdit) {
300+
setEditingCell([colId, rowId, false]);
301+
} else {
302+
setEditingCell([colId, rowId, isEditing]);
303+
}
298304
// 当前聚焦或者编辑的单元格的坐标
299-
setEditingCell([colId, rowId, isEditing]);
300305
// 如果是编辑状态,则需要聚焦到input
301306
if (isEditing) {
302307
setTimeout(() => {
@@ -611,7 +616,7 @@ export default function TableBox(props: ITableProps) {
611616
className={styles.allSelectBox}
612617
onClick={() => {
613618
setEditingCell(null);
614-
if(curOperationRowNo){
619+
if (curOperationRowNo) {
615620
setCurOperationRowNo(null);
616621
return;
617622
}
@@ -888,16 +893,6 @@ export default function TableBox(props: ITableProps) {
888893
};
889894

890895
const rowRightClickMenu = useMemo(() => {
891-
// const allSupportedMenus = {
892-
// [AllSupportedMenusType.CopyCell]: copyCell,
893-
// [AllSupportedMenusType.CopyRow]: copyRow,
894-
// [AllSupportedMenusType.CloneRow]: cloneRow,
895-
// [AllSupportedMenusType.DeleteRow]: deleteRow,
896-
// [AllSupportedMenusType.SetDefault]: setDefault,
897-
// [AllSupportedMenusType.SetNull]: setNull,
898-
// [AllSupportedMenusType.ViewData]: viewData,
899-
// }
900-
901896
let rightClickMenu: any = [];
902897
if (curOperationRowNo) {
903898
rightClickMenu = [copyRow, cloneRow, deleteRow];

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface IProps {
3030
sql?: string;
3131
executeSqlParams: any;
3232
concealTabHeader?: boolean;
33+
viewTable?: boolean;
3334
}
3435

3536
const defaultResultConfig: IResultConfig = {
@@ -45,13 +46,13 @@ export interface ISearchResultRef {
4546

4647
interface IContext {
4748
// 这里不用ref的话,会导致切换时闪动
48-
activeTabIdRef: React.MutableRefObject<null | string>
49+
activeTabIdRef: React.MutableRefObject<null | string>;
4950
}
5051

5152
export const Context = createContext<IContext>({} as any);
5253

5354
export default forwardRef((props: IProps, ref: ForwardedRef<ISearchResultRef>) => {
54-
const { className, sql, executeSqlParams, concealTabHeader } = props;
55+
const { className, sql, executeSqlParams, concealTabHeader, viewTable } = props;
5556
const [resultDataList, setResultDataList] = useState<IManageResultData[]>();
5657
const [tableLoading, setTableLoading] = useState(false);
5758
const controllerRef = useRef<AbortController>();
@@ -73,19 +74,20 @@ export default forwardRef((props: IProps, ref: ForwardedRef<ISearchResultRef>) =
7374
*/
7475
const handleExecuteSQL = (_sql: string) => {
7576
setTableLoading(true);
77+
const api = viewTable ? sqlServer.viewTable : sqlServer.executeSql;
7678

7779
const executeSQLParams: IExecuteSqlParams = {
7880
sql: _sql,
81+
tableName: executeSqlParams?.tableName,
7982
...defaultResultConfig,
8083
...executeSqlParams,
8184
};
8285

8386
controllerRef.current = new AbortController();
8487
// 获取当前SQL的查询结果
85-
sqlServer
86-
.executeSql(executeSQLParams, {
87-
signal: controllerRef.current.signal,
88-
})
88+
api(executeSQLParams, {
89+
signal: controllerRef.current.signal,
90+
})
8991
.then((res) => {
9092
const sqlResult = res.map((_res) => ({
9193
..._res,

chat2db-client/src/constants/database.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ export const databaseMap: {
118118
// port: 27017,
119119
icon: '\uec21',
120120
},
121-
[DatabaseTypeCode.REDIS]: {
122-
name: 'Redis',
123-
img: moreDBLogo,
124-
code: DatabaseTypeCode.REDIS,
125-
// port: 6379,
126-
icon: '\ue6a2',
127-
},
121+
// [DatabaseTypeCode.REDIS]: {
122+
// name: 'Redis',
123+
// img: moreDBLogo,
124+
// code: DatabaseTypeCode.REDIS,
125+
// // port: 6379,
126+
// icon: '\ue6a2',
127+
// },
128128
};
129129

130130
export const databaseTypeList = Object.keys(databaseMap).map((keys) => {

chat2db-client/src/pages/main/workspace/components/SaveList/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { approximateList } from '@/utils';
1111
import { addWorkspaceTab, getSavedConsoleList } from '@/pages/main/workspace/store/console';
1212
import { useWorkspaceStore } from '@/pages/main/workspace/store';
1313
import MenuLabel from '@/components/MenuLabel';
14-
import { set } from 'lodash';
1514

1615
const SaveList = () => {
1716
const [searching, setSearching] = useState<boolean>(false);

chat2db-client/src/pages/main/workspace/components/WorkspaceTabs/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ const WorkspaceTabs = memo(() => {
179179
// 渲染搜索结果
180180
const renderSearchResult = (item: IWorkspaceTab) => {
181181
const { uniqueData } = item;
182-
return <SearchResult sql={uniqueData.sql} executeSqlParams={uniqueData} concealTabHeader />;
182+
return <SearchResult sql={uniqueData.sql} executeSqlParams={uniqueData} viewTable concealTabHeader />;
183183
};
184184

185185
// 渲染所有表

chat2db-client/src/service/sql.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const getTableList = createRequest<IGetTableListParams, IPageResponse<ITable>>('
4848

4949
const executeSql = createRequest<IExecuteSqlParams, IManageResultData[]>('/api/rdb/dml/execute', { method: 'post', delayTime: 10 });
5050

51+
const viewTable = createRequest<IExecuteSqlParams, IManageResultData[]>('/api/rdb/dml/execute_table', { method: 'post', delayTime: 10 });
52+
5153
const connectConsole = createRequest<IConnectConsoleParams, void>('/api/connection/console/connect', { method: 'get' });
5254

5355
//表操作
@@ -322,12 +324,13 @@ export default {
322324
getViewList,
323325
getTableList,
324326
executeSql,
327+
executeTable,
325328
connectConsole,
326329
deleteTable,
327330
createTableExample,
328331
updateTableExample,
329332
exportCreateTableSql,
330-
executeTable,
333+
viewTable,
331334
getColumnList,
332335
getIndexList,
333336
getKeyList,

0 commit comments

Comments
 (0)