Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ yarn-error.log*
/packages/icons/.dumi/tmp*
docs-dist
docs-dist.tar.gz
es
es

## local config
.cursor/
30 changes: 28 additions & 2 deletions packages/shared/lib/api/sqle/service/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
exportSqlManageV1FilterStatusEnum,
exportSqlManageV1SortFieldEnum,
exportSqlManageV1SortOrderEnum,
exportSqlManageRemediationV1ExportScopeEnum,
GetSqlManageListV2FilterSourceEnum,
GetSqlManageListV2FilterAuditLevelEnum,
GetSqlManageListV2FilterStatusEnum,
Expand All @@ -20,10 +21,12 @@ import {

import {
IGetSqlManageListResp,
IGetSqlManageListV1Resp,
IBatchUpdateSqlManageReq,
IBaseRes,
IGetSqlManageRuleTipsResp,
IGetSqlManageSqlAnalysisResp
IGetSqlManageSqlAnalysisResp,
IGetSqlManageRemediationResp
} from '../common.d';

export interface IGetSqlManageListParams {
Expand Down Expand Up @@ -62,7 +65,7 @@ export interface IGetSqlManageListParams {
page_size: number;
}

export interface IGetSqlManageListReturn extends IGetSqlManageListResp {}
export interface IGetSqlManageListReturn extends IGetSqlManageListV1Resp {}

export interface IBatchUpdateSqlManageParams extends IBatchUpdateSqlManageReq {
project_name: string;
Expand Down Expand Up @@ -106,6 +109,20 @@ export interface IExportSqlManageV1Params {
sort_order?: exportSqlManageV1SortOrderEnum;
}

export interface IExportGlobalSqlManageRemediationV1Params {}

export interface IExportSqlManageRemediationV1Params {
project_name: string;

export_scope: exportSqlManageRemediationV1ExportScopeEnum;

filter_instance_id?: string;

instance_audit_plan_id?: string;

audit_plan_type?: string;
}

export interface IGetSqlManageRuleTipsParams {
project_name: string;
}
Expand Down Expand Up @@ -163,3 +180,12 @@ export interface IGetSqlManageListV2Params {
}

export interface IGetSqlManageListV2Return extends IGetSqlManageListResp {}

export interface IGetSqlManageRemediationV1Params {
project_name: string;

sql_manage_id: string;
}

export interface IGetSqlManageRemediationV1Return
extends IGetSqlManageRemediationResp {}
8 changes: 8 additions & 0 deletions packages/shared/lib/api/sqle/service/SqlManage/index.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export enum exportSqlManageV1SortOrderEnum {
'desc' = 'desc'
}

export enum exportSqlManageRemediationV1ExportScopeEnum {
'project' = 'project',

'data_source' = 'data_source',

'scan_task' = 'scan_task'
}

export enum GetSqlManageListV2FilterSourceEnum {
'audit_plan' = 'audit_plan',

Expand Down
54 changes: 52 additions & 2 deletions packages/shared/lib/api/sqle/service/SqlManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import {
IBatchUpdateSqlManageParams,
IBatchUpdateSqlManageReturn,
IExportSqlManageV1Params,
IExportGlobalSqlManageRemediationV1Params,
IExportSqlManageRemediationV1Params,
IGetSqlManageRuleTipsParams,
IGetSqlManageRuleTipsReturn,
IGetSqlManageSqlAnalysisV1Params,
IGetSqlManageSqlAnalysisV1Return,
IGetSqlManageListV2Params,
IGetSqlManageListV2Return
IGetSqlManageListV2Return,
IGetSqlManageRemediationV1Params,
IGetSqlManageRemediationV1Return
} from './index.d';

class SqlManageService extends ServiceBase {
Expand Down Expand Up @@ -59,13 +63,41 @@ class SqlManageService extends ServiceBase {
const project_name = paramsData.project_name;
delete paramsData.project_name;

return this.get<any>(
return this.get<Blob>(
`/v1/projects/${project_name}/sql_manages/exports`,
paramsData,
options
);
}

public exportGlobalSqlManageRemediationV1(
params: IExportGlobalSqlManageRemediationV1Params = {},
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);

return this.get<Blob>(
`/v1/sql_manages/remediation_exports`,
paramsData,
options
);
}

public exportSqlManageRemediationV1(
params: IExportSqlManageRemediationV1Params,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const project_name = paramsData.project_name;
delete paramsData.project_name;

return this.get<Blob>(
`/v1/projects/${project_name}/sql_manages/remediation_exports`,
paramsData,
options
);
}

public GetSqlManageRuleTips(
params: IGetSqlManageRuleTipsParams,
options?: AxiosRequestConfig
Expand Down Expand Up @@ -113,6 +145,24 @@ class SqlManageService extends ServiceBase {
options
);
}

public GetSqlManageRemediationV1(
params: IGetSqlManageRemediationV1Params,
options?: AxiosRequestConfig
) {
const paramsData = this.cloneDeep(params);
const project_name = paramsData.project_name;
delete paramsData.project_name;

const sql_manage_id = paramsData.sql_manage_id;
delete paramsData.sql_manage_id;

return this.get<IGetSqlManageRemediationV1Return>(
`/v1/projects/${project_name}/sql_manages/${sql_manage_id}/remediation`,
paramsData,
options
);
}
}

export default new SqlManageService();
97 changes: 97 additions & 0 deletions packages/shared/lib/api/sqle/service/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2360,6 +2360,52 @@ export interface ISqlManage {

remark?: string;

// TODO: 后端已移除/变更,待 codegen 重新生成
first_audit_missing?: boolean;

first_audit_result?: IAuditResult[];

first_audit_time?: string;

rule_diff?: IRuleDiff;

schema_name?: string;

source?: ISource;

sql?: string;

sql_fingerprint?: string;

status?: SqlManageStatusEnum;
}

// TODO: 后端 v1.SqlManage 与 v2.SqlManage 字段不同,单独建模 v1(v1 接口已 deprecated)
export interface ISqlManageV1 {
appear_num?: number;

assignees?: string[];

audit_result?: IAuditResult[];

endpoint?: string;

first_appear_time?: string;

first_audit_result?: IAuditResult[];

first_audit_time?: string;

id?: number;

instance_name?: string;

last_appear_time?: string;

remark?: string;

rule_diff?: IRuleDiff;

schema_name?: string;

source?: ISource;
Expand All @@ -2371,6 +2417,20 @@ export interface ISqlManage {
status?: SqlManageStatusEnum;
}

export interface IGetSqlManageListV1Resp {
code?: number;

data?: ISqlManageV1[];

message?: string;

sql_manage_bad_num?: number;

sql_manage_optimized_num?: number;

sql_manage_total_num?: number;
}

export interface IStatisticAuditPlanResV1 {
code?: number;

Expand Down Expand Up @@ -3458,3 +3518,40 @@ export interface IWorkflowStepResV2 {

workflow_step_id?: number;
}

export interface IRuleDiff {
new?: IAuditResult[];

resolved?: IAuditResult[];

unchanged?: IAuditResult[];
}

export interface ISqlManageRemediation {
// TODO: 后端已移除/变更,待 codegen 重新生成
first_audit_missing?: boolean;

first_audit_result?: IAuditResult[];

first_audit_time?: string;

id?: number;

latest_audit_result?: IAuditResult[];

latest_audit_time?: string;

rule_diff?: IRuleDiff;

sql?: string;

sql_fingerprint?: string;
}

export interface IGetSqlManageRemediationResp {
code?: number;

data?: ISqlManageRemediation;

message?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { useMemo, type FC } from 'react';
import { Space } from 'antd';
import {
WarningFilled,
InfoHexagonFilled,
CloseCircleFilled
} from '@actiontech/icons';
import { IAuditResult } from '@actiontech/shared/lib/api/sqle/service/common';
import AuditResultMessage from './index';
import {
AUDIT_LEVEL_DISPLAY_ORDER,
AuditLevelSummaryKey,
countAuditResultsByLevel,
hasAuditViolations
} from './auditLevelUtils';
import { AuditLevelSummaryStyleWrapper } from './style';

const LEVEL_ICON_MAP: Record<
AuditLevelSummaryKey,
FC<{ width?: number; height?: number }>
> = {
error: CloseCircleFilled,
warn: WarningFilled,
notice: InfoHexagonFilled
};

export type AuditLevelSummaryProps = {
auditResults?: IAuditResult[];
};

const AuditLevelSummary = ({ auditResults }: AuditLevelSummaryProps) => {
const levelCounts = useMemo(
() => countAuditResultsByLevel(auditResults),
[auditResults]
);

if (!hasAuditViolations(auditResults)) {
return <AuditResultMessage auditResult={{}} />;
}

return (
<AuditLevelSummaryStyleWrapper>
<Space size={12}>
{AUDIT_LEVEL_DISPLAY_ORDER.map((level) => {
const count = levelCounts[level];
if (!count) {
return null;
}

const Icon = LEVEL_ICON_MAP[level];

return (
<span key={level} className="audit-level-summary-item">
<Icon width={20} height={20} />
<span className="audit-level-summary-count">× {count}</span>
</span>
);
})}
</Space>
</AuditLevelSummaryStyleWrapper>
);
};

export default AuditLevelSummary;
Loading
Loading