@@ -2,12 +2,8 @@ import { ActionButton } from 'components/common/ActionComponent';
22import ResourcePageHeading from 'components/common/ResourcePageHeading/ResourcePageHeading' ;
33import Tooltip from 'components/common/Tooltip/Tooltip' ;
44import 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' ;
117import useAppParams from 'lib/hooks/useAppParams' ;
128import {
139 clusterConnectorNewPath ,
@@ -16,46 +12,38 @@ import {
1612 kafkaConnectClustersRelativePath ,
1713} from 'lib/paths' ;
1814import 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
2518type 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+
2936const 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