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](DataSourceForm): supply tips when user attempt to swtich off auditRequired #32

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions 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, Popconfirm } from 'antd5';
import { Form, 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,8 +45,9 @@ 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 auditRequired = Form.useWatch(
'needSqlAuditService',
props.form as FormInstance<DataSourceFormField>
siriuswh0327 marked this conversation as resolved.
Show resolved Hide resolved
);
const [auditRequiredPopupVisible, setAuditRequiredPopupVisible] =
useState<boolean>(false);
Expand Down Expand Up @@ -130,13 +131,12 @@ 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
needSqlAuditService: true
});
if (params.length > 0) {
props.form.setFieldsValue({
Expand All @@ -155,7 +155,10 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
}, [props.form]);

const changeAuditRequired = (check: boolean) => {
if (check) setAuditRequired(check);
if (check)
props.form.setFieldsValue({
needSqlAuditService: check
});
};

const onAuditRequiredPopupOpenChange = (open: boolean) => {
Expand Down Expand Up @@ -186,7 +189,6 @@ const DataSourceForm: React.FC<IDataSourceFormProps> = (props) => {
ruleTemplateId: undefined,
ruleTemplateName: undefined
});
setAuditRequired(false);
};

const changeRuleTemplate = (value: string, option: BaseOptionType) => {
Expand Down
Loading