Skip to content

Commit

Permalink
fix: fix issue-1945
Browse files Browse the repository at this point in the history
  • Loading branch information
siriuswh0327 committed Oct 26, 2023
1 parent 3ca3423 commit f2f52b6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/base/src/locale/en-US/dmsDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default {
queryTimeoutSecond: 'SQL超时限制(s)',
maintenanceTime: '运维时间',
maintenanceTimeTips: '设置运维时间后,仅能在此运维时间段内上线工单',
needAuditSqlService: '是否开启SQL审核业务',
closeAuditSqlServiceTips:
'如果不启用SQL审核业务,则在SQL审核相关业务中无法使用该数据源,是否确认关闭?',
needAuditForSqlQuery: 'SQL查询是否需要审核',
allowQueryWhenLessThanAuditLevel: '运行查询的最高审核等级',
passwordTips:
Expand Down
3 changes: 3 additions & 0 deletions packages/base/src/locale/zh-CN/dmsDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export default {
queryTimeoutSecond: 'SQL超时限制(s)',
maintenanceTime: '运维时间',
maintenanceTimeTips: '设置运维时间后,仅能在此运维时间段内上线工单',
needAuditSqlService: '是否开启SQL审核业务',
closeAuditSqlServiceTips:
'如果不启用SQL审核业务,则在SQL审核相关业务中无法使用该数据源,是否确认关闭?',
needAuditForSqlQuery: 'SQL查询是否需要审核',
allowQueryWhenLessThanAuditLevel: '运行查询的最高审核等级',
passwordTips:
Expand Down
53 changes: 52 additions & 1 deletion packages/base/src/page/DataSource/DataSourceForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { FormInstance } from 'antd5';
import { FormInstance, Popconfirm } from 'antd5';
import Select, { BaseOptionType } from 'antd5/es/select';
import { DataSourceFormField, IDataSourceFormProps } from './index.type';
import { useRequest } from 'ahooks';
Expand Down Expand Up @@ -45,6 +45,11 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
return props.defaultData.source !== SQLE_INSTANCE_SOURCE_NAME;
}, [props.defaultData]);

const [auditRequired, setAuditRequired] = useState<boolean>(
!props?.isUpdate || !!props.defaultData?.sqle_config?.rule_template_id
);
const [auditRequiredPopupVisible, setAuditRequiredPopupVisible] =
useState<boolean>(false);
const [auditEnabled, setAuditEnabled] = useState<boolean>(false);
const [databaseType, setDatabaseType] = useState<string>('');
const { projectName } = useCurrentProject();
Expand Down Expand Up @@ -105,6 +110,7 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
user: props.defaultData.user,
ruleTemplateId: props.defaultData.sqle_config?.rule_template_id,
ruleTemplateName: props.defaultData.sqle_config?.rule_template_name,
needSqlAuditService: !!props.defaultData.sqle_config?.rule_template_id,
params: generateFormValueByParams(
turnDataSourceAsyncFormToCommon(
props.defaultData.additional_params ?? []
Expand All @@ -124,10 +130,14 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
password: props.defaultData.password
});
setDatabaseType(props.defaultData.db_type ?? '');
setAuditRequired(!!props.defaultData.sqle_config?.rule_template_id);
setAuditEnabled(
!!props.defaultData.sqle_config?.sql_query_config?.audit_enabled
);
} else {
props.form.setFieldsValue({
needSqlAuditService: auditRequired
});
if (params.length > 0) {
props.form.setFieldsValue({
params: generateFormValueByParams(params)
Expand All @@ -144,6 +154,15 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
setDatabaseType('');
}, [props.form]);

const changeAuditRequired = (check: boolean) => {
if (check) setAuditRequired(check);
};

const onAuditRequiredPopupOpenChange = (open: boolean) => {
if (!auditRequired) return;
setAuditRequiredPopupVisible(open);
};

const changeAuditEnabled = (check: boolean) => {
setAuditEnabled(check);
if (!check) {
Expand All @@ -161,6 +180,15 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
}
};

const clearRuleTemplate = () => {
props.form.setFieldsValue({
needSqlAuditService: false,
ruleTemplateId: undefined,
ruleTemplateName: undefined
});
setAuditRequired(false);
};

const changeRuleTemplate = (value: string, option: BaseOptionType) => {
props.form.setFieldsValue({
ruleTemplateId: option.key
Expand All @@ -169,6 +197,7 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {

const submit = useCallback(async () => {
const values = await props.form.validateFields();
delete values.needSqlAuditService;
if (values.params) {
values.asyncParams = dmsMergeFromValueIntoParams(values.params, params);
delete values.params;
Expand Down Expand Up @@ -295,12 +324,34 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
<FormItemSubTitle>
{t('dmsDataSource.dataSourceForm.sqlConfig')}
</FormItemSubTitle>

<FormItemLabel
label={t('dmsDataSource.dataSourceForm.needAuditSqlService')}
name="needSqlAuditService"
valuePropName="checked"
>
<Popconfirm
title={t('dmsDataSource.dataSourceForm.closeAuditSqlServiceTips')}
overlayClassName="popconfirm-small"
open={auditRequiredPopupVisible}
onOpenChange={onAuditRequiredPopupOpenChange}
onConfirm={clearRuleTemplate}
>
<BasicSwitch
checked={auditRequired}
onChange={changeAuditRequired}
/>
</Popconfirm>
</FormItemLabel>
<FormItemLabel name="ruleTemplateId" hidden={true}>
<BasicInput />
</FormItemLabel>
<FormItemLabel
hidden={!auditRequired}
label={t('dmsDataSource.dataSourceForm.ruleTemplate')}
name="ruleTemplateName"
className="has-required-style"
rules={[{ required: auditRequired }]}
>
<BasicSelect
showSearch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type DataSourceFormField = {
password: string;
business: string;
maintenanceTime: MaintenanceTimeValue[];
needSqlAuditService?: boolean;
ruleTemplateId?: string;
ruleTemplateName?: string;
allowQueryWhenLessThanAuditLevel?: SQLQueryConfigAllowQueryWhenLessThanAuditLevelEnum;
Expand Down

0 comments on commit f2f52b6

Please sign in to comment.