Skip to content

Commit 668206c

Browse files
author
Leshe4ka
committed
few updates
1 parent 3711f75 commit 668206c

File tree

3 files changed

+75
-77
lines changed

3 files changed

+75
-77
lines changed

frontend/src/components/Brokers/BrokersList/BrokersList.tsx

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import React, { useMemo } from 'react';
22
import { ClusterName } from 'lib/interfaces/cluster';
33
import { useNavigate } from 'react-router-dom';
44
import useAppParams from 'lib/hooks/useAppParams';
5-
import Table from 'components/common/NewTable';
5+
import Table, {
6+
exportTableCSV,
7+
TableProvider,
8+
} from 'components/common/NewTable';
69
import { clusterBrokerPath } from 'lib/paths';
710
import { useBrokers } from 'lib/hooks/api/brokers';
811
import { useClusterStats } from 'lib/hooks/api/clusters';
912
import ResourcePageHeading from 'components/common/ResourcePageHeading/ResourcePageHeading';
10-
import { DownloadCsvButton } from 'components/common/DownloadCsvButton/DownloadCsvButton';
11-
import { brokersApiClient } from 'lib/api';
13+
import { Button } from 'components/common/Button/Button';
1214

1315
import { getBrokersTableColumns, getBrokersTableRows } from './lib';
1416
import { BrokersMetrics } from './BrokersMetrics/BrokersMetrics';
@@ -45,40 +47,49 @@ const BrokersList: React.FC = () => {
4547

4648
const columns = useMemo(() => getBrokersTableColumns(), []);
4749

48-
const fetchCsv = async () => {
49-
return brokersApiClient.getBrokersCsv({ clusterName });
50-
};
51-
5250
return (
53-
<>
54-
<ResourcePageHeading text="Brokers">
55-
<DownloadCsvButton
56-
fetchCsv={fetchCsv}
57-
filePrefix={`brokers-${clusterName}`}
58-
/>
59-
</ResourcePageHeading>
51+
<TableProvider>
52+
{({ table }) => {
53+
const handleExportClick = () => {
54+
exportTableCSV(table, { prefix: 'brokers' });
55+
};
56+
57+
return (
58+
<>
59+
<ResourcePageHeading text="Brokers">
60+
<Button
61+
buttonType="primary"
62+
buttonSize="M"
63+
onClick={handleExportClick}
64+
>
65+
Export CSV
66+
</Button>
67+
</ResourcePageHeading>
6068

61-
<BrokersMetrics
62-
brokerCount={brokerCount}
63-
inSyncReplicasCount={inSyncReplicasCount}
64-
outOfSyncReplicasCount={outOfSyncReplicasCount}
65-
version={version}
66-
activeControllers={activeControllers}
67-
offlinePartitionCount={offlinePartitionCount}
68-
onlinePartitionCount={onlinePartitionCount}
69-
underReplicatedPartitionCount={underReplicatedPartitionCount}
70-
/>
69+
<BrokersMetrics
70+
brokerCount={brokerCount}
71+
inSyncReplicasCount={inSyncReplicasCount}
72+
outOfSyncReplicasCount={outOfSyncReplicasCount}
73+
version={version}
74+
activeControllers={activeControllers}
75+
offlinePartitionCount={offlinePartitionCount}
76+
onlinePartitionCount={onlinePartitionCount}
77+
underReplicatedPartitionCount={underReplicatedPartitionCount}
78+
/>
7179

72-
<Table
73-
columns={columns}
74-
data={rows}
75-
enableSorting
76-
onRowClick={({ original: { brokerId } }) =>
77-
navigate(clusterBrokerPath(clusterName, brokerId))
78-
}
79-
emptyMessage="No clusters are online"
80-
/>
81-
</>
80+
<Table
81+
columns={columns}
82+
data={rows}
83+
enableSorting
84+
onRowClick={({ original: { brokerId } }) =>
85+
navigate(clusterBrokerPath(clusterName, brokerId))
86+
}
87+
emptyMessage="No clusters are online"
88+
/>
89+
</>
90+
);
91+
}}
92+
</TableProvider>
8293
);
8394
};
8495

frontend/src/components/Connect/Connect.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react';
2-
import { Navigate, NavLink, Route, Routes } from 'react-router-dom';
2+
import { Navigate, Routes, Route, NavLink } from 'react-router-dom';
33
import {
44
clusterConnectorsPath,
5-
clusterConnectorsRelativePath,
65
ClusterNameRoute,
76
kafkaConnectClustersPath,
87
kafkaConnectClustersRelativePath,
8+
clusterConnectorsRelativePath,
99
} from 'lib/paths';
1010
import useAppParams from 'lib/hooks/useAppParams';
1111
import Navbar from 'components/common/Navigation/Navbar.styled';
1212
import Clusters from 'components/Connect/Clusters/Clusters';
13+
import { TableProvider } from 'components/common/NewTable';
1314

