11import { DATE_TIME_FORMAT , DateSelectOption } from '@/constants/datetime' ;
22import {
33 listSqlMetrics ,
4- listSqlStats ,
54 queryPlanDetailInfo ,
65 querySqlDetailInfo ,
76 querySqlHistoryInfo ,
@@ -19,6 +18,7 @@ import {
1918} from '@umijs/max' ;
2019import {
2120 Button ,
21+ Checkbox ,
2222 DatePicker ,
2323 Drawer ,
2424 Select ,
@@ -120,9 +120,10 @@ const SqlTrendChart: React.FC<SqlTrendChartProps> = ({
120120// --- Main Page Component ---
121121
122122const SqlDetail : React . FC = ( ) => {
123- const { ns, name, sqlId } = useParams < {
123+ const { ns, name, tenantName , sqlId } = useParams < {
124124 ns : string ;
125125 name : string ;
126+ tenantName : string ;
126127 sqlId : string ;
127128 } > ( ) ;
128129 const [ searchParams ] = useSearchParams ( ) ;
@@ -147,6 +148,10 @@ const SqlDetail: React.FC = () => {
147148 const [ selectedLatencyMetrics , setSelectedLatencyMetrics ] = useState <
148149 string [ ]
149150 > ( [ 'elapsed_time' ] ) ;
151+ // 临时存储选中的指标,等下拉框关闭后再更新到正式状态
152+ const [ tempSelectedLatencyMetrics , setTempSelectedLatencyMetrics ] = useState <
153+ string [ ]
154+ > ( [ 'elapsed_time' ] ) ;
150155
151156 // Fetch metrics meta to populate latency selector
152157 useRequest (
@@ -164,10 +169,12 @@ const SqlDetail: React.FC = () => {
164169 . map ( ( m : any ) => m . key ) ;
165170 if ( defaults . length > 0 ) {
166171 setSelectedLatencyMetrics ( defaults ) ;
172+ setTempSelectedLatencyMetrics ( defaults ) ;
167173 } else {
168174 // Fallback to first if no defaults
169175 if ( latencyCat . metrics . length > 0 ) {
170176 setSelectedLatencyMetrics ( [ latencyCat . metrics [ 0 ] . key ] ) ;
177+ setTempSelectedLatencyMetrics ( [ latencyCat . metrics [ 0 ] . key ] ) ;
171178 }
172179 }
173180 }
@@ -204,7 +211,11 @@ const SqlDetail: React.FC = () => {
204211 ) ;
205212
206213 // 2. Fetch History Trend Info
207- const { data : historyData , loading : historyLoading } = useRequest (
214+ const {
215+ data : historyData ,
216+ loading : historyLoading ,
217+ run : refreshHistoryData ,
218+ } = useRequest (
208219 async ( ) => {
209220 if ( ! ns || ! name || ! sqlId ) return ;
210221 const start = timeRange [ 0 ] . unix ( ) ;
@@ -273,28 +284,6 @@ const SqlDetail: React.FC = () => {
273284 }
274285 } ;
275286
276- const { data : sqlMetaData } = useRequest (
277- async ( ) => {
278- if ( ! ns || ! name || ! sqlId ) return ;
279- return listSqlStats ( {
280- // Reuse existing list API to get meta
281- namespace : ns ,
282- obtenant : name ,
283- startTime : timeRange [ 0 ] . unix ( ) ,
284- endTime : timeRange [ 1 ] . unix ( ) ,
285- keyword : sqlId , // Filter by SQL ID
286- outputColumns : [ 'query_sql' , 'user_name' , 'db_name' , 'sql_id' ] , // metrics
287- pageSize : 1 ,
288- pageNum : 1 ,
289- } as any ) ;
290- } ,
291- {
292- refreshDeps : [ ns , name , sqlId , timeRange ] ,
293- } ,
294- ) ;
295-
296- const sqlMeta = stateSqlMeta || sqlMetaData ?. data ?. items ?. [ 0 ] ;
297-
298287 const [ planDrawerOpen , setPlanDrawerOpen ] = useState ( false ) ;
299288
300289 const [ currentPlanId , setCurrentPlanId ] = useState < number > ( ) ;
@@ -410,7 +399,13 @@ const SqlDetail: React.FC = () => {
410399 < Space >
411400 < Button
412401 icon = { < ArrowLeftOutlined /> }
413- onClick = { ( ) => history . back ( ) }
402+ onClick = { ( ) => {
403+ // 返回到列表页,并带上标记表示是从详情页返回的
404+ history . push ( {
405+ pathname : `/tenant/${ ns } /${ name } /${ tenantName } /sql` ,
406+ state : { fromDetail : true } ,
407+ } ) ;
408+ } }
414409 type = "text"
415410 >
416411 { intl . formatMessage ( {
@@ -445,7 +440,7 @@ const SqlDetail: React.FC = () => {
445440 ellipsis = { { rows : 2 , expandable : true , symbol : 'more' } }
446441 copyable
447442 >
448- { sqlMeta ?. querySql || sqlInfo ?. querySql || '-' }
443+ { stateSqlMeta ?. querySql || sqlInfo ?. querySql || '-' }
449444 </ Typography . Paragraph >
450445 </ ProDescriptions . Item >
451446
@@ -464,7 +459,7 @@ const SqlDetail: React.FC = () => {
464459 defaultMessage : '数据库' ,
465460 } ) }
466461 >
467- { dbName || sqlMeta ?. dbName || '-' }
462+ { stateSqlMeta ?. dbName || dbName || '-' }
468463 </ ProDescriptions . Item >
469464
470465 < ProDescriptions . Item
@@ -473,7 +468,7 @@ const SqlDetail: React.FC = () => {
473468 defaultMessage : '用户' ,
474469 } ) }
475470 >
476- { sqlMeta ?. userName || '-' }
471+ { stateSqlMeta ?. userName || '-' }
477472 </ ProDescriptions . Item >
478473 </ ProDescriptions >
479474 </ ProCard >
@@ -532,14 +527,61 @@ const SqlDetail: React.FC = () => {
532527 < Select
533528 mode = "multiple"
534529 maxTagCount = "responsive"
535- value = { selectedLatencyMetrics }
536- onChange = { setSelectedLatencyMetrics }
530+ value = { tempSelectedLatencyMetrics }
531+ onChange = { setTempSelectedLatencyMetrics }
532+ onDropdownVisibleChange = { ( open ) => {
533+ // 当下拉框关闭时,更新正式状态并刷新数据
534+ if ( ! open ) {
535+ setSelectedLatencyMetrics ( tempSelectedLatencyMetrics ) ;
536+ // 延迟刷新,确保状态已更新
537+ setTimeout ( ( ) => {
538+ refreshHistoryData ( ) ;
539+ } , 0 ) ;
540+ }
541+ } }
537542 style = { { width : 400 } }
538543 options = { latencyMetricsMeta . map ( ( m ) => ( {
539544 label : m . name ,
540-
541545 value : m . key ,
542546 } ) ) }
547+ dropdownRender = { ( menu ) => (
548+ < div >
549+ < div
550+ style = { {
551+ padding : '4px 8px' ,
552+ borderBottom : '1px solid #f0f0f0' ,
553+ } }
554+ >
555+ < Checkbox
556+ indeterminate = {
557+ tempSelectedLatencyMetrics . length > 0 &&
558+ tempSelectedLatencyMetrics . length <
559+ latencyMetricsMeta . length
560+ }
561+ checked = {
562+ latencyMetricsMeta . length > 0 &&
563+ tempSelectedLatencyMetrics . length ===
564+ latencyMetricsMeta . length
565+ }
566+ onChange = { ( e ) => {
567+ if ( e . target . checked ) {
568+ setTempSelectedLatencyMetrics (
569+ latencyMetricsMeta . map ( ( m ) => m . key ) ,
570+ ) ;
571+ } else {
572+ setTempSelectedLatencyMetrics ( [ ] ) ;
573+ }
574+ } }
575+ >
576+ { intl . formatMessage ( {
577+ id : 'src.pages.Tenant.Detail.Sql.Detail.SelectAll' ,
578+ defaultMessage : '全选' ,
579+ } ) }
580+ </ Checkbox >
581+ </ div >
582+ { menu }
583+ </ div >
584+ ) }
543585 />
544586 </ Space >
545587 }
0 commit comments