Unverified Commit 02a3bf3d authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Optimization-2755] Optimization datasource detail search box (#2853)

* fix-datasource-detail-search-bug * Spotless Apply --------- Co-authored-by: 's avatarZzm0809 <Zzm0809@users.noreply.github.com>
parent fda2de4f
...@@ -18,12 +18,12 @@ ...@@ -18,12 +18,12 @@
*/ */
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { ProForm, ProFormText } from '@ant-design/pro-components'; import { ProForm, ProFormItem } from '@ant-design/pro-components';
import { AutoComplete } from 'antd'; import { AutoComplete, Input } from 'antd';
import { FormInstance } from 'antd/es/form/hooks/useForm'; import { FormInstance } from 'antd/es/form/hooks/useForm';
import { Values } from 'async-validator'; import { Values } from 'async-validator';
import { DefaultOptionType } from 'rc-select/es/Select'; import { DefaultOptionType } from 'rc-select/es/Select';
import React from 'react'; import React, { useState } from 'react';
type QueryFormProps = { type QueryFormProps = {
form: FormInstance<Values>; form: FormInstance<Values>;
...@@ -42,44 +42,60 @@ const QueryForm: React.FC<QueryFormProps> = (props) => { ...@@ -42,44 +42,60 @@ const QueryForm: React.FC<QueryFormProps> = (props) => {
submitHandle(values); submitHandle(values);
}; };
/** const [condition, setCondition] = useState<{
* handle change where: string;
* @param value order: string;
* @param tag }>({
*/ where: '',
const handleChange = (value: string, tag: string) => { order: ''
switch (tag) {
case 'where':
form.setFieldsValue({
where: `${(form.getFieldsValue().where || '') + value}`
});
break;
case 'order':
form.setFieldsValue({
order: `${(form.getFieldsValue().order || '') + value}`
}); });
break;
} const handleOrderChange = (value: string) => {
setCondition((prevState) => ({
...prevState,
order: prevState.where + `${value} ,`
}));
};
const handleWhereChange = (value: string) => {
setCondition((prevState) => ({
...prevState,
where: prevState.where + ` ${value} and`
}));
}; };
const renderForm = () => { const renderForm = () => {
return ( return (
<> <>
<ProFormItem
key='where'
name='where'
required
initialValue={condition.where}
addonBefore={'WHERE'}
>
<AutoComplete <AutoComplete
backfill
autoFocus
options={autoCompleteColumns} options={autoCompleteColumns}
onSelect={(value: string) => handleChange(value, 'where')} onSelect={(value: string) => handleWhereChange(value)}
> >
<ProFormText addonBefore={'WHERE'} width={'md'} key='where' name='where' required /> <Input value={condition.where} style={{ width: '25vw' }} maxLength={2000} />
</AutoComplete> </AutoComplete>
</ProFormItem>
<ProFormItem
key='order'
name='order'
initialValue={condition.order}
required
addonBefore={'ORDER BY'}
>
<AutoComplete <AutoComplete
options={autoCompleteColumns} options={autoCompleteColumns}
onSelect={(value: string) => handleChange(value, 'order')} onSelect={(value: string) => handleOrderChange(value)}
> >
<ProFormText addonBefore={'ORDER BY'} width={'md'} key='order' name='order' required /> <Input value={condition.order} style={{ width: '25vw' }} maxLength={2000} />
</AutoComplete> </AutoComplete>
</ProFormItem>
</> </>
); );
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment