1
- import React , { useState } from 'react' ;
2
- import { Table , Typography , Alert , Input , Button , Space , Empty } from 'antd' ;
3
- import { SearchOutlined , ReloadOutlined } from '@ant-design/icons' ;
4
- import { useHistory } from 'react-router-dom' ;
5
- import { useEnvironments } from './hooks/useEnvironments' ;
6
- import { Environment } from './types/environment.types' ;
1
+ import React , { useState } from "react" ;
2
+ import { Table , Typography , Alert , Input , Button , Space , Empty } from "antd" ;
3
+ import { SearchOutlined , ReloadOutlined } from "@ant-design/icons" ;
4
+ import { useHistory } from "react-router-dom" ;
5
+ import { useEnvironments } from "./hooks/useEnvironments" ;
6
+ import { Environment } from "./types/environment.types" ;
7
+ import EnvironmentsTable from "./components/EnvironmentsTable" ;
7
8
8
9
const { Title } = Typography ;
9
10
@@ -14,19 +15,19 @@ const { Title } = Typography;
14
15
const EnvironmentsList : React . FC = ( ) => {
15
16
// Use our custom hook to get environments data and states
16
17
const { environments, loading, error, refresh } = useEnvironments ( ) ;
17
-
18
+
18
19
// State for search input
19
- const [ searchText , setSearchText ] = useState ( '' ) ;
20
-
20
+ const [ searchText , setSearchText ] = useState ( "" ) ;
21
+
21
22
// Hook for navigation (using history instead of navigate)
22
23
const history = useHistory ( ) ;
23
24
24
25
// Filter environments based on search text
25
- const filteredEnvironments = environments . filter ( env => {
26
+ const filteredEnvironments = environments . filter ( ( env ) => {
26
27
const searchLower = searchText . toLowerCase ( ) ;
27
28
return (
28
- ( env . environmentName || '' ) . toLowerCase ( ) . includes ( searchLower ) ||
29
- ( env . environmentFrontendUrl || '' ) . toLowerCase ( ) . includes ( searchLower ) ||
29
+ ( env . environmentName || "" ) . toLowerCase ( ) . includes ( searchLower ) ||
30
+ ( env . environmentFrontendUrl || "" ) . toLowerCase ( ) . includes ( searchLower ) ||
30
31
env . environmentId . toLowerCase ( ) . includes ( searchLower ) ||
31
32
env . environmentType . toLowerCase ( ) . includes ( searchLower )
32
33
) ;
@@ -35,64 +36,63 @@ const EnvironmentsList: React.FC = () => {
35
36
// Define table columns - updated to match the actual data structure
36
37
const columns = [
37
38
{
38
- title : ' Name' ,
39
- dataIndex : ' environmentName' ,
40
- key : ' environmentName' ,
41
- render : ( name : string ) => name || ' Unnamed Environment' ,
39
+ title : " Name" ,
40
+ dataIndex : " environmentName" ,
41
+ key : " environmentName" ,
42
+ render : ( name : string ) => name || " Unnamed Environment" ,
42
43
} ,
43
44
{
44
- title : ' Domain' ,
45
- dataIndex : ' environmentFrontendUrl' ,
46
- key : ' environmentFrontendUrl' ,
47
- render : ( url : string ) => url || ' No URL' ,
45
+ title : " Domain" ,
46
+ dataIndex : " environmentFrontendUrl" ,
47
+ key : " environmentFrontendUrl" ,
48
+ render : ( url : string ) => url || " No URL" ,
48
49
} ,
49
50
{
50
- title : 'ID' ,
51
- dataIndex : ' environmentId' ,
52
- key : ' environmentId' ,
51
+ title : "ID" ,
52
+ dataIndex : " environmentId" ,
53
+ key : " environmentId" ,
53
54
} ,
54
55
{
55
- title : ' Stage' ,
56
- dataIndex : ' environmentType' ,
57
- key : ' environmentType' ,
56
+ title : " Stage" ,
57
+ dataIndex : " environmentType" ,
58
+ key : " environmentType" ,
58
59
} ,
59
60
{
60
- title : ' Master' ,
61
- dataIndex : ' isMaster' ,
62
- key : ' isMaster' ,
63
- render : ( isMaster : boolean ) => isMaster ? ' Yes' : 'No' ,
61
+ title : " Master" ,
62
+ dataIndex : " isMaster" ,
63
+ key : " isMaster" ,
64
+ render : ( isMaster : boolean ) => ( isMaster ? " Yes" : "No" ) ,
64
65
} ,
65
66
] ;
66
-
67
+
67
68
// Handle row click to navigate to environment detail
68
69
const handleRowClick = ( record : Environment ) => {
69
70
history . push ( `/home/settings/environments/${ record . environmentId } ` ) ;
70
71
} ;
71
72
72
73
return (
73
- < div className = "environments-container" style = { { padding : ' 24px' } } >
74
+ < div className = "environments-container" style = { { padding : " 24px" } } >
74
75
{ /* Header section with title and controls */ }
75
- < div className = "environments-header" style = { {
76
- marginBottom : '24px' ,
77
- display : 'flex' ,
78
- justifyContent : 'space-between' ,
79
- alignItems : 'center'
80
- } } >
76
+ < div
77
+ className = "environments-header"
78
+ style = { {
79
+ marginBottom : "24px" ,
80
+ display : "flex" ,
81
+ justifyContent : "space-between" ,
82
+ alignItems : "center" ,
83
+ } }
84
+ >
81
85
< Title level = { 3 } > Environments</ Title >
82
86
< Space >
83
87
< Input
84
88
placeholder = "Search environments"
85
89
value = { searchText }
86
- onChange = { e => setSearchText ( e . target . value ) }
90
+ onChange = { ( e ) => setSearchText ( e . target . value ) }
87
91
style = { { width : 250 } }
88
92
prefix = { < SearchOutlined /> }
89
93
allowClear
90
94
/>
91
- < Button
92
- icon = { < ReloadOutlined /> }
93
- onClick = { refresh }
94
- loading = { loading }
95
- >
95
+ < Button icon = { < ReloadOutlined /> } onClick = { refresh } loading = { loading } >
96
96
Refresh
97
97
</ Button >
98
98
</ Space >
@@ -105,7 +105,7 @@ const EnvironmentsList: React.FC = () => {
105
105
description = { error }
106
106
type = "error"
107
107
showIcon
108
- style = { { marginBottom : ' 24px' } }
108
+ style = { { marginBottom : " 24px" } }
109
109
/>
110
110
) }
111
111
@@ -117,20 +117,14 @@ const EnvironmentsList: React.FC = () => {
117
117
/>
118
118
) : (
119
119
/* Table component */
120
- < Table
121
- dataSource = { filteredEnvironments }
122
- columns = { columns }
123
- rowKey = "environmentId"
120
+ < EnvironmentsTable
121
+ environments = { filteredEnvironments }
124
122
loading = { loading }
125
- pagination = { { pageSize : 10 } }
126
- onRow = { ( record ) => ( {
127
- onClick : ( ) => handleRowClick ( record ) ,
128
- style : { cursor : 'pointer' }
129
- } ) }
123
+ onRowClick = { handleRowClick }
130
124
/>
131
125
) }
132
126
</ div >
133
127
) ;
134
128
} ;
135
129
136
- export default EnvironmentsList ;
130
+ export default EnvironmentsList ;
0 commit comments