@@ -18,6 +18,7 @@ import {
18
18
PoweroffOutlined ,
19
19
RedoOutlined ,
20
20
RiseOutlined ,
21
+ SettingOutlined ,
21
22
SyncOutlined ,
22
23
} from '@ant-design/icons' ;
23
24
import { useQueryClient } from '@tanstack/react-query' ;
@@ -34,9 +35,10 @@ import {
34
35
TablePaginationConfig ,
35
36
Tooltip ,
36
37
} from 'antd' ;
37
- import type { ColumnsType } from 'antd/es/table' ;
38
+ import type { ColumnsType , ColumnType } from 'antd/es/table' ;
38
39
import { ColumnFilterItem , FilterValue , SorterResult } from 'antd/es/table/interface' ;
39
40
import React , { useEffect , useMemo , useState } from 'react' ;
41
+ import { useMediaQuery } from 'react-responsive' ;
40
42
import { useLocation , useNavigate } from 'react-router-dom' ;
41
43
import { v4 } from 'uuid' ;
42
44
import myServicesStyles from '../../../../styles/my-services.module.css' ;
@@ -104,6 +106,9 @@ import {
104
106
isDisableServiceConfigBtn ,
105
107
isDisableServicePortingBtn ,
106
108
isDisableStartBtn ,
109
+ Option ,
110
+ showForMediumScreenColumn ,
111
+ showForSmallScreenColumn ,
107
112
updateBillingModeFilters ,
108
113
updateCategoryFilters ,
109
114
updateCspFilters ,
@@ -120,6 +125,7 @@ import useGetOrderableServiceDetailsByServiceIdQuery from './query/useGetOrderab
120
125
import useListDeployedServicesDetailsQuery , {
121
126
getListDeployedServicesDetailsQueryKey ,
122
127
} from './query/useListDeployedServicesDetailsQuery' ;
128
+ import { SelectMyServicesColumns } from './SelectMyServicesColumns.tsx' ;
123
129
import { TooltipWhenDetailsDisabled } from './TooltipWhenDetailsDisabled.tsx' ;
124
130
125
131
function MyServices ( ) : React . JSX . Element {
@@ -226,6 +232,10 @@ function MyServices(): React.JSX.Element {
226
232
const [ isLocksModalOpen , setIsLocksModalOpen ] = useState < boolean > ( false ) ;
227
233
228
234
const [ uniqueRequestId , setUniqueRequestId ] = useState < string > ( v4 ( ) ) ;
235
+ const [ isColumnSelectorVisible , setIsColumnSelectorVisible ] = useState ( false ) ;
236
+ const [ checkedValues , setCheckedValues ] = useState < string [ ] > ( [ ] ) ;
237
+ const isLargeScreen = useMediaQuery ( { minWidth : 1200 } ) ;
238
+ const isMediumScreen = useMediaQuery ( { minWidth : 768 , maxWidth : 1199 } ) ;
229
239
230
240
const serviceDestroyQuery = useDestroyRequestSubmitQuery ( ) ;
231
241
const servicePurgeQuery = usePurgeRequestSubmitQuery ( ) ;
@@ -1027,6 +1037,8 @@ function MyServices(): React.JSX.Element {
1027
1037
} ,
1028
1038
] ;
1029
1039
1040
+ const [ selectedColumns , setSelectedColumns ] = useState < ColumnsType < DeployedService > > ( columns ) ;
1041
+
1030
1042
const closeDestroyResultAlert = ( isClose : boolean ) => {
1031
1043
if ( isClose ) {
1032
1044
setActiveRecord ( undefined ) ;
@@ -1327,6 +1339,59 @@ function MyServices(): React.JSX.Element {
1327
1339
} ) ;
1328
1340
} ;
1329
1341
1342
+ const handleColumnsSelectAll = ( ) => {
1343
+ setCheckedValues ( columnOptions . map ( ( option ) => option . value ) ) ;
1344
+ } ;
1345
+
1346
+ const handleColumnsSelectNone = ( ) => {
1347
+ setCheckedValues ( [ ] ) ;
1348
+ } ;
1349
+
1350
+ const columnOptions : Option [ ] = columns . map ( ( column ) => ( {
1351
+ label : column . title as string ,
1352
+ value : ( column as ColumnType < DeployedService > ) . dataIndex as string ,
1353
+ } ) ) ;
1354
+
1355
+ const handleColumnChange = ( checkedValues : string [ ] ) => {
1356
+ setCheckedValues ( checkedValues ) ;
1357
+ } ;
1358
+
1359
+ const handleColumnSelectorOpen = ( ) => {
1360
+ setIsColumnSelectorVisible ( true ) ;
1361
+ } ;
1362
+
1363
+ const handleColumnSelectorSubmit = ( ) => {
1364
+ setIsColumnSelectorVisible ( false ) ;
1365
+ if ( checkedValues . length > 0 ) {
1366
+ const selectedColumns = columns . filter ( ( column ) =>
1367
+ checkedValues . includes ( ( column as ColumnType < DeployedService > ) . dataIndex as string )
1368
+ ) ;
1369
+ setSelectedColumns ( selectedColumns ) ;
1370
+ }
1371
+ } ;
1372
+
1373
+ const handleColumnSelectorClose = ( ) => {
1374
+ setIsColumnSelectorVisible ( false ) ;
1375
+ } ;
1376
+
1377
+ useEffect ( ( ) => {
1378
+ let defaultColumns ;
1379
+
1380
+ if ( isLargeScreen ) {
1381
+ defaultColumns = columns ;
1382
+ } else if ( isMediumScreen ) {
1383
+ defaultColumns = columns . filter ( ( col ) =>
1384
+ showForMediumScreenColumn . includes ( ( col as ColumnType < DeployedService > ) . dataIndex as string )
1385
+ ) ;
1386
+ } else {
1387
+ defaultColumns = columns . filter ( ( col ) =>
1388
+ showForSmallScreenColumn . includes ( ( col as ColumnType < DeployedService > ) . dataIndex as string )
1389
+ ) ;
1390
+ }
1391
+ setSelectedColumns ( defaultColumns ) ;
1392
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1393
+ } , [ isLargeScreen , isMediumScreen ] ) ;
1394
+
1330
1395
return (
1331
1396
< div className = { tableStyles . genericTableContainer } >
1332
1397
{ isDestroyRequestSubmitted && activeRecord ? (
@@ -1535,6 +1600,23 @@ function MyServices(): React.JSX.Element {
1535
1600
</ Modal >
1536
1601
) : null }
1537
1602
1603
+ < Modal
1604
+ title = { 'Select Columns' }
1605
+ open = { isColumnSelectorVisible }
1606
+ onCancel = { handleColumnSelectorClose }
1607
+ onOk = { handleColumnSelectorSubmit }
1608
+ width = { 800 }
1609
+ destroyOnClose = { true }
1610
+ >
1611
+ < SelectMyServicesColumns
1612
+ checkedValues = { checkedValues }
1613
+ columnOptions = { columnOptions }
1614
+ handleColumnChange = { handleColumnChange }
1615
+ handleColumnsSelectAll = { handleColumnsSelectAll }
1616
+ handleColumnsSelectNone = { handleColumnsSelectNone }
1617
+ />
1618
+ </ Modal >
1619
+
1538
1620
< div >
1539
1621
< Button
1540
1622
disabled = { activeRecord !== undefined }
@@ -1546,6 +1628,10 @@ function MyServices(): React.JSX.Element {
1546
1628
>
1547
1629
refresh
1548
1630
</ Button >
1631
+
1632
+ < Button type = 'primary' icon = { < SettingOutlined /> } onClick = { handleColumnSelectorOpen } >
1633
+ Select Columns
1634
+ </ Button >
1549
1635
</ div >
1550
1636
{ listDeployedServicesQuery . isError ? (
1551
1637
< >
@@ -1562,7 +1648,7 @@ function MyServices(): React.JSX.Element {
1562
1648
< Row >
1563
1649
< div className = { myServicesStyles . serviceInstanceList } >
1564
1650
< Table
1565
- columns = { columns }
1651
+ columns = { selectedColumns }
1566
1652
dataSource = { serviceVoList }
1567
1653
loading = { listDeployedServicesQuery . isPending || listDeployedServicesQuery . isRefetching }
1568
1654
rowKey = { 'id' }
0 commit comments