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

[fix]: change file valid locale #345

Merged
merged 1 commit into from
Nov 29, 2023
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
1 change: 1 addition & 0 deletions src/locale/en-US/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default {
placeholder: {
input: 'Please input {{name}}',
select: 'Please select {{name}}',
upload: 'Please upload {{name}}',
searchInput: 'Input the {{name}} to search',
searchSelect: 'Select the {{name}} to search',
},
Expand Down
1 change: 0 additions & 1 deletion src/locale/en-US/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export default {
instanceSchema: '数据库',
sql: 'SQL语句',
sqlFile: 'SQL文件',
validateSqlFileMsg: '请上传SQL文件',
mybatisFile: 'Mybatis的XML文件',
zipFile: 'ZIP文件',

Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-CN/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default {
placeholder: {
input: '请输入{{name}}',
select: '请选择{{name}}',
upload: '请上传{{name}}',
searchInput: '请输入要搜索的 {{name}}',
searchSelect: '请选择要搜索的 {{name}}',
},
Expand Down
1 change: 0 additions & 1 deletion src/locale/zh-CN/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export default {
instanceSchema: '数据库',
sql: 'SQL语句',
sqlFile: 'SQL文件',
validateSqlFileMsg: '请上传SQL文件',
mybatisFile: 'Mybatis的XML文件',
zipFile: 'ZIP文件',

Expand Down
21 changes: 13 additions & 8 deletions src/page/Order/SqlStatementFormTabs/SqlStatementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({

const resetUploadTypeContent = () => {
setCurrentSQLInputTYpe(SQLInputType.manualInput);
}
};

const { editorDidMount } = useMonacoEditor(form, {
formName: generateFieldName('sql'),
Expand Down Expand Up @@ -88,8 +88,7 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

}, []);

return (
<>
Expand Down Expand Up @@ -126,9 +125,9 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
}}
rules={[
{
required: true
required: true,
},
...whiteSpaceSql()
...whiteSpaceSql(),
]}
>
<MonacoEditorFunComponent
Expand All @@ -151,7 +150,9 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
rules={[
{
required: true,
message: t('order.sqlInfo.validateSqlFileMsg')
message: t('common.form.placeholder.upload', {
name: t('order.sqlInfo.sqlFile'),
}),
},
]}
getValueFromEvent={getFileFromUploadChangeEvent}
Expand All @@ -173,7 +174,9 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
rules={[
{
required: true,
message: t('order.sqlInfo.validateSqlFileMsg')
message: t('common.form.placeholder.upload', {
name: t('order.sqlInfo.mybatisFile'),
}),
},
]}
getValueFromEvent={getFileFromUploadChangeEvent}
Expand All @@ -196,7 +199,9 @@ const SqlStatementForm: React.FC<SqlStatementFormProps> = ({
rules={[
{
required: true,
message: t('order.sqlInfo.validateSqlFileMsg')
message: t('common.form.placeholder.upload', {
name: t('order.sqlInfo.zipFile'),
}),
},
]}
getValueFromEvent={getFileFromUploadChangeEvent}
Expand Down
43 changes: 36 additions & 7 deletions src/page/SqlAuditRecord/Create/SQLInfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
Tooltip,
Upload,
} from 'antd';
import { PageFormLayout, ResponseCode, SqlFiledInitialValue } from '../../../data/common';
import {
PageFormLayout,
ResponseCode,
SqlFiledInitialValue,
} from '../../../data/common';
import {
AuditTypeEnum,
SQLInfoFormFields,
Expand Down Expand Up @@ -49,7 +53,7 @@
import { Link } from 'react-router-dom';
import { getInstanceTipListV1FunctionalModuleEnum } from '../../../api/instance/index.enum';
import EmptyBox from '../../../components/EmptyBox';
import { whiteSpaceSql } from '../../../utils/FormRule';
import { whiteSpaceSql, nameRule } from '../../../utils/FormRule';

const MonacoEditorFunComponent =
MonacoEditor as ComponentType<MonacoEditorProps>;
Expand All @@ -57,120 +61,145 @@
const SQLInfoForm: React.ForwardRefRenderFunction<
SQLInfoFormRef,
SQLInfoFormProps
> = ({ form, submit, projectName }, ref) => {
const { t } = useTranslation();
const theme = useStyles();
const { currentEditorTheme } = useChangeTheme();
const { generateInstanceSelectOption, updateInstanceList, instanceList } =
useInstance();
const { updateDriverNameList, generateDriverSelectOptions } =
useDatabaseType();

const { editorDidMount } = useMonacoEditor(form, {
formName: 'sql',
});

const uploadType = Form.useWatch('uploadType', form);
const auditType = Form.useWatch('auditType', form);
const instanceName = Form.useWatch('instanceName', form);

const { updateSchemaList, generateInstanceSchemaSelectOption } =
useInstanceSchema(projectName, instanceName);

const removeFile = (
fileName: keyof Pick<
SQLInfoFormFields,
'sqlFile' | 'mybatisFile' | 'zipFile'
>
) => {
form.setFieldsValue({
[fileName]: [],
});
};

const genUploadItem = (type: UploadTypeEnum): FormItemProps => {
const uploadCommonProps: FormItemProps = {
valuePropName: 'fileList',
getValueFromEvent: getFileFromUploadChangeEvent,
rules: [
{
required: true,
message: t('order.sqlInfo.validateSqlFileMsg')
},
],
};
if (type === UploadTypeEnum.sql) {
return {
name: 'sql',
label: t('sqlAudit.create.SQLInfo.uploadLabelEnum.sql'),
initialValue: SqlFiledInitialValue,
wrapperCol: {
...PageFormLayout.wrapperCol,
className: theme.editor,
},
rules: [{ required: uploadType === UploadTypeEnum.sql }, ...whiteSpaceSql()],
rules: [
{
required: uploadType === UploadTypeEnum.sql,
},
...whiteSpaceSql(),
],

children: (
<MonacoEditorFunComponent
theme={currentEditorTheme}
width="100%"
height="500"
language="sql"
editorDidMount={editorDidMount}
options={{
automaticLayout: true,
}}
/>
),
};

Check warning on line 133 in src/page/SqlAuditRecord/Create/SQLInfoForm.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else if (type === UploadTypeEnum.sqlFile) {
return {
name: 'sqlFile',
label: t('sqlAudit.create.SQLInfo.uploadLabelEnum.sqlFile'),
rules: [{ required: uploadType === UploadTypeEnum.sqlFile }],
rules: [
{
required: uploadType === UploadTypeEnum.sqlFile,
message: t('common.form.placeholder.upload', {
name: t('sqlAudit.create.SQLInfo.uploadLabelEnum.sqlFile'),
}),
},
],
children: (
<Upload
accept=".sql"
beforeUpload={() => false}
onRemove={removeFile.bind(null, 'sqlFile')}
>
<Button>{t('common.upload')}</Button>
</Upload>
),
...uploadCommonProps,
};

Check warning on line 156 in src/page/SqlAuditRecord/Create/SQLInfoForm.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else if (type === UploadTypeEnum.xmlFile) {
return {
name: 'mybatisFile',
label: t('sqlAudit.create.SQLInfo.uploadLabelEnum.xmlFile'),
rules: [{ required: uploadType === UploadTypeEnum.xmlFile }],
rules: [
{
required: uploadType === UploadTypeEnum.xmlFile,
message: t('common.form.placeholder.upload', {
name: t('sqlAudit.create.SQLInfo.uploadLabelEnum.xmlFile'),
}),
},
],
children: (
<Upload
accept=".xml"
beforeUpload={() => false}
onRemove={removeFile.bind(null, 'mybatisFile')}
>
<Button>{t('common.upload')}</Button>
</Upload>
),
...uploadCommonProps,
};

Check warning on line 179 in src/page/SqlAuditRecord/Create/SQLInfoForm.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else if (type === UploadTypeEnum.zipFile) {
return {
name: 'zipFile',
label: t('sqlAudit.create.SQLInfo.uploadLabelEnum.zipFile'),
rules: [{ required: uploadType === UploadTypeEnum.zipFile }],
rules: [
{
required: uploadType === UploadTypeEnum.zipFile,
message: t('common.form.placeholder.upload', {
name: t('sqlAudit.create.SQLInfo.uploadLabelEnum.zipFile'),
}),
},
],
children: (
<Upload
accept=".zip"
beforeUpload={() => false}
onRemove={removeFile.bind(null, 'zipFile')}
>
<Button>{t('common.upload')}</Button>
</Upload>
),
...uploadCommonProps,
};

Check warning on line 202 in src/page/SqlAuditRecord/Create/SQLInfoForm.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} else if (type === UploadTypeEnum.git) {
return {
name: 'gitHttpUrl',
Expand Down