@@ -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' ;
@@ -94,6 +96,7 @@ import { LocksTitle } from './LocksTitle.tsx';
94
96
import { MyServiceDetails } from './MyServiceDetails' ;
95
97
import { MyServiceHistory } from './MyServiceHistory' ;
96
98
import {
99
+ getDefaultColumns ,
97
100
isDisableDestroyBtn ,
98
101
isDisableDetails ,
99
102
isDisabledStopOrRestartBtn ,
@@ -104,6 +107,9 @@ import {
104
107
isDisableServiceConfigBtn ,
105
108
isDisableServicePortingBtn ,
106
109
isDisableStartBtn ,
110
+ Option ,
111
+ showForMediumScreenColumn ,
112
+ showForSmallScreenColumn ,
107
113
updateBillingModeFilters ,
108
114
updateCategoryFilters ,
109
115
updateCspFilters ,
@@ -120,6 +126,7 @@ import useGetOrderableServiceDetailsByServiceIdQuery from './query/useGetOrderab
120
126
import useListDeployedServicesDetailsQuery , {
121
127
getListDeployedServicesDetailsQueryKey ,
122
128
} from './query/useListDeployedServicesDetailsQuery' ;
129
+ import { SelectMyServicesColumns } from './SelectMyServicesColumns.tsx' ;
123
130
import { TooltipWhenDetailsDisabled } from './TooltipWhenDetailsDisabled.tsx' ;
124
131
125
132
function MyServices ( ) : React . JSX . Element {
@@ -226,6 +233,9 @@ function MyServices(): React.JSX.Element {
226
233
const [ isLocksModalOpen , setIsLocksModalOpen ] = useState < boolean > ( false ) ;
227
234
228
235
const [ uniqueRequestId , setUniqueRequestId ] = useState < string > ( v4 ( ) ) ;
236
+ const [ isColumnSelectorVisible , setIsColumnSelectorVisible ] = useState ( false ) ;
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
+ const [ checkedValues , setCheckedValues ] = useState < string [ ] > ( getDefaultColumns ( selectedColumns ) ) ;
1030
1042
const closeDestroyResultAlert = ( isClose : boolean ) => {
1031
1043
if ( isClose ) {
1032
1044
setActiveRecord ( undefined ) ;
@@ -1327,6 +1339,61 @@ 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
+ setCheckedValues ( getDefaultColumns ( defaultColumns ) ) ;
1393
+
1394
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1395
+ } , [ isLargeScreen , isMediumScreen ] ) ;
1396
+
1330
1397
return (
1331
1398
< div className = { tableStyles . genericTableContainer } >
1332
1399
{ isDestroyRequestSubmitted && activeRecord ? (
@@ -1535,17 +1602,45 @@ function MyServices(): React.JSX.Element {
1535
1602
</ Modal >
1536
1603
) : null }
1537
1604
1538
- < div >
1605
+ < Modal
1606
+ title = { 'Select Columns' }
1607
+ open = { isColumnSelectorVisible }
1608
+ onCancel = { handleColumnSelectorClose }
1609
+ onOk = { handleColumnSelectorSubmit }
1610
+ width = { 800 }
1611
+ destroyOnClose = { true }
1612
+ >
1613
+ < SelectMyServicesColumns
1614
+ checkedValues = { checkedValues }
1615
+ columnOptions = { columnOptions }
1616
+ handleColumnChange = { handleColumnChange }
1617
+ handleColumnsSelectAll = { handleColumnsSelectAll }
1618
+ handleColumnsSelectNone = { handleColumnsSelectNone }
1619
+ />
1620
+ </ Modal >
1621
+
1622
+ < div className = { myServicesStyles . refreshBtnContainer } >
1539
1623
< Button
1540
1624
disabled = { activeRecord !== undefined }
1541
1625
type = 'primary'
1542
1626
icon = { < SyncOutlined /> }
1543
1627
onClick = { ( ) => {
1544
1628
refreshData ( ) ;
1545
1629
} }
1630
+ block = { false }
1631
+ className = { myServicesStyles . refreshBtnClass }
1546
1632
>
1547
1633
refresh
1548
1634
</ Button >
1635
+ < Button
1636
+ type = 'primary'
1637
+ icon = { < SettingOutlined /> }
1638
+ onClick = { handleColumnSelectorOpen }
1639
+ block = { false }
1640
+ className = { myServicesStyles . selectColumnsClass }
1641
+ >
1642
+ Select Columns
1643
+ </ Button >
1549
1644
</ div >
1550
1645
{ listDeployedServicesQuery . isError ? (
1551
1646
< >
@@ -1562,7 +1657,7 @@ function MyServices(): React.JSX.Element {
1562
1657
< Row >
1563
1658
< div className = { myServicesStyles . serviceInstanceList } >
1564
1659
< Table
1565
- columns = { columns }
1660
+ columns = { selectedColumns }
1566
1661
dataSource = { serviceVoList }
1567
1662
loading = { listDeployedServicesQuery . isPending || listDeployedServicesQuery . isRefetching }
1568
1663
rowKey = { 'id' }
0 commit comments