balibabu commited on
Commit
eb002c7
·
1 Parent(s): 6b7630c

feat: Test the database connection of the ExeSQL operator #1739 (#2036)

Browse files

### What problem does this PR solve?

feat: Test the database connection of the ExeSQL operator #1739
### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/.umirc.ts CHANGED
@@ -30,7 +30,7 @@ export default defineConfig({
30
  copy: ['src/conf.json'],
31
  proxy: {
32
  '/v1': {
33
- target: 'http://123.60.95.134:9380/',
34
  changeOrigin: true,
35
  ws: true,
36
  logger: console,
 
30
  copy: ['src/conf.json'],
31
  proxy: {
32
  '/v1': {
33
+ target: 'http://localhost:9380/',
34
  changeOrigin: true,
35
  ws: true,
36
  logger: console,
web/src/hooks/flow-hooks.ts CHANGED
@@ -191,3 +191,24 @@ export const useResetFlow = () => {
191
 
192
  return { data, loading, resetFlow: mutateAsync };
193
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
 
192
  return { data, loading, resetFlow: mutateAsync };
193
  };
194
+
195
+ export const useTestDbConnect = () => {
196
+ const {
197
+ data,
198
+ isPending: loading,
199
+ mutateAsync,
200
+ } = useMutation({
201
+ mutationKey: ['testDbConnect'],
202
+ mutationFn: async (params: any) => {
203
+ const ret = await flowService.testDbConnect(params);
204
+ if (ret?.retcode === 0) {
205
+ message.success(ret?.data?.data);
206
+ } else {
207
+ message.error(ret?.data?.data);
208
+ }
209
+ return ret;
210
+ },
211
+ });
212
+
213
+ return { data, loading, testDbConnect: mutateAsync };
214
+ };
web/src/pages/flow/exesql-form/index.tsx CHANGED
@@ -1,11 +1,19 @@
1
  import TopNItem from '@/components/top-n-item';
2
  import { useTranslate } from '@/hooks/common-hooks';
3
- import { Form, Input, InputNumber, Select } from 'antd';
 
 
4
  import { ExeSQLOptions } from '../constant';
5
  import { IOperatorForm } from '../interface';
6
 
7
  const ExeSQLForm = ({ onValuesChange, form }: IOperatorForm) => {
8
  const { t } = useTranslate('flow');
 
 
 
 
 
 
9
 
10
  return (
11
  <Form
@@ -59,6 +67,11 @@ const ExeSQLForm = ({ onValuesChange, form }: IOperatorForm) => {
59
  <InputNumber></InputNumber>
60
  </Form.Item>
61
  <TopNItem initialValue={30} max={1000}></TopNItem>
 
 
 
 
 
62
  </Form>
63
  );
64
  };
 
1
  import TopNItem from '@/components/top-n-item';
2
  import { useTranslate } from '@/hooks/common-hooks';
3
+ import { useTestDbConnect } from '@/hooks/flow-hooks';
4
+ import { Button, Flex, Form, Input, InputNumber, Select } from 'antd';
5
+ import { useCallback } from 'react';
6
  import { ExeSQLOptions } from '../constant';
7
  import { IOperatorForm } from '../interface';
8
 
9
  const ExeSQLForm = ({ onValuesChange, form }: IOperatorForm) => {
10
  const { t } = useTranslate('flow');
11
+ const { testDbConnect, loading } = useTestDbConnect();
12
+
13
+ const handleTest = useCallback(async () => {
14
+ const ret = await form?.validateFields();
15
+ testDbConnect(ret);
16
+ }, [form, testDbConnect]);
17
 
18
  return (
19
  <Form
 
67
  <InputNumber></InputNumber>
68
  </Form.Item>
69
  <TopNItem initialValue={30} max={1000}></TopNItem>
70
+ <Flex justify={'end'}>
71
+ <Button type={'primary'} loading={loading} onClick={handleTest}>
72
+ Test
73
+ </Button>
74
+ </Flex>
75
  </Form>
76
  );
77
  };
web/src/services/flow-service.ts CHANGED
@@ -10,6 +10,7 @@ const {
10
  removeCanvas,
11
  runCanvas,
12
  listTemplates,
 
13
  } = api;
14
 
15
  const methods = {
@@ -41,6 +42,10 @@ const methods = {
41
  url: listTemplates,
42
  method: 'get',
43
  },
 
 
 
 
44
  } as const;
45
 
46
  const chatService = registerServer<keyof typeof methods>(methods, request);
 
10
  removeCanvas,
11
  runCanvas,
12
  listTemplates,
13
+ testDbConnect,
14
  } = api;
15
 
16
  const methods = {
 
42
  url: listTemplates,
43
  method: 'get',
44
  },
45
+ testDbConnect: {
46
+ url: testDbConnect,
47
+ method: 'post',
48
+ },
49
  } as const;
50
 
51
  const chatService = registerServer<keyof typeof methods>(methods, request);
web/src/utils/api.ts CHANGED
@@ -94,4 +94,5 @@ export default {
94
  setCanvas: `${api_host}/canvas/set`,
95
  resetCanvas: `${api_host}/canvas/reset`,
96
  runCanvas: `${api_host}/canvas/completion`,
 
97
  };
 
94
  setCanvas: `${api_host}/canvas/set`,
95
  resetCanvas: `${api_host}/canvas/reset`,
96
  runCanvas: `${api_host}/canvas/completion`,
97
+ testDbConnect: `${api_host}/canvas/test_db_connect`,
98
  };