Skip to content

Commit

Permalink
[feature]:(SQLManagement) Support sql analyze
Browse files Browse the repository at this point in the history
  • Loading branch information
LZS911 committed Dec 21, 2023
1 parent f1d9d74 commit 6743950
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 40 deletions.
12 changes: 11 additions & 1 deletion src/api/SqlManage/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
IGetSqlManageListResp,
IBatchUpdateSqlManageReq,
IBaseRes,
IGetSqlManageRuleTipsResp
IGetSqlManageRuleTipsResp,
IGetSqlManageSqlAnalysisResp
} from '../common.d';

export interface IGetSqlManageListParams {
Expand Down Expand Up @@ -106,6 +107,15 @@ export interface IGetSqlManageRuleTipsParams {
export interface IGetSqlManageRuleTipsReturn
extends IGetSqlManageRuleTipsResp {}

export interface IGetSqlManageSqlAnalysisV1Params {
project_name: string;

sql_manage_id: string;
}

export interface IGetSqlManageSqlAnalysisV1Return
extends IGetSqlManageSqlAnalysisResp {}

export interface IGetSqlManageListV2Params {
project_name: string;

Expand Down
20 changes: 20 additions & 0 deletions src/api/SqlManage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
IExportSqlManageV1Params,
IGetSqlManageRuleTipsParams,
IGetSqlManageRuleTipsReturn,
IGetSqlManageSqlAnalysisV1Params,
IGetSqlManageSqlAnalysisV1Return,
IGetSqlManageListV2Params,
IGetSqlManageListV2Return
} from './index.d';
Expand Down Expand Up @@ -79,6 +81,24 @@ class SqlManageService extends ServiceBase {
);
}

public GetSqlManageSqlAnalysisV1(
params: IGetSqlManageSqlAnalysisV1Params,
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<IGetSqlManageSqlAnalysisV1Return>(
`/v1/projects/${project_name}/sql_manages/${sql_manage_id}/sql_analysis`,
paramsData,
options
);
}

public GetSqlManageListV2(
params: IGetSqlManageListV2Params,
options?: AxiosRequestConfig
Expand Down
48 changes: 32 additions & 16 deletions src/api/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export interface IBaseRes {
message?: string;
}

export interface IAffectRows {
count?: number;

err_message?: string;
}

export interface IAuditPlanCount {
audit_plan_count?: number;

Expand Down Expand Up @@ -1385,6 +1391,14 @@ export interface IGetSqlManageRuleTipsResp {
message?: string;
}

export interface IGetSqlManageSqlAnalysisResp {
code?: number;

data?: ISqlAnalysis;

message?: string;
}

export interface IGetSyncInstanceTaskListResV1 {
code?: number;

Expand Down Expand Up @@ -1997,6 +2011,10 @@ export interface IPatchUserGroupReqV1 {
user_name_list?: string[];
}

export interface IPerformanceStatistics {
affect_rows?: IAffectRows;
}

export interface IPersonaliseReqV1 {
title?: string;
}
Expand Down Expand Up @@ -2289,6 +2307,14 @@ export interface ISource {
type?: SourceTypeEnum;
}

export interface ISqlAnalysis {
performance_statistics?: IPerformanceStatistics;

sql_explain?: ISQLExplain;

table_metas?: ITableMetas;
}

export interface ISqlAnalysisResDataV1 {
sql_explain?: ISQLExplain;

Expand Down Expand Up @@ -2427,6 +2453,12 @@ export interface ITableMetaItemHeadResV1 {
field_name?: string;
}

export interface ITableMetas {
err_message?: string;

table_meta_items?: ITableMeta[];
}

export interface ITestAuditPlanNotifyConfigResDataV1 {
is_notify_send_normal?: boolean;

Expand Down Expand Up @@ -3093,12 +3125,6 @@ export interface IWorkflowTemplateDetailResV1 {
workflow_template_name?: string;
}

export interface IAffectRows {
count?: number;

err_message?: string;
}

export interface IAuditPlanReportSQLResV2 {
audit_plan_report_sql?: string;

Expand Down Expand Up @@ -3421,10 +3447,6 @@ export interface IPartialSyncAuditPlanSQLsReqV2 {
audit_plan_sql_list?: IAuditPlanSQLReqV2[];
}

export interface IPerformanceStatistics {
affect_rows?: IAffectRows;
}

export interface IRejectWorkflowReqV2 {
reason?: string;
}
Expand All @@ -3435,12 +3457,6 @@ export interface IRuleTemplateV2 {
name?: string;
}

export interface ITableMetas {
err_message?: string;

table_meta_items?: ITableMeta[];
}

export interface ITaskAnalysisDataV2 {
performance_statistics?: IPerformanceStatistics;

Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-CN/sqlManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default {
status: '状态',
comment: '备注',
endpoint: '端点信息',
analyze: '分析',

actions: {
batchAssignment: '批量指派',
Expand Down
58 changes: 36 additions & 22 deletions src/page/SQLManagement/SQLPanel/column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const SQLPanelColumns: (params: {
id: number,
status: BatchUpdateSqlManageReqStatusEnum
) => Promise<void> | undefined;
handleClickAnalyze: (sqlManageId: string) => void;
}) => Array<
| (ColumnGroupType<ISqlManage> | ColumnType<ISqlManage>) & {
dataIndex?: keyof ISqlManage | 'operator';
Expand All @@ -61,6 +62,7 @@ export const SQLPanelColumns: (params: {
actionPermission,
username,
updateSQLStatus,
handleClickAnalyze,
}) => {
const columns: Array<
| (ColumnGroupType<ISqlManage> | ColumnType<ISqlManage>) & {
Expand Down Expand Up @@ -250,41 +252,53 @@ export const SQLPanelColumns: (params: {
);
},
},

{
dataIndex: 'operator',
title: () => t('common.operate'),
fixed: 'right',
render: (_, record) => {
return (
<Space>
<AssignMember
projectName={projectName}
disabled={signalActionsLoading}
onConfirm={(members: string[]) =>
signalAssignment(record.id ?? 0, members)
}
>
<Typography.Link>
{t('sqlManagement.table.assignMember.label')}
</Typography.Link>
</AssignMember>
<EmptyBox if={actionPermission}>
<AssignMember
projectName={projectName}
disabled={signalActionsLoading}
onConfirm={(members: string[]) =>
signalAssignment(record.id ?? 0, members)

Check warning on line 267 in src/page/SQLManagement/SQLPanel/column.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 267 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 267 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
}
>
<Typography.Link>
{t('sqlManagement.table.assignMember.label')}
</Typography.Link>
</AssignMember>
</EmptyBox>

<EmptyBox if={actionPermission}>
<UpdateSQLStatus
disabled={signalActionsLoading}
onConfirm={(status) => updateSQLStatus(record.id ?? 0, status)}

Check warning on line 279 in src/page/SQLManagement/SQLPanel/column.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 279 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 279 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
>
<Typography.Link>
{t('sqlManagement.table.updateStatus.triggerText')}
</Typography.Link>
</UpdateSQLStatus>
</EmptyBox>

<UpdateSQLStatus
disabled={signalActionsLoading}
onConfirm={(status) => updateSQLStatus(record.id ?? 0, status)}
<Typography.Link
disabled={
!record.sql || !record.schema_name || !record.instance_name

Check warning on line 289 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 289 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
}
onClick={() => {
handleClickAnalyze(record.id?.toString() ?? '');

Check warning on line 292 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
}}
>
<Typography.Link>
{t('sqlManagement.table.updateStatus.triggerText')}
</Typography.Link>
</UpdateSQLStatus>
{t('sqlManagement.table.analyze')}
</Typography.Link>
</Space>
);

Check warning on line 298 in src/page/SQLManagement/SQLPanel/column.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 301 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
if (!actionPermission) {
return columns.filter((v) => v.dataIndex !== 'operator');
}

return columns;
};

Check warning on line 304 in src/page/SQLManagement/SQLPanel/column.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
5 changes: 5 additions & 0 deletions src/page/SQLManagement/SQLPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ const SQLPanel: React.FC = () => {
]
);

const handleClickAnalyze = (sqlManageId: string) => {
window.open(`/project/${projectName}/sqlManagement/${sqlManageId}/analyze`);
};

const [
exportButtonDisabled,
{ setFalse: finishExport, setTrue: startExport },
Expand Down Expand Up @@ -454,6 +458,7 @@ const SQLPanel: React.FC = () => {
actionPermission,
username,
updateSQLStatus,
handleClickAnalyze,
})}
pagination={{
showSizeChanger: true,
Expand Down
77 changes: 77 additions & 0 deletions src/page/SqlAnalyze/SqlManage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { useBoolean } from 'ahooks';
import { ResultStatusType } from 'antd/lib/result';
import { useCallback, useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import {
IPerformanceStatistics,
ISQLExplain,
ITableMetas,
} from '../../../api/common';
import { ResponseCode } from '../../../data/common';
import SqlAnalyze from '../SqlAnalyze';
import { SQLManageAnalyzeUrlParams } from './index.type';
import SqlManage from '../../../api/SqlManage';
import { useCurrentProjectName } from '../../ProjectManage/ProjectDetail';

const SQLManageAnalyze = () => {

Check warning on line 16 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
const urlParams = useParams<SQLManageAnalyzeUrlParams>();

Check warning on line 17 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const { projectName } = useCurrentProjectName();

Check warning on line 18 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const [errorMessage, setErrorMessage] = useState<string>('');

Check warning on line 19 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

const [sqlExplain, setSqlExplain] = useState<ISQLExplain>();

Check warning on line 21 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const [tableMetas, setTableMetas] = useState<ITableMetas>();

Check warning on line 22 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const [performanceStatistics, setPerformancesStatistics] =
useState<IPerformanceStatistics>();

Check warning on line 24 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const [
loading,
{ setTrue: startGetSqlAnalyze, setFalse: getSqlAnalyzeFinish },
] = useBoolean();

Check warning on line 28 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
const [errorType, setErrorType] = useState<ResultStatusType>('error');

Check warning on line 29 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

const getSqlAnalyze = useCallback(async () => {

Check warning on line 31 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
startGetSqlAnalyze();

Check warning on line 32 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
try {
const res = await SqlManage.GetSqlManageSqlAnalysisV1({
sql_manage_id: urlParams.sqlManageId ?? '',

Check warning on line 35 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 35 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
project_name: projectName,
});

Check warning on line 37 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
if (res.data.code === ResponseCode.SUCCESS) {
setErrorMessage('');

Check warning on line 39 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
setSqlExplain(res.data.data?.sql_explain);

Check warning on line 40 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
setTableMetas(res.data.data?.table_metas);

Check warning on line 41 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
setPerformancesStatistics(res.data.data?.performance_statistics);

Check warning on line 42 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
} else {
if (res.data.code === ResponseCode.NotSupportDML) {
setErrorType('info');

Check warning on line 45 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
} else {
setErrorType('error');

Check warning on line 47 in src/page/SqlAnalyze/SqlManage/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 48 in src/page/SqlAnalyze/SqlManage/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 48 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 48 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
setErrorMessage(res.data.message ?? '');

Check warning on line 49 in src/page/SqlAnalyze/SqlManage/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 49 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 49 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 50 in src/page/SqlAnalyze/SqlManage/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 50 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 50 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🌿 Branch is not covered

Warning! Not covered branch
} finally {
getSqlAnalyzeFinish();

Check warning on line 52 in src/page/SqlAnalyze/SqlManage/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 53 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
}, [
getSqlAnalyzeFinish,
projectName,
startGetSqlAnalyze,
urlParams.sqlManageId,
]);

Check warning on line 59 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

useEffect(() => {

Check warning on line 61 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🕹️ Function is not covered

Warning! Not covered function
getSqlAnalyze();

Check warning on line 62 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement
}, [getSqlAnalyze]);

Check warning on line 63 in src/page/SqlAnalyze/SqlManage/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 (
<SqlAnalyze
errorType={errorType}
tableMetas={tableMetas}
sqlExplain={sqlExplain}
errorMessage={errorMessage}
performanceStatistics={performanceStatistics}
loading={loading}
/>
);

Check warning on line 74 in src/page/SqlAnalyze/SqlManage/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 75 in src/page/SqlAnalyze/SqlManage/index.tsx

View workflow job for this annotation

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

🧾 Statement is not covered

Warning! Not covered statement

export default SQLManageAnalyze;
3 changes: 3 additions & 0 deletions src/page/SqlAnalyze/SqlManage/index.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type SQLManageAnalyzeUrlParams = {
sqlManageId: string;
};
Loading

0 comments on commit 6743950

Please sign in to comment.