1
1
import React , { useState , useEffect } from 'react' ;
2
2
import { Card , Button , Divider , Alert , message , Table , Tag , Input , Space , Tooltip , Row , Col , Avatar } from 'antd' ;
3
- import { SyncOutlined , AuditOutlined , TeamOutlined , CheckCircleFilled , CloudServerOutlined , DisconnectOutlined } from '@ant-design/icons' ;
3
+ import { SyncOutlined , AuditOutlined , TeamOutlined , CheckCircleFilled , CloudServerOutlined , DisconnectOutlined , FilterOutlined } from '@ant-design/icons' ;
4
4
import Title from 'antd/lib/typography/Title' ;
5
5
import { Environment } from '../types/environment.types' ;
6
6
import { Workspace } from '../types/workspace.types' ;
@@ -26,6 +26,7 @@ const WorkspacesTab: React.FC<WorkspacesTabProps> = ({ environment }) => {
26
26
const [ refreshing , setRefreshing ] = useState ( false ) ;
27
27
const [ error , setError ] = useState < string | null > ( null ) ;
28
28
const [ searchText , setSearchText ] = useState ( '' ) ;
29
+ const [ showManagedOnly , setShowManagedOnly ] = useState ( false ) ;
29
30
30
31
// Fetch workspaces
31
32
const fetchWorkspaces = async ( ) => {
@@ -73,13 +74,17 @@ const WorkspacesTab: React.FC<WorkspacesTabProps> = ({ environment }) => {
73
74
history . push ( `/setting/environments/${ environment . environmentId } /workspaces/${ workspace . id } ` ) ;
74
75
} ;
75
76
76
- // Filter workspaces based on search
77
+ // Filter workspaces based on search and managed status
77
78
const filteredWorkspaces = searchText
78
79
? workspaces . filter ( workspace =>
79
80
workspace . name . toLowerCase ( ) . includes ( searchText . toLowerCase ( ) ) ||
80
81
workspace . id . toLowerCase ( ) . includes ( searchText . toLowerCase ( ) ) )
81
82
: workspaces ;
82
83
84
+ const displayedWorkspaces = showManagedOnly
85
+ ? filteredWorkspaces . filter ( workspace => workspace . managed )
86
+ : filteredWorkspaces ;
87
+
83
88
// Helper function to generate colors from strings
84
89
const stringToColor = ( str : string ) => {
85
90
let hash = 0 ;
@@ -301,8 +306,8 @@ const WorkspacesTab: React.FC<WorkspacesTabProps> = ({ environment }) => {
301
306
/>
302
307
) : (
303
308
< >
304
- { /* Search Bar */ }
305
- < div style = { { marginBottom : 20 } } >
309
+ { /* Search and Filter Bar */ }
310
+ < div style = { { display : 'flex' , justifyContent : 'space-between' , marginBottom : 20 } } >
306
311
< Search
307
312
placeholder = "Search workspaces by name or ID"
308
313
allowClear
@@ -311,16 +316,28 @@ const WorkspacesTab: React.FC<WorkspacesTabProps> = ({ environment }) => {
311
316
style = { { width : 300 } }
312
317
size = "large"
313
318
/>
314
- { searchText && filteredWorkspaces . length !== workspaces . length && (
315
- < div style = { { marginTop : 8 , color : '#8c8c8c' } } >
316
- Showing { filteredWorkspaces . length } of { workspaces . length } workspaces
317
- </ div >
318
- ) }
319
+ < Button
320
+ onClick = { ( ) => setShowManagedOnly ( ! showManagedOnly ) }
321
+ type = "default"
322
+ icon = { < FilterOutlined /> }
323
+ style = { {
324
+ marginLeft : '8px' ,
325
+ backgroundColor : showManagedOnly ? '#52c41a' : 'white' ,
326
+ color : showManagedOnly ? 'white' : '#52c41a' ,
327
+ borderColor : '#52c41a'
328
+ } }
329
+ />
319
330
</ div >
320
331
332
+ { searchText && displayedWorkspaces . length !== workspaces . length && (
333
+ < div style = { { marginTop : 8 , color : '#8c8c8c' } } >
334
+ Showing { displayedWorkspaces . length } of { workspaces . length } workspaces
335
+ </ div >
336
+ ) }
337
+
321
338
< Table
322
339
columns = { columns }
323
- dataSource = { filteredWorkspaces }
340
+ dataSource = { displayedWorkspaces }
324
341
rowKey = "id"
325
342
pagination = { {
326
343
pageSize : 10 ,
0 commit comments