1415
import Connectors from './List/ListPage';
1516
import Header from './Header/Header';
@@ -18,7 +19,7 @@ const Connect: React.FC = () => {
1819
const { clusterName } = useAppParams<ClusterNameRoute>();
1920

2021
return (
21-
<>
22+
<TableProvider>
2223
<Header />
2324
<Navbar role="navigation">
2425
<NavLink
@@ -46,7 +47,7 @@ const Connect: React.FC = () => {
4647
<Route path={kafkaConnectClustersRelativePath} element={<Clusters />} />
4748
<Route path={clusterConnectorsRelativePath} element={<Connectors />} />
4849
</Routes>
49-
</>
50+
</TableProvider>
5051
);
5152
};
5253

frontend/src/components/Connect/Header/Header.tsx

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ import { ActionButton } from 'components/common/ActionComponent';
22
import ResourcePageHeading from 'components/common/ResourcePageHeading/ResourcePageHeading';
33
import Tooltip from 'components/common/Tooltip/Tooltip';
44
import ClusterContext from 'components/contexts/ClusterContext';
5-
import {
6-
Action,
7-
ConnectorColumnsToSort,
8-
ResourceType,
9-
SortOrder,
10-
} from 'generated-sources';
5+
import { ResourceType, Action } from 'generated-sources';
6+
import { useConnects } from 'lib/hooks/api/kafkaConnect';
117
import useAppParams from 'lib/hooks/useAppParams';
128
import {
139
clusterConnectorNewPath,
@@ -16,46 +12,38 @@ import {
1612
kafkaConnectClustersRelativePath,
1713
} from 'lib/paths';
1814
import React from 'react';
19-
import { DownloadCsvButton } from 'components/common/DownloadCsvButton/DownloadCsvButton';
20-
import { kafkaConnectApiClient } from 'lib/api';
21-
import { connects } from 'lib/fixtures/kafkaConnect';
22-
import { useSearchParams } from 'react-router-dom';
23-
import useFts from 'components/common/Fts/useFts';
15+
import { exportTableCSV, useTableInstance } from 'components/common/NewTable';
16+
import { Button } from 'components/common/Button/Button';
2417

2518
type ConnectPage =
2619
| typeof kafkaConnectClustersRelativePath
2720
| typeof clusterConnectorsRelativePath;
2821

22+
const getCsvPrefix = (page: ConnectPage) => {
23+
let prefix = 'kafka-connect';
24+
25+
if (page === clusterConnectorsRelativePath) {
26+
prefix += '-connectors';
27+
}
28+
29+
if (page === kafkaConnectClustersRelativePath) {
30+
prefix += '-clusters';
31+
}
32+
33+
return prefix;
34+
};
35+
2936
const Header = () => {
3037
const { isReadOnly } = React.useContext(ClusterContext);
3138
const { '*': currentPath, clusterName } = useAppParams<
3239
ClusterNameRoute & { ['*']: ConnectPage }
3340
>();
34-
const [searchParams] = useSearchParams();
35-
const { isFtsEnabled } = useFts('connects');
36-
37-
const fetchCsv = async () => {
38-
if (currentPath === kafkaConnectClustersRelativePath) {
39-
return kafkaConnectApiClient.getConnectsCsv({
40-
clusterName,
41-
withStats: true,
42-
});
43-
}
41+
const { data: connects = [] } = useConnects(clusterName, true);
4442

45-
if (currentPath === clusterConnectorsRelativePath) {
46-
return kafkaConnectApiClient.getAllConnectorsCsv({
47-
clusterName,
48-
search: searchParams.get('q') || undefined,
49-
fts: isFtsEnabled,
50-
orderBy:
51-
(searchParams.get('sortBy') as ConnectorColumnsToSort) || undefined,
52-
sortOrder:
53-
(searchParams.get('sortDirection')?.toUpperCase() as SortOrder) ||
54-
undefined,
55-
});
56-
}
43+
const { table } = useTableInstance();
5744

58-
return '';
45+
const handleExportClick = () => {
46+
exportTableCSV(table, { prefix: getCsvPrefix(currentPath) });
5947
};
6048

6149
return (
@@ -64,7 +52,6 @@ const Header = () => {
6452
<Tooltip
6553
value={
6654
<ActionButton
67-
name="Create Connector"
6855
buttonType="primary"
6956
buttonSize="M"
7057
disabled={!connects.length}
@@ -83,10 +70,9 @@ const Header = () => {
8370
/>
8471
)}
8572

86-
<DownloadCsvButton
87-
filePrefix={`connectors-${clusterName}`}
88-
fetchCsv={fetchCsv}
89-
/>
73+
<Button buttonType="primary" buttonSize="M" onClick={handleExportClick}>
74+
Export CSV
75+
</Button>
9076
</ResourcePageHeading>
9177
);
9278
};

0 commit comments

Comments
 (0)