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]: update sql audit create result show methods #335

Merged
merged 1 commit into from
Nov 16, 2023
Merged
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
13 changes: 8 additions & 5 deletions src/page/SqlAuditRecord/Create/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,87 +16,90 @@
import AuditResult from '../../Order/AuditResult';
import sql_audit_record from '../../../api/sql_audit_record';
import { ICreateSQLAuditRecordV1Params } from '../../../api/sql_audit_record/index.d';
import { useRef, useState } from 'react';
import { useRef, useState, useEffect } from "react";
import { IAuditTaskResV1, ISQLAuditRecordResData } from '../../../api/common';
import { ResponseCode } from '../../../data/common';
import EmptyBox from '../../../components/EmptyBox';
import FooterButtonWrapper from '../../../components/FooterButtonWrapper';
import { Link } from '../../../components/Link';

const SQLAuditCreate: React.FC = () => {
const { t } = useTranslation();
const theme = useTheme<Theme>();
const [baseForm] = useForm<BaseInfoFormFields>();
const [sqlInfoForm] = useForm<SQLInfoFormFields>();
const { projectName } = useCurrentProjectName();
const [task, setTask] = useState<IAuditTaskResV1>();
const baseRef = useRef<BaseInfoFormRef>(null);
const sqlInfoRef = useRef<SQLInfoFormRef>(null);

const scrollToAuditResult = () => {
const auditResultCardElement = document.getElementById(
'audit-result-task-card'
);
auditResultCardElement?.scrollIntoView({
behavior: 'smooth',
block: 'end',
});
};

const auditSQL: SQLInfoFormProps['submit'] = async (values) => {
const baseValues = await baseForm.validateFields();
const params: ICreateSQLAuditRecordV1Params = {
project_name: projectName,
sqls: values.sql,
input_sql_file: values.sqlFile?.[0],
input_mybatis_xml_file: values.mybatisFile?.[0],
input_zip_file: values.zipFile?.[0],
instance_name: values.instanceName,
instance_schema: values.instanceSchema,
db_type: values.dbType,
git_http_url: values.gitHttpUrl,
git_user_name: values.gitUserName,
git_user_password: values.gitUserPassword,
};

return sql_audit_record.CreateSQLAuditRecordV1(params).then((res) => {
if (res.data.code === ResponseCode.SUCCESS && res.data.data) {
if ((baseValues.tags?.length ?? 0) > 0) {
return updateTags(res.data.data, baseValues);
} else {
setTask(res.data.data.task);
message.success(t('sqlAudit.create.SQLInfo.successTips'));
scrollToAuditResult();
}
}
});
};

const updateTags = async (
record: ISQLAuditRecordResData,
values: BaseInfoFormFields
) => {
return sql_audit_record
.updateSQLAuditRecordV1({
tags: values.tags,
sql_audit_record_id: record.sql_audit_record_id ?? '',
project_name: projectName,
})
.then((res) => {
if (res.data.code === ResponseCode.SUCCESS) {
setTask(record.task);
message.success(t('sqlAudit.create.SQLInfo.successTips'));
scrollToAuditResult();
}
});
};

const resetForm = () => {
baseRef.current?.reset();
sqlInfoRef.current?.reset();
setTask(undefined);
};

useEffect(() => {

Check warning on line 96 in src/page/SqlAuditRecord/Create/index.tsx

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
if (typeof task?.task_id === 'number') {
message.success(t("sqlAudit.create.SQLInfo.successTips"));

Check warning on line 98 in src/page/SqlAuditRecord/Create/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
scrollToAuditResult();

Check warning on line 99 in src/page/SqlAuditRecord/Create/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 100 in src/page/SqlAuditRecord/Create/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 100 in src/page/SqlAuditRecord/Create/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
}, [task, t]);

Check warning on line 101 in src/page/SqlAuditRecord/Create/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

return (
<>
<PageHeader title={t('sqlAudit.create.title')} ghost={false}>
Expand Down