Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/.umirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 21 additions & 0 deletions web/src/hooks/flow-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
15 changes: 14 additions & 1 deletion web/src/pages/flow/exesql-form/index.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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>
);
};
Expand Down
5 changes: 5 additions & 0 deletions web/src/services/flow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
removeCanvas,
runCanvas,
listTemplates,
testDbConnect,
} = api;

const methods = {
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions web/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
};