Unverified Commit 678817b5 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

Improve document form layout (#2849)

* improve-document-form-layout * delete un use code * delete some code
parent cac5239d
......@@ -113,7 +113,7 @@ const JobModal: React.FC<JobModalProps> = (props) => {
// if this type is flink job, init task value and submit
if (isFlinkJob(formData.type ?? '')) {
const initTaskValue = {
savePointStrategy: -1, // -1 is disabled
savePointStrategy: 0, // 0 is disabled
parallelism: 1, // default parallelism
envId: -1, // -1 is disabled
step: 1, // default step is develop
......
......@@ -422,7 +422,6 @@ const Model: ModelType = {
},
*queryEnv({ payload }, { call, put }) {
const response: EnvType[] = yield call(getEnvData, payload);
console.log(response);
yield put({
type: 'saveEnv',
payload: response
......@@ -463,13 +462,6 @@ const Model: ModelType = {
payload: response
});
},
*queryEnv({ payload }, { call, put }) {
const response: EnvType[] = yield call(getEnvData, payload);
yield put({
type: 'saveEnv',
payload: response
});
},
*queryClusterConfigurationData({ payload }, { call, put }) {
const response: Cluster.Config[] = yield call(getClusterConfigurationData, payload);
yield put({
......
......@@ -18,18 +18,17 @@
*/
import CodeEdit from '@/components/CustomEditor/CodeEdit';
import { JOB_TYPE } from '@/pages/DataStudio/LeftContainer/Project/constants';
import {JOB_TYPE} from '@/pages/DataStudio/LeftContainer/Project/constants';
import {
DOCUMENT_CATEGORY_ENUMS,
DOCUMENT_FUNCTION_TYPE_ENUMS,
DOCUMENT_TYPE_ENUMS,
VERSIONS
} from '@/pages/RegCenter/Document/constans';
import { FORM_LAYOUT_PUBLIC } from '@/services/constants';
import { Document } from '@/types/RegCenter/data';
import { l } from '@/utils/intl';
import {Document} from '@/types/RegCenter/data';
import {l} from '@/utils/intl';
import {
ProForm,
ProFormGroup,
ProFormItem,
ProFormSegmented,
ProFormSelect,
......@@ -37,11 +36,10 @@ import {
ProFormText,
ProFormTextArea
} from '@ant-design/pro-components';
import { ProFormDependency } from '@ant-design/pro-form';
import { FormInstance } from 'antd/es/form/hooks/useForm';
import { Values } from 'async-validator';
import { DefaultOptionType } from 'rc-select/lib/Select';
import React, { useState } from 'react';
import {FormInstance} from 'antd/es/form/hooks/useForm';
import {Values} from 'async-validator';
import {DefaultOptionType} from 'rc-select/lib/Select';
import React, {useState} from 'react';
type DocumentFormProps = {
values: Partial<Document>;
......@@ -54,16 +52,16 @@ const CodeEditProps = {
};
const DocumentForm: React.FC<DocumentFormProps> = (props) => {
const { values, form } = props;
const {values, form} = props;
/**
* status
*/
const [codeFillValue, setCodeFillValue] = useState<string>(values.fillValue || '');
const { FLINK_OPTIONS, SQL_TEMPLATE, FUN_UDF, OTHER } = DOCUMENT_TYPE_ENUMS;
const {FLINK_OPTIONS, SQL_TEMPLATE, FUN_UDF, OTHER} = DOCUMENT_TYPE_ENUMS;
const [CATEGORY_LIST] = useState<DefaultOptionType[]>(
Object.values(DOCUMENT_CATEGORY_ENUMS).map((item) => ({ label: item.text, value: item.value }))
Object.values(DOCUMENT_CATEGORY_ENUMS).map((item) => ({label: item.text, value: item.value}))
);
const [FUNCTION_TYPES] = useState<DefaultOptionType[]>(
......@@ -74,17 +72,11 @@ const DocumentForm: React.FC<DocumentFormProps> = (props) => {
);
const [VERSION_OPTIONS] = useState<DefaultOptionType[]>(
VERSIONS.map((item) => ({ label: item.text, value: item.value }))
VERSIONS.map((item) => ({label: item.text, value: item.value}))
);
const onTypeAndNameChange = (type: string, name: string) => {
if (type == FLINK_OPTIONS.value) {
const fillValue = "set '" + name + "' = '${1:}'";
form.setFieldsValue({ category: 'Varible' });
form.setFieldsValue({ fillValue: fillValue });
setCodeFillValue(fillValue);
}
};
const [documentType, setDocumentType] = useState<string>('');
/**
* form
......@@ -93,51 +85,62 @@ const DocumentForm: React.FC<DocumentFormProps> = (props) => {
const documentFormRender = () => {
return (
<>
<ProFormSegmented
name='type'
label={l('rc.doc.functionType')}
rules={[{ required: true, message: l('rc.doc.typePlaceholder') }]}
valueEnum={DOCUMENT_TYPE_ENUMS}
/>
<ProFormGroup>
<ProFormSegmented
name='type'
label={l('rc.doc.functionType')}
initialValue={SQL_TEMPLATE.value}
rules={[{required: true, message: l('rc.doc.typePlaceholder')}]}
valueEnum={DOCUMENT_TYPE_ENUMS} fieldProps={{onChange: (value) => setDocumentType(value as string)}}
/>
<ProFormText
name='name'
label={l('rc.doc.name')}
placeholder={l('rc.doc.namePlaceholder')}
rules={[{ required: true, message: l('rc.doc.namePlaceholder') }]}
/>
<ProFormText
name='name'
width={'md'}
label={l('rc.doc.name')}
placeholder={l('rc.doc.namePlaceholder')}
rules={[{required: true, message: l('rc.doc.namePlaceholder')}]}
/>
<ProFormSwitch
name='enabled'
label={l('global.table.isEnable')}
checkedChildren={l('button.enable')}
unCheckedChildren={l('button.disable')}
/>
<ProFormDependency name={['type', 'name']}>
{({ type, name }) => {
onTypeAndNameChange(type, name);
return (
<>
{type != FLINK_OPTIONS.value && type != OTHER.value && (
<ProFormSelect
name='subtype'
label={l('rc.doc.subFunctionType')}
rules={[{ required: true, message: l('rc.doc.subTypePlaceholder') }]}
options={type == FUN_UDF.value ? FUNCTION_TYPES : JOB_TYPE}
/>
)}
<ProFormSelect
disabled={type == FLINK_OPTIONS.value}
name='category'
label={l('rc.doc.category')}
rules={[{ required: true, message: l('rc.doc.categoryPlaceholder') }]}
options={CATEGORY_LIST}
/>
</>
);
}}
</ProFormDependency>
</ProFormGroup>
<ProFormGroup>
<ProFormSelect
name='subtype'
width={'sm'}
label={l('rc.doc.subFunctionType')}
rules={[{required: true, message: l('rc.doc.subTypePlaceholder')}]}
options={documentType == FUN_UDF.value ? FUNCTION_TYPES : JOB_TYPE}
/>
<ProFormSelect
name='category'
width={'sm'}
label={l('rc.doc.category')}
rules={[{required: true, message: l('rc.doc.categoryPlaceholder')}]}
options={CATEGORY_LIST}
/>
<ProFormSelect
name='version'
width={'sm'}
label={l('rc.doc.version')}
rules={[{required: true, message: l('rc.doc.versionPlaceholder')}]}
options={VERSION_OPTIONS}
/>
</ProFormGroup>
<ProFormItem
name='fillValue'
label={l('rc.doc.fillValue')}
tooltip={l('rc.doc.fillValuePlaceholder')}
rules={[{ required: true, message: l('rc.doc.fillValueHelp') }]}
rules={[{required: true, message: l('rc.doc.fillValueHelp')}]}
>
<CodeEdit
code={codeFillValue}
......@@ -152,35 +155,13 @@ const DocumentForm: React.FC<DocumentFormProps> = (props) => {
label={l('rc.doc.description')}
placeholder={l('rc.doc.descriptionPlaceholder')}
/>
<ProFormSelect
name='version'
label={l('rc.doc.version')}
rules={[{ required: true, message: l('rc.doc.versionPlaceholder') }]}
options={VERSION_OPTIONS}
/>
<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>
{documentFormRender()}
</>
);
};
......
......@@ -19,11 +19,12 @@
import { FormContextValue } from '@/components/Context/FormContext';
import DocumentForm from '@/pages/RegCenter/Document/components/DocumentModal/DocumentForm';
import { NORMAL_MODAL_OPTIONS } from '@/services/constants';
import {MODAL_FORM_OPTIONS} from '@/services/constants';
import { Document } from '@/types/RegCenter/data';
import { l } from '@/utils/intl';
import { Form, Modal } from 'antd';
import {Form} from 'antd';
import React, { useEffect } from 'react';
import {ModalForm} from "@ant-design/pro-components";
type DocumentModalProps = {
onCancel: (flag?: boolean) => void;
......@@ -68,26 +69,28 @@ const DocumentModalForm: React.FC<DocumentModalProps> = (props) => {
/**
* submit form
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
handleSubmit({ ...values, ...fieldsValue });
const submitForm = async (formValue: Partial<Document>) => {
await form.validateFields();
handleSubmit({ ...values, ...formValue });
await handleCancel();
};
return (
<Modal
{...NORMAL_MODAL_OPTIONS}
<ModalForm<Partial<Document>>
{...MODAL_FORM_OPTIONS}
title={values.id ? l('rc.doc.modify') : l('rc.doc.create')}
open={modalVisible}
okButtonProps={{
htmlType: 'submit',
autoFocus: true
form={form}
initialValues={values}
modalProps={{
onCancel: handleCancel,
destroyOnClose: true
}}
onOk={() => submitForm()}
onCancel={() => handleCancel()}
onFinish={submitForm}
>
<DocumentForm values={values} form={form} />
</Modal>
</ModalForm>
);
};
......
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