Skip to content

Commit

Permalink
Merge pull request #319 from actiontech/feature/issue-ee-958
Browse files Browse the repository at this point in the history
Feature/issue ee 958
  • Loading branch information
Rain-1214 authored Sep 21, 2023
2 parents 30347ba + 663ade7 commit 0355871
Show file tree
Hide file tree
Showing 25 changed files with 1,562 additions and 88 deletions.
2 changes: 1 addition & 1 deletion craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module.exports = {
const res = {};
for (let i = 0; i < 10; i++) {
res[`/v${i}`] = {
target: 'http://124.70.158.246:8889',
target: 'http://10.186.62.87:10000',
secure: false,
changeOrigin: true,
ws: true,
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@mui/styles": "^5.11.16",
"@mui/system": "^5.9.1",
"@reduxjs/toolkit": "^1.9.1",
"@uiw/react-md-editor": "^3.23.5",
"ahooks": "^3.7.5",
"antd": "^4.24.8",
"axios": "^0.27.2",
Expand All @@ -25,6 +26,7 @@
"react-monaco-editor": "^0.43.0",
"react-redux": "^8.0.5",
"react-router-dom": "^6.3.0",
"rehype-sanitize": "^6.0.0",
"sql-formatter": "^12.2.2",
"typescript": "^5.0.2",
"use-resize-observer": "^9.0.2",
Expand Down
8 changes: 8 additions & 0 deletions src/api/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,14 @@ export interface IGetRolesResV1 {
total_nums?: number;
}

export interface IGetRuleKnowledgeResV1 {
code?: number;

data?: IRuleKnowledgeResV1;

message?: string;
}

export interface IGetRuleTemplateResV1 {
code?: number;

Expand Down
8 changes: 6 additions & 2 deletions src/api/rule_template/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
IGetProjectRuleTemplateResV1,
IUpdateProjectRuleTemplateReqV1,
ICloneProjectRuleTemplateReqV1,
IRuleKnowledgeResV1,
IGetRuleKnowledgeResV1,
IUpdateRuleKnowledgeReq,
IGetRuleTemplatesResV1,
ICreateRuleTemplateReqV1,
Expand Down Expand Up @@ -129,12 +129,16 @@ export interface IExportProjectRuleTemplateV1Params {

export interface IGetRuleKnowledgeV1Params {
rule_name: string;

db_type: string;
}

export interface IGetRuleKnowledgeV1Return extends IRuleKnowledgeResV1 {}
export interface IGetRuleKnowledgeV1Return extends IGetRuleKnowledgeResV1 {}

export interface IUpdateRuleKnowledgeParams extends IUpdateRuleKnowledgeReq {
rule_name: string;

db_type: string;
}

export interface IUpdateRuleKnowledgeReturn extends IBaseRes {}
Expand Down
10 changes: 8 additions & 2 deletions src/api/rule_template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,14 @@ class RuleTemplateService extends ServiceBase {
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const db_type = paramsData.db_type;
delete paramsData.db_type;

const rule_name = paramsData.rule_name;
delete paramsData.rule_name;

return this.get<IGetRuleKnowledgeV1Return>(
`/v1/rule_knowledge/${rule_name}/`,
`/v1/rule_knowledge/db_types/${db_type}/rules/${rule_name}/`,
paramsData,
options
);
Expand All @@ -299,11 +302,14 @@ class RuleTemplateService extends ServiceBase {
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const db_type = paramsData.db_type;
delete paramsData.db_type;

const rule_name = paramsData.rule_name;
delete paramsData.rule_name;

return this.patch<IUpdateRuleKnowledgeReturn>(
`/v1/rule_knowledge/${rule_name}/`,
`/v1/rule_knowledge/db_types/${db_type}/rules/${rule_name}/`,
paramsData,
options
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ exports[`AuditResultErrorMessage should call getRuleList when rule name is not e
class="ant-col message"
style="flex: 1 1 auto; min-width: 0;"
>
<span>
schema 不存在
</span>
schema 不存在
</div>
</div>
</div>
Expand Down Expand Up @@ -197,9 +195,7 @@ exports[`AuditResultErrorMessage should call getRuleList when rule name is not e
class="ant-col message"
style="flex: 1 1 auto; min-width: 0;"
>
<span>
select 语句必须带limit,且限制数不得超过1000
</span>
select 语句必须带limit,且限制数不得超过1000
</div>
</div>
</div>
Expand Down Expand Up @@ -268,9 +264,7 @@ exports[`AuditResultErrorMessage should render normal level when not match level
class="ant-col message"
style="flex: 1 1 auto; min-width: 0;"
>
<span>
禁止使用没有where条件的sql语句或者使用where 1=1等变相没有条件的sql
</span>
禁止使用没有where条件的sql语句或者使用where 1=1等变相没有条件的sql
</div>
</div>
</div>
Expand Down
19 changes: 13 additions & 6 deletions src/components/AuditResultErrorMessage/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { fireEvent, render, screen, act } from '@testing-library/react';
import { fireEvent, screen, act, cleanup } from '@testing-library/react';
import AuditResultErrorMessage from '.';
import { IAuditResult } from '../../api/common';
import { mockGetAllRules } from '../../page/Rule/__test__/utils';
import { renderWithRouter } from '../../testUtils/customRender';

describe('AuditResultErrorMessage', () => {
const auditResult: IAuditResult[] = [
Expand Down Expand Up @@ -33,18 +34,24 @@ describe('AuditResultErrorMessage', () => {
});

test('should call getRuleList when rule name is not empty', async () => {
const { rerender, baseElement } = render(<AuditResultErrorMessage />);
const { baseElement: baseElement1 } = renderWithRouter(
<AuditResultErrorMessage />
);

await act(async () => jest.advanceTimersByTime(3000));

expect(baseElement).toMatchSnapshot();
expect(baseElement1).toMatchSnapshot();
expect(getRulesSpy).toBeCalledTimes(0);

rerender(<AuditResultErrorMessage auditResult={auditResult} />);
cleanup();

const { baseElement: baseElement2 } = renderWithRouter(
<AuditResultErrorMessage auditResult={auditResult} />
);

await act(async () => jest.advanceTimersByTime(3000));

expect(baseElement).toMatchSnapshot();
expect(baseElement2).toMatchSnapshot();
expect(getRulesSpy).toBeCalledTimes(1);
expect(getRulesSpy).nthCalledWith(1, {
filter_rule_names: 'all_check_where_is_invalid,dml_check_select_limit',
Expand All @@ -66,7 +73,7 @@ describe('AuditResultErrorMessage', () => {
});

test('should render normal level when not match level', () => {
const { container } = render(
const { container } = renderWithRouter(
<AuditResultErrorMessage
auditResult={[
{
Expand Down
38 changes: 31 additions & 7 deletions src/components/AuditResultErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { AuditResultErrorMessageProps } from './index.type';
import EmptyBox from '../EmptyBox';
import { useRequest } from 'ahooks';
import rule_template from '../../api/rule_template';
import { Link } from '../Link';
import { useTranslation } from 'react-i18next';

import './index.less';

const AuditResultErrorMessage: React.FC<AuditResultErrorMessageProps> = (
props
) => {
const { t } = useTranslation();
const filterRuleNames = useMemo(
() =>
(props.auditResult?.map((v) => v.rule_name ?? '') ?? []).filter(
Expand All @@ -37,20 +40,41 @@ const AuditResultErrorMessage: React.FC<AuditResultErrorMessageProps> = (
className="audit-result-error-message-wrapper"
>
{props.auditResult?.map((v) => {
const rule = ruleInfo?.find((rule) => rule.rule_name === v.rule_name);
return (
<Row wrap={false} key={v.message}>
<Col flex="50px">
<RuleLevelIcon ruleLevel={v.level} />
</Col>
<Col flex={1} className="message">
<Tooltip
title={
ruleInfo?.find((rule) => rule.rule_name === v.rule_name)
?.annotation ?? ''
}
<EmptyBox
if={!!rule && !!rule.annotation}
defaultNode={v.message}
>
{v.message}
</Tooltip>
<Tooltip
title={
<>
<span>{rule?.annotation}</span>

{/* IFTRUE_isEE */}
{' '}
{/* 暂时不支持自定义规则 */}
<EmptyBox if={!rule?.is_custom_rule && !!rule?.db_type}>
<Link
target="_blank"
to={`rule/knowledge/${v.rule_name}?db_type=${rule?.db_type}`}
>
{t('common.showMore')}
</Link>
</EmptyBox>

{/* FITRUE_isEE */}
</>
}
>
{v.message}
</Tooltip>
</EmptyBox>
</Col>
</Row>
);
Expand Down
22 changes: 21 additions & 1 deletion src/components/RuleList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useTranslation } from 'react-i18next';
import { RuleListDefaultTabKey } from '../../data/common';
import { RuleListProps, TabRuleItem } from './index.type';
import RuleLevelIcon from './RuleLevelIcon';
import { Link } from '../Link';
import EmptyBox from '../EmptyBox';

const RuleList: React.FC<RuleListProps> = (props) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -80,7 +82,25 @@ const RuleList: React.FC<RuleListProps> = (props) => {
avatar={<RuleLevelIcon ruleLevel={item.level} />}
title={item.desc}
description={
<Tooltip title={item.annotation}>
<Tooltip
title={
<>
{item.annotation}
{/* IFTRUE_isEE */}
{' '}
{/* 暂时不支持自定义规则 */}
<EmptyBox if={!item?.is_custom_rule && !!item?.db_type}>
<Link
target="_blank"
to={`rule/knowledge/${item.rule_name}?db_type=${item?.db_type}`}
>
{t('common.showMore')}
</Link>
</EmptyBox>
{/* FITRUE_isEE */}
</>
}
>
<Typography.Text
ellipsis={true}
type="secondary"
Expand Down
2 changes: 2 additions & 0 deletions src/locale/zh-CN/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import customRule from './customRule';
import ruleManager from './ruleManager';
import sqlManagement from './sqlManagement';
import sqlAudit from './sqlAudit';
import ruleKnowledge from './ruleKnowledge';

// eslint-disable-next-line import/no-anonymous-default-export
export default {
Expand Down Expand Up @@ -58,5 +59,6 @@ export default {
ruleManager,
sqlManagement,
sqlAudit,
ruleKnowledge,
},
};
11 changes: 11 additions & 0 deletions src/locale/zh-CN/ruleKnowledge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable import/no-anonymous-default-export */
export default {
pageTitle: '知识库',
pageDesc: '您可以在这里了解规则的更多信息, 并进行沉淀',

ruleUnderstanding: '规则理解',
edit: '编辑',
noData: '暂无数据, 请编辑',
hasDirtyDataTips: '当前内容已经发生更改,是否确认取消修改?',
successTips: '规则理解修改成功',
};
Loading

0 comments on commit 0355871

Please sign in to comment.