Skip to content

Commit 3e2b543

Browse files
committed
make myServices table can be selectable.
1 parent 69c7048 commit 3e2b543

File tree

6 files changed

+221
-9
lines changed

6 files changed

+221
-9
lines changed

package-lock.json

+43-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"rc-tabs": "^15.5.1",
1616
"react": "^19.0.0",
1717
"react-dom": "^19.0.0",
18+
"react-responsive": "^10.0.1",
1819
"react-router-dom": "^7.2.0",
1920
"react-timer-hook": "^3.0.8",
2021
"yaml": "^2.6.1",

src/components/content/deployedServices/myServices/MyServices.tsx

+88-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
PoweroffOutlined,
1919
RedoOutlined,
2020
RiseOutlined,
21+
SettingOutlined,
2122
SyncOutlined,
2223
} from '@ant-design/icons';
2324
import { useQueryClient } from '@tanstack/react-query';
@@ -34,9 +35,10 @@ import {
3435
TablePaginationConfig,
3536
Tooltip,
3637
} from 'antd';
37-
import type { ColumnsType } from 'antd/es/table';
38+
import type { ColumnsType, ColumnType } from 'antd/es/table';
3839
import { ColumnFilterItem, FilterValue, SorterResult } from 'antd/es/table/interface';
3940
import React, { useEffect, useMemo, useState } from 'react';
41+
import { useMediaQuery } from 'react-responsive';
4042
import { useLocation, useNavigate } from 'react-router-dom';
4143
import { v4 } from 'uuid';
4244
import myServicesStyles from '../../../../styles/my-services.module.css';
@@ -104,6 +106,9 @@ import {
104106
isDisableServiceConfigBtn,
105107
isDisableServicePortingBtn,
106108
isDisableStartBtn,
109+
Option,
110+
showForMediumScreenColumn,
111+
showForSmallScreenColumn,
107112
updateBillingModeFilters,
108113
updateCategoryFilters,
109114
updateCspFilters,
@@ -120,6 +125,7 @@ import useGetOrderableServiceDetailsByServiceIdQuery from './query/useGetOrderab
120125
import useListDeployedServicesDetailsQuery, {
121126
getListDeployedServicesDetailsQueryKey,
122127
} from './query/useListDeployedServicesDetailsQuery';
128+
import { SelectMyServicesColumns } from './SelectMyServicesColumns.tsx';
123129
import { TooltipWhenDetailsDisabled } from './TooltipWhenDetailsDisabled.tsx';
124130

125131
function MyServices(): React.JSX.Element {
@@ -226,6 +232,10 @@ function MyServices(): React.JSX.Element {
226232
const [isLocksModalOpen, setIsLocksModalOpen] = useState<boolean>(false);
227233

228234
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 });
229239

230240
const serviceDestroyQuery = useDestroyRequestSubmitQuery();
231241
const servicePurgeQuery = usePurgeRequestSubmitQuery();
@@ -1027,6 +1037,8 @@ function MyServices(): React.JSX.Element {
10271037
},
10281038
];
10291039

1040+
const [selectedColumns, setSelectedColumns] = useState<ColumnsType<DeployedService>>(columns);
1041+
10301042
const closeDestroyResultAlert = (isClose: boolean) => {
10311043
if (isClose) {
10321044
setActiveRecord(undefined);
@@ -1327,6 +1339,59 @@ function MyServices(): React.JSX.Element {
13271339
});
13281340
};
13291341

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+
13301395
return (
13311396
<div className={tableStyles.genericTableContainer}>
13321397
{isDestroyRequestSubmitted && activeRecord ? (
@@ -1535,6 +1600,23 @@ function MyServices(): React.JSX.Element {
15351600
</Modal>
15361601
) : null}
15371602

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+
15381620
<div>
15391621
<Button
15401622
disabled={activeRecord !== undefined}
@@ -1546,6 +1628,10 @@ function MyServices(): React.JSX.Element {
15461628
>
15471629
refresh
15481630
</Button>
1631+
&nbsp;&nbsp;&nbsp;
1632+
<Button type='primary' icon={<SettingOutlined />} onClick={handleColumnSelectorOpen}>
1633+
Select Columns
1634+
</Button>
15491635
</div>
15501636
{listDeployedServicesQuery.isError ? (
15511637
<>
@@ -1562,7 +1648,7 @@ function MyServices(): React.JSX.Element {
15621648
<Row>
15631649
<div className={myServicesStyles.serviceInstanceList}>
15641650
<Table
1565-
columns={columns}
1651+
columns={selectedColumns}
15661652
dataSource={serviceVoList}
15671653
loading={listDeployedServicesQuery.isPending || listDeployedServicesQuery.isRefetching}
15681654
rowKey={'id'}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* SPDX-FileCopyrightText: Huawei Inc.
4+
*/
5+
6+
import { CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons';
7+
import { Button, Checkbox, Col, Row } from 'antd';
8+
import React from 'react';
9+
import myServicesStyles from '../../../../styles/my-services.module.css';
10+
import { Option } from './myServiceProps.tsx';
11+
12+
export const SelectMyServicesColumns = ({
13+
checkedValues,
14+
columnOptions,
15+
handleColumnChange,
16+
handleColumnsSelectAll,
17+
handleColumnsSelectNone,
18+
}: {
19+
checkedValues: string[];
20+
columnOptions: Option[];
21+
handleColumnChange: (checkedValues: string[]) => void;
22+
handleColumnsSelectAll: () => void;
23+
handleColumnsSelectNone: () => void;
24+
}): React.JSX.Element => {
25+
return (
26+
<div>
27+
<div className={myServicesStyles.selectColumnsButton}>
28+
<Button type='primary' onClick={handleColumnsSelectAll}>
29+
<CheckCircleOutlined />
30+
Select All
31+
</Button>
32+
&nbsp;&nbsp;
33+
<Button type='default' onClick={handleColumnsSelectNone}>
34+
<CloseCircleOutlined /> Cancel
35+
</Button>
36+
</div>
37+
<div className={myServicesStyles.columnsContainer}>
38+
<Checkbox.Group
39+
className={myServicesStyles.selectColumns}
40+
onChange={handleColumnChange}
41+
value={checkedValues}
42+
>
43+
<Row>
44+
{columnOptions.map((option, index) => (
45+
<Col span={8} key={index}>
46+
<Checkbox value={option.value}>{option.label}</Checkbox>
47+
</Col>
48+
))}
49+
</Row>
50+
</Checkbox.Group>
51+
</div>
52+
</div>
53+
);
54+
};

src/components/content/deployedServices/myServices/myServiceProps.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,26 @@ export const isDisableRecreateBtn = (
401401
}
402402
return false;
403403
};
404+
405+
export interface Option {
406+
label: string;
407+
value: string;
408+
disabled?: boolean;
409+
}
410+
411+
export const showForMediumScreenColumn = [
412+
'serviceId',
413+
'name',
414+
'version',
415+
'serviceHostingType',
416+
'billingMode',
417+
'region',
418+
'csp',
419+
'flavor',
420+
'createdTime',
421+
'serviceDeploymentState',
422+
'serviceState',
423+
'operation',
424+
];
425+
426+
export const showForSmallScreenColumn = ['serviceId', 'name', 'serviceDeploymentState', 'serviceState', 'operation'];

src/styles/my-services.module.css

+12
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,15 @@
114114
align-items: center;
115115
font-size: 12px;
116116
}
117+
118+
.select-columns {
119+
width: 100%;
120+
}
121+
122+
.select-column-button {
123+
margin-bottom: 100px;
124+
}
125+
126+
.columns-container {
127+
margin-top: 10px;
128+
}

0 commit comments

Comments
 (0)