-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
- Loading branch information
There are no files selected for viewing
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 = () => { | ||
const urlParams = useParams<SQLManageAnalyzeUrlParams>(); | ||
const { projectName } = useCurrentProjectName(); | ||
const [errorMessage, setErrorMessage] = useState<string>(''); | ||
|
||
const [sqlExplain, setSqlExplain] = useState<ISQLExplain>(); | ||
const [tableMetas, setTableMetas] = useState<ITableMetas>(); | ||
const [performanceStatistics, setPerformancesStatistics] = | ||
useState<IPerformanceStatistics>(); | ||
const [ | ||
loading, | ||
{ setTrue: startGetSqlAnalyze, setFalse: getSqlAnalyzeFinish }, | ||
] = useBoolean(); | ||
const [errorType, setErrorType] = useState<ResultStatusType>('error'); | ||
|
||
const getSqlAnalyze = useCallback(async () => { | ||
startGetSqlAnalyze(); | ||
try { | ||
const res = await SqlManage.GetSqlManageSqlAnalysisV1({ | ||
sql_manage_id: urlParams.sqlManageId ?? '', | ||
Check warning on line 35 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
project_name: projectName, | ||
}); | ||
if (res.data.code === ResponseCode.SUCCESS) { | ||
setErrorMessage(''); | ||
setSqlExplain(res.data.data?.sql_explain); | ||
setTableMetas(res.data.data?.table_metas); | ||
setPerformancesStatistics(res.data.data?.performance_statistics); | ||
} else { | ||
if (res.data.code === ResponseCode.NotSupportDML) { | ||
setErrorType('info'); | ||
} else { | ||
setErrorType('error'); | ||
} | ||
Check warning on line 48 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 48 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
setErrorMessage(res.data.message ?? ''); | ||
Check warning on line 49 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 49 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
} | ||
Check warning on line 50 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🧾 Statement is not covered
Check warning on line 50 in src/page/SqlAnalyze/SqlManage/index.tsx GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)🌿 Branch is not covered
|
||
} finally { | ||
getSqlAnalyzeFinish(); | ||
} | ||
}, [ | ||
getSqlAnalyzeFinish, | ||
projectName, | ||
startGetSqlAnalyze, | ||
urlParams.sqlManageId, | ||
]); | ||
|
||
useEffect(() => { | ||
getSqlAnalyze(); | ||
}, [getSqlAnalyze]); | ||
|
||
return ( | ||
<SqlAnalyze | ||
errorType={errorType} | ||
tableMetas={tableMetas} | ||
sqlExplain={sqlExplain} | ||
errorMessage={errorMessage} | ||
performanceStatistics={performanceStatistics} | ||
loading={loading} | ||
/> | ||
); | ||
}; | ||
|
||
export default SQLManageAnalyze; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type SQLManageAnalyzeUrlParams = { | ||
sqlManageId: string; | ||
}; |