1
- import React , { useMemo } from 'react' ;
2
- import { Grid2 } from '@mui/material' ;
3
- import Tile from '../tile/Index' ;
4
1
import { v1 } from '@docker/extension-api-client-types' ;
2
+ import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' ;
3
+ import KeyboardArrowRightIcon from '@mui/icons-material/KeyboardArrowRight' ;
4
+ import { Collapse , Grid2 , Typography } from '@mui/material' ;
5
+ import React , { useMemo , useState } from 'react' ;
5
6
import { CATALOG_LAYOUT_SX } from '../../Constants' ;
6
7
import { useCatalogAll } from '../../queries/useCatalog' ;
8
+ import Tile from '../tile/Index' ;
7
9
8
10
interface ToolCatalogProps {
9
11
search : string ;
@@ -19,6 +21,8 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
19
21
sort,
20
22
} ) => {
21
23
const { catalogItems, registryLoading } = useCatalogAll ( client ) ;
24
+ const [ expandedEnabled , setExpandedEnabled ] = useState ( true ) ;
25
+ const [ expandedNotEnabled , setExpandedNotEnabled ] = useState ( true ) ;
22
26
23
27
// Memoize the filtered catalog items to prevent unnecessary recalculations
24
28
const result = useMemo ( ( ) => {
@@ -32,29 +36,67 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
32
36
33
37
return sort === 'name-asc'
34
38
? filteredItems . sort ( ( a , b ) => {
35
- return a . name . localeCompare ( b . name ) ;
36
- } )
39
+ return a . name . localeCompare ( b . name ) ;
40
+ } )
37
41
: sort === 'name-desc'
38
- ? filteredItems . sort ( ( a , b ) => {
42
+ ? filteredItems . sort ( ( a , b ) => {
39
43
return b . name . localeCompare ( a . name ) ;
40
44
} )
41
- : filteredItems ;
45
+ : filteredItems ;
42
46
} , [ catalogItems , search , showMine , sort ] ) ;
43
47
48
+
49
+
44
50
return (
45
- < Grid2 container spacing = { 1 } sx = { CATALOG_LAYOUT_SX } >
46
- { result . map ( ( catalogItem ) => {
47
- return (
48
- < Grid2 size = { { xs : 12 , sm : 6 , md : 4 } } key = { catalogItem . name } >
49
- < Tile
50
- item = { catalogItem }
51
- client = { client }
52
- registryLoading = { registryLoading }
53
- />
54
- </ Grid2 >
55
- ) ;
56
- } ) }
57
- </ Grid2 >
51
+ < >
52
+ < Typography
53
+ variant = 'subtitle2'
54
+ sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" } }
55
+ onClick = { ( ) => setExpandedEnabled ( ! expandedEnabled ) } >
56
+ Enabled tools
57
+ { expandedEnabled ? < KeyboardArrowDownIcon fontSize = "small" /> : < KeyboardArrowRightIcon fontSize = "small" /> }
58
+ </ Typography >
59
+
60
+ < Collapse in = { expandedEnabled } >
61
+ < Grid2 container spacing = { 1 } sx = { CATALOG_LAYOUT_SX } >
62
+ { result . filter ( ( item ) => item . registered ) . map ( ( catalogItem ) => {
63
+ return (
64
+ < Grid2 size = { { xs : 12 , sm : 6 , md : 4 } } key = { catalogItem . name } >
65
+ < Tile
66
+ item = { catalogItem }
67
+ client = { client }
68
+ registryLoading = { registryLoading }
69
+ />
70
+ </ Grid2 >
71
+ ) ;
72
+ } ) }
73
+ </ Grid2 >
74
+ </ Collapse >
75
+
76
+ < Typography
77
+ variant = 'subtitle2'
78
+ sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" } }
79
+ onClick = { ( ) => setExpandedNotEnabled ( ! expandedNotEnabled ) } >
80
+ All the tools
81
+ { expandedNotEnabled ? < KeyboardArrowDownIcon fontSize = "small" /> : < KeyboardArrowRightIcon fontSize = "small" /> }
82
+ </ Typography >
83
+
84
+ < Collapse in = { expandedNotEnabled } >
85
+ < Grid2 container spacing = { 1 } sx = { CATALOG_LAYOUT_SX } >
86
+ { result . filter ( ( item ) => true ) . map ( ( catalogItem ) => {
87
+ return (
88
+ < Grid2 size = { { xs : 12 , sm : 6 , md : 4 } } key = { catalogItem . name } >
89
+ < Tile
90
+ item = { catalogItem }
91
+ client = { client }
92
+ registryLoading = { registryLoading }
93
+ />
94
+ </ Grid2 >
95
+ ) ;
96
+ } ) }
97
+ </ Grid2 >
98
+ </ Collapse >
99
+ </ >
58
100
) ;
59
101
} ;
60
102
0 commit comments