Unverified Commit 0afc758e authored by Licho's avatar Licho Committed by GitHub

refactor: some trivial modify on dinky-web document component. (#2092)

* refactor: package uri wrong, and trivial optimization * refactor: some trivial modify on web. * Spotless Apply --------- Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent fadcbdbd
......@@ -21,7 +21,7 @@ import {l} from '@/utils/intl';
/**
* data source type
*/
export const DATA_SOURCE_TYPE: any = [
export const DATA_SOURCE_TYPE = [
{
type: 'MySQL',
}, {
......
......@@ -20,20 +20,20 @@
import {FormInstance} from "antd/es/form/hooks/useForm";
import {Values} from "async-validator";
import {
ProForm,
ProFormItem,
ProFormSelect,
ProFormSwitch,
ProFormText,
ProFormTextArea
ProForm,
ProFormItem,
ProFormSelect,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {FORM_LAYOUT_PUBLIC} from "@/services/constants";
import React, {useEffect, useState} from "react";
import React, {useState} from "react";
import {
DOCUMENT_CATEGORY,
DOCUMENT_FUNCTION_TYPE,
DOCUMENT_SUBTYPE,
VERSIONS
DOCUMENT_CATEGORY,
DOCUMENT_FUNCTION_TYPE,
DOCUMENT_SUBTYPE,
VERSIONS
} from "@/pages/RegCenter/Document/constans";
import {l} from "@/utils/intl";
import CodeEdit from "@/components/CustomEditor/CodeEdit";
......@@ -41,174 +41,129 @@ import {Document} from "@/types/RegCenter/data";
import {DefaultOptionType} from "rc-select/lib/Select";
type DocumentFormProps = {
values: Partial<Document>;
form: FormInstance<Values>
values: Partial<Document>;
form: FormInstance<Values>
}
const CodeEditProps = {
height: "25vh",
lineNumbers: "on",
height: "25vh",
lineNumbers: "on",
}
const DocumentForm: React.FC<DocumentFormProps> = (props) => {
const {values, form} = props;
/**
* status
*/
const [codeFillValue, setCodeFillValue] = useState<string>(values.fillValue || '');
const [categoryList, setCategoryList] = useState<DefaultOptionType []>([]);
const [typeList, setTypeList] = useState<DefaultOptionType []>([]);
const [subTypeList, setSubTypeList] = useState<DefaultOptionType []>([]);
const [versionOptions, setVersionOptions] = useState<DefaultOptionType []>([]);
useEffect(() => {
let versionOptions: DefaultOptionType [] = []
let categoryOptions: DefaultOptionType [] = []
let typeOptions: DefaultOptionType [] = []
let subTypeOptions: DefaultOptionType [] = []
/**
* generate version options
*/
VERSIONS.map((item) => {
return versionOptions.push({
label: item.text,
value: item.value
})
})
setVersionOptions(versionOptions)
/**
* generate category options
*/
DOCUMENT_CATEGORY.map((item) => {
return categoryOptions.push({
label: item.text,
value: item.value
})
})
setCategoryList(categoryOptions)
/**
* generate subType options
*/
DOCUMENT_SUBTYPE.map((item) => {
return subTypeOptions.push({
label: item.text,
value: item.value
})
})
setSubTypeList(subTypeOptions)
/**
* generate type options
*/
DOCUMENT_FUNCTION_TYPE.map((item) => {
return typeOptions.push({
label: item.text,
value: item.value
})
})
setTypeList(typeOptions)
}, [])
/**
* code editor change callback
* @param value
*/
const handleFillValueChange = (value: string) => {
setCodeFillValue(value);
}
/**
* form
* @constructor
*/
const documentFormRender = () => {
return (
<>
<ProFormText
name="name"
label={l('rc.doc.name')}
placeholder={l('rc.doc.namePlaceholder')}
rules={[{required: true, message: l('rc.doc.namePlaceholder')}]}
/>
<ProFormSelect
name="category"
label={l('rc.doc.category')}
rules={[{required: true, message: l('rc.doc.categoryPlaceholder')}]}
options={categoryList}
/>
<ProFormSelect
name="type"
label={l('rc.doc.functionType')}
rules={[{required: true, message: l('rc.doc.typePlaceholder')}]}
options={typeList}
/>
<ProFormSelect
name="subtype"
label={l('rc.doc.subFunctionType')}
rules={[{required: true, message: l('rc.doc.subTypePlaceholder')}]}
options={subTypeList}
/>
<ProFormTextArea
name="description"
label={l('rc.doc.description')}
placeholder={l('rc.doc.descriptionPlaceholder')}
/>
<ProFormItem
name="fillValue"
label={l('rc.doc.fillValue')}
tooltip={l('rc.doc.fillValuePlaceholder')}
rules={[{required: true, message: l('rc.doc.fillValueHelp')}]}
>
<CodeEdit
onChange={(value => {
handleFillValueChange(value)
})}
code={codeFillValue}
language={"sql"}
{...CodeEditProps}
/>
</ProFormItem>
<ProFormSelect
name="version"
label={l('rc.doc.version')}
rules={[{required: true, message: l('rc.doc.versionPlaceholder')}]}
options={versionOptions}
/>
<ProFormSwitch
name="enabled"
label={l('global.table.isEnable')}
checkedChildren={l('button.enable')} unCheckedChildren={l('button.disable')}
/>
</>
);
};
return <>
<ProForm
{...FORM_LAYOUT_PUBLIC}
form={form}
submitter={false}
layout={'horizontal'}
initialValues={values}
const {values, form} = props;
/**
* status
*/
const [codeFillValue, setCodeFillValue] = useState<string>(values.fillValue || '');
const [categoryList] = useState<DefaultOptionType []>(
DOCUMENT_CATEGORY.map((item) => ({label: item.text, value: item.value})));
const [typeList] = useState<DefaultOptionType []>(
DOCUMENT_FUNCTION_TYPE.map((item) => ({label: item.text, value: item.value})));
const [subTypeList] = useState<DefaultOptionType []>(
DOCUMENT_SUBTYPE.map((item) => ({label: item.text, value: item.value})));
const [versionOptions] = useState<DefaultOptionType []>(
VERSIONS.map((item) => ({label: item.text, value: item.value})));
/**
* code editor change callback
* @param value
*/
const handleFillValueChange = (value: string) => {
setCodeFillValue(value);
}
/**
* form
* @constructor
*/
const documentFormRender = () => {
return (
<>
<ProFormText
name="name"
label={l('rc.doc.name')}
placeholder={l('rc.doc.namePlaceholder')}
rules={[{required: true, message: l('rc.doc.namePlaceholder')}]}
/>
<ProFormSelect
name="category"
label={l('rc.doc.category')}
rules={[{required: true, message: l('rc.doc.categoryPlaceholder')}]}
options={categoryList}
/>
<ProFormSelect
name="type"
label={l('rc.doc.functionType')}
rules={[{required: true, message: l('rc.doc.typePlaceholder')}]}
options={typeList}
/>
<ProFormSelect
name="subtype"
label={l('rc.doc.subFunctionType')}
rules={[{required: true, message: l('rc.doc.subTypePlaceholder')}]}
options={subTypeList}
/>
<ProFormTextArea
name="description"
label={l('rc.doc.description')}
placeholder={l('rc.doc.descriptionPlaceholder')}
/>
<ProFormItem
name="fillValue"
label={l('rc.doc.fillValue')}
tooltip={l('rc.doc.fillValuePlaceholder')}
rules={[{required: true, message: l('rc.doc.fillValueHelp')}]}
>
{documentFormRender()}
</ProForm>
</>;
<CodeEdit
onChange={(value => {
handleFillValueChange(value)
})}
code={codeFillValue}
language={"sql"}
{...CodeEditProps}
/>
</ProFormItem>
<ProFormSelect
name="version"
label={l('rc.doc.version')}
rules={[{required: true, message: l('rc.doc.versionPlaceholder')}]}
options={versionOptions}
/>
<ProFormSwitch
name="enabled"
label={l('global.table.isEnable')}
checkedChildren={l('button.enable')} unCheckedChildren={l('button.disable')}
/>
</>
);
};
return <>
<ProForm
{...FORM_LAYOUT_PUBLIC}
form={form}
submitter={false}
layout={'horizontal'}
initialValues={values}
>
{documentFormRender()}
</ProForm>
</>;
};
export default DocumentForm;
\ No newline at end of file
export default DocumentForm;
......@@ -54,13 +54,6 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
values
} = props;
/**
* when modalVisible or values changed, set form values
*/
useEffect(() => {
form.setFieldsValue(values);
}, [modalVisible, values, form]);
/**
* handle cancel
*/
......@@ -73,12 +66,10 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
await handleSubmit({...values, ...fieldsValue});
await handleCancel();
handleSubmit({...values, ...fieldsValue});
handleCancel();
};
return <>
<Modal
{...NORMAL_MODAL_OPTIONS}
......@@ -92,4 +83,4 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
</>
}
export default DocumentModalForm;
\ No newline at end of file
export default DocumentModalForm;
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