11import {
22 AgentSummaryListQuery ,
33 AgentSummaryListQuery$data ,
4+ AgentSummaryListQuery$variables ,
45} from '../__generated__/AgentSummaryListQuery.graphql' ;
56import {
67 convertToBinaryUnit ,
78 toFixedFloorWithoutTrailingZeros ,
89} from '../helper' ;
910import { useUpdatableState } from '../hooks' ;
1011import { ResourceSlotName , useResourceSlotsDetails } from '../hooks/backendai' ;
11- import { useBAIPaginationOptionState } from '../hooks/reactPaginationQueryOptions' ;
12+ import { useBAIPaginationOptionStateOnSearchParam } from '../hooks/reactPaginationQueryOptions' ;
1213import { useResourceGroupsForCurrentProject } from '../hooks/useCurrentProject' ;
1314import { useHiddenColumnKeysSetting } from '../hooks/useHiddenColumnKeysSetting' ;
1415import BAIProgressWithLabel from './BAIProgressWithLabel' ;
@@ -19,7 +20,6 @@ import {
1920 CheckCircleOutlined ,
2021 MinusCircleOutlined ,
2122 ReloadOutlined ,
22- SettingOutlined ,
2323} from '@ant-design/icons' ;
2424import { useToggle } from 'ahooks' ;
2525import { Button , TableProps , theme , Tooltip , Typography } from 'antd' ;
@@ -33,9 +33,17 @@ import {
3333 mergeFilterValues ,
3434} from 'backend.ai-ui' ;
3535import _ from 'lodash' ;
36- import React , { useState , useTransition } from 'react' ;
36+ import React , {
37+ useDeferredValue ,
38+ useMemo ,
39+ useState ,
40+ useTransition ,
41+ } from 'react' ;
3742import { useTranslation } from 'react-i18next' ;
3843import { graphql , FetchPolicy , useLazyLoadQuery } from 'react-relay' ;
44+ import { useBAISettingUserState } from 'src/hooks/useBAISetting' ;
45+ import { useDeferredQueryParams } from 'src/hooks/useDeferredQueryParams' ;
46+ import { StringParam , withDefault } from 'use-query-params' ;
3947
4048type AgentSummary = NonNullable <
4149 AgentSummaryListQuery$data [ 'agent_summary_list' ]
@@ -55,25 +63,22 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
5563 const { mergedResourceSlots } = useResourceSlotsDetails ( ) ;
5664 const [ visibleColumnSettingModal , { toggle : toggleColumnSettingModal } ] =
5765 useToggle ( ) ;
58- const [ isPendingStatusFetch , startStatusFetchTransition ] = useTransition ( ) ;
5966 const [ isPendingRefresh , startRefreshTransition ] = useTransition ( ) ;
60- const [ isPendingPageChange , startPageChangeTransition ] = useTransition ( ) ;
61- const [ selectedStatus , setSelectedStatus ] = useState ( 'ALIVE' ) ;
62- const [ optimisticSelectedStatus , setOptimisticSelectedStatus ] =
63- useState ( selectedStatus ) ;
64- const [ isPendingFilter , startFilterTransition ] = useTransition ( ) ;
65-
66- const [ filterString , setFilterString ] = useState < string > ( ) ;
6767
6868 const {
6969 baiPaginationOption,
7070 tablePaginationOption,
7171 setTablePaginationOption,
72- } = useBAIPaginationOptionState ( {
72+ } = useBAIPaginationOptionStateOnSearchParam ( {
7373 current : 1 ,
7474 pageSize : 20 ,
7575 } ) ;
76- const [ order , setOrder ] = useState < string > ( ) ;
76+
77+ const [ queryParams , setQuery ] = useDeferredQueryParams ( {
78+ order : withDefault ( StringParam , undefined ) ,
79+ filter : withDefault ( StringParam , undefined ) ,
80+ status : withDefault ( StringParam , 'ALIVE' ) ,
81+ } ) ;
7782
7883 const [ fetchKey , updateFetchKey ] = useUpdatableState ( 'first' ) ;
7984 const [ fetchPolicy ] = useState < FetchPolicy > ( 'network-only' ) ;
@@ -88,6 +93,29 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
8893 ? `!(scaling_group in [${ sftpResourceGroups . map ( ( group ) => `"${ group } "` ) . join ( ', ' ) } ])`
8994 : undefined ;
9095
96+ const queryVariables : AgentSummaryListQuery$variables = useMemo (
97+ ( ) => ( {
98+ limit : baiPaginationOption . limit ,
99+ offset : baiPaginationOption . offset ,
100+ filter : mergeFilterValues ( [ queryParams . filter , sftpExclusionFilter ] ) ,
101+ order : queryParams . order ,
102+ status : queryParams . status ,
103+ } ) ,
104+ [
105+ baiPaginationOption . limit ,
106+ baiPaginationOption . offset ,
107+ queryParams . filter ,
108+ queryParams . order ,
109+ queryParams . status ,
110+ sftpExclusionFilter ,
111+ ] ,
112+ ) ;
113+ const deferredQueryVariables = useDeferredValue ( queryVariables ) ;
114+
115+ const [ columnOverrides , setColumnOverrides ] = useBAISettingUserState (
116+ 'table_column_overrides.AgentSummaryList' ,
117+ ) ;
118+
91119 const { agent_summary_list } = useLazyLoadQuery < AgentSummaryListQuery > (
92120 graphql `
93121 query AgentSummaryListQuery(
@@ -117,13 +145,7 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
117145 }
118146 }
119147 ` ,
120- {
121- limit : baiPaginationOption . limit ,
122- offset : baiPaginationOption . offset ,
123- filter : mergeFilterValues ( [ filterString , sftpExclusionFilter ] ) ,
124- order,
125- status : selectedStatus ,
126- } ,
148+ deferredQueryVariables ,
127149 {
128150 fetchKey,
129151 fetchPolicy,
@@ -363,15 +385,10 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
363385 value : 'TERMINATED' ,
364386 } ,
365387 ] }
366- value = {
367- isPendingStatusFetch ? optimisticSelectedStatus : selectedStatus
368- }
388+ value = { queryParams . status }
369389 onChange = { ( e ) => {
370390 const value = e . target . value ;
371- setOptimisticSelectedStatus ( value ) ;
372- startStatusFetchTransition ( ( ) => {
373- setSelectedStatus ( value ) ;
374- } ) ;
391+ setQuery ( { status : value } , 'replaceIn' ) ;
375392 } }
376393 />
377394
@@ -398,12 +415,10 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
398415 ] ,
399416 } ,
400417 ] }
401- value = { filterString }
402- // loading={isPendingFilter}
418+ value = { queryParams . filter }
403419 onChange = { ( value ) => {
404- startFilterTransition ( ( ) => {
405- setFilterString ( value ) ;
406- } ) ;
420+ setQuery ( { filter : value } , 'replaceIn' ) ;
421+ setTablePaginationOption ( { current : 1 } ) ;
407422 } }
408423 />
409424 </ BAIFlex >
@@ -431,34 +446,22 @@ const AgentSummaryList: React.FC<AgentSummaryListProps> = ({
431446 }
432447 pagination = { {
433448 pageSize : tablePaginationOption . pageSize ,
434- total : agent_summary_list ?. total_count || 0 ,
435449 current : tablePaginationOption . current ,
436- onChange ( page , pageSize ) {
437- startPageChangeTransition ( ( ) => {
438- if ( _ . isNumber ( page ) && _ . isNumber ( pageSize ) ) {
439- setTablePaginationOption ( {
440- current : page ,
441- pageSize,
442- } ) ;
443- }
444- } ) ;
450+ total : agent_summary_list ?. total_count ?? 0 ,
451+ onChange ( current , pageSize ) {
452+ if ( _ . isNumber ( current ) && _ . isNumber ( pageSize ) ) {
453+ setTablePaginationOption ( { current, pageSize } ) ;
454+ }
445455 } ,
446- extraContent : (
447- < Button
448- type = "text"
449- icon = { < SettingOutlined /> }
450- onClick = { ( ) => {
451- toggleColumnSettingModal ( ) ;
452- } }
453- />
454- ) ,
455456 } }
456457 onChangeOrder = { ( order ) => {
457- startPageChangeTransition ( ( ) => {
458- setOrder ( order ) ;
459- } ) ;
458+ setQuery ( { order } , 'replaceIn' ) ;
459+ } }
460+ tableSettings = { {
461+ columnOverrides : columnOverrides ,
462+ onColumnOverridesChange : setColumnOverrides ,
460463 } }
461- loading = { isPendingPageChange || isPendingStatusFetch || isPendingFilter }
464+ loading = { deferredQueryVariables !== queryVariables }
462465 { ...tableProps }
463466 />
464467 < TableColumnsSettingModal
0 commit comments