Przeglądaj źródła

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

### 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)
tags/v0.10.0
balibabu 1 rok temu
rodzic
commit
6c26872799
No account linked to committer's email address

+ 1
- 1
web/.umirc.ts Wyświetl plik

@@ -30,7 +30,7 @@ export default defineConfig({
copy: ['src/conf.json'],
proxy: {
'/v1': {
target: 'http://123.60.95.134:9380/',
target: 'http://localhost:9380/',
changeOrigin: true,
ws: true,
logger: console,

+ 21
- 0
web/src/hooks/flow-hooks.ts Wyświetl plik

@@ -191,3 +191,24 @@ export const useResetFlow = () => {

return { data, loading, resetFlow: mutateAsync };
};

export const useTestDbConnect = () => {
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['testDbConnect'],
mutationFn: async (params: any) => {
const ret = await flowService.testDbConnect(params);
if (ret?.retcode === 0) {
message.success(ret?.data?.data);
} else {
message.error(ret?.data?.data);
}
return ret;
},
});

return { data, loading, testDbConnect: mutateAsync };
};

+ 14
- 1
web/src/pages/flow/exesql-form/index.tsx Wyświetl plik

@@ -1,11 +1,19 @@
import TopNItem from '@/components/top-n-item';
import { useTranslate } from '@/hooks/common-hooks';
import { Form, Input, InputNumber, Select } from 'antd';
import { useTestDbConnect } from '@/hooks/flow-hooks';
import { Button, Flex, Form, Input, InputNumber, Select } from 'antd';
import { useCallback } from 'react';
import { ExeSQLOptions } from '../constant';
import { IOperatorForm } from '../interface';

const ExeSQLForm = ({ onValuesChange, form }: IOperatorForm) => {
const { t } = useTranslate('flow');
const { testDbConnect, loading } = useTestDbConnect();

const handleTest = useCallback(async () => {
const ret = await form?.validateFields();
testDbConnect(ret);
}, [form, testDbConnect]);

return (
<Form
@@ -59,6 +67,11 @@ const ExeSQLForm = ({ onValuesChange, form }: IOperatorForm) => {
<InputNumber></InputNumber>
</Form.Item>
<TopNItem initialValue={30} max={1000}></TopNItem>
<Flex justify={'end'}>
<Button type={'primary'} loading={loading} onClick={handleTest}>
Test
</Button>
</Flex>
</Form>
);
};

+ 5
- 0
web/src/services/flow-service.ts Wyświetl plik

@@ -10,6 +10,7 @@ const {
removeCanvas,
runCanvas,
listTemplates,
testDbConnect,
} = api;

const methods = {
@@ -41,6 +42,10 @@ const methods = {
url: listTemplates,
method: 'get',
},
testDbConnect: {
url: testDbConnect,
method: 'post',
},
} as const;

const chatService = registerServer<keyof typeof methods>(methods, request);

+ 1
- 0
web/src/utils/api.ts Wyświetl plik

@@ -94,4 +94,5 @@ export default {
setCanvas: `${api_host}/canvas/set`,
resetCanvas: `${api_host}/canvas/reset`,
runCanvas: `${api_host}/canvas/completion`,
testDbConnect: `${api_host}/canvas/test_db_connect`,
};

Ładowanie…
Anuluj
Zapisz