@@ -6,21 +6,28 @@ import React, { useEffect, useMemo, useState } from 'react';
6
6
import { CATALOG_LAYOUT_SX } from '../../Constants' ;
7
7
import { useCatalogAll } from '../../queries/useCatalog' ;
8
8
import Tile from '../tile/Index' ;
9
+ import ConfigurationModal from '../tile/Modal' ;
10
+ import { CatalogItemRichened } from '../../types' ;
9
11
10
12
interface ToolCatalogProps {
11
13
search : string ;
12
14
client : v1 . DockerDesktopClient ;
13
15
sort : 'name-asc' | 'name-desc' ;
14
16
}
15
17
16
- const ToolCatalog : React . FC < ToolCatalogProps > = ( {
17
- search,
18
- client,
19
- sort,
20
- } ) => {
18
+ const ToolCatalog : React . FC < ToolCatalogProps > = ( { search, client, sort } ) => {
21
19
const { catalogItems, registryLoading } = useCatalogAll ( client ) ;
22
- const [ expandedEnabled , setExpandedEnabled ] = useState ( localStorage . getItem ( 'expandedEnabled' ) !== 'false' ) ;
23
- const [ expandedNotEnabled , setExpandedNotEnabled ] = useState ( localStorage . getItem ( 'expandedNotEnabled' ) !== 'false' ) ;
20
+ const [ expandedEnabled , setExpandedEnabled ] = useState (
21
+ localStorage . getItem ( 'expandedEnabled' ) !== 'false' ,
22
+ ) ;
23
+ const [ expandedNotEnabled , setExpandedNotEnabled ] = useState (
24
+ localStorage . getItem ( 'expandedNotEnabled' ) !== 'false' ,
25
+ ) ;
26
+
27
+ const [ showConfigModal , setShowConfigModal ] = useState ( false ) ;
28
+ const [ selectedItem , setSelectedItem ] = useState < CatalogItemRichened | null > (
29
+ null ,
30
+ ) ;
24
31
25
32
// Memoize the filtered catalog items to prevent unnecessary recalculations
26
33
const all = useMemo ( ( ) => {
@@ -30,31 +37,54 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
30
37
31
38
return sort === 'name-asc'
32
39
? filteredItems . sort ( ( a , b ) => {
33
- return a . name . localeCompare ( b . name ) ;
34
- } )
40
+ return a . name . localeCompare ( b . name ) ;
41
+ } )
35
42
: sort === 'name-desc'
36
43
? filteredItems . sort ( ( a , b ) => {
37
- return b . name . localeCompare ( a . name ) ;
38
- } )
44
+ return b . name . localeCompare ( a . name ) ;
45
+ } )
39
46
: filteredItems ;
40
47
} , [ catalogItems , search , sort ] ) ;
41
48
const enabled = all . filter ( ( item ) => item . registered ) ;
42
49
43
50
return (
44
51
< >
45
- { ( enabled . length > 0 ) && (
52
+ { selectedItem !== null && (
53
+ < ConfigurationModal
54
+ open = { showConfigModal }
55
+ onClose = { ( ) => setShowConfigModal ( false ) }
56
+ catalogItem = { selectedItem }
57
+ client = { client }
58
+ registryLoading = { registryLoading }
59
+ />
60
+ ) }
61
+ { enabled . length > 0 && (
46
62
< >
47
63
< Typography
48
- variant = 'subtitle2'
49
- sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" , width : 'fit-content' } }
64
+ variant = "subtitle2"
65
+ sx = { {
66
+ color : 'text.secondary' ,
67
+ display : 'flex' ,
68
+ alignItems : 'center' ,
69
+ cursor : 'pointer' ,
70
+ width : 'fit-content' ,
71
+ } }
50
72
onClick = { ( ) => {
51
- const newExpanded = ! expandedEnabled
73
+ const newExpanded = ! expandedEnabled ;
52
74
setExpandedEnabled ( newExpanded ) ;
53
- localStorage . setItem ( 'expandedEnabled' , JSON . stringify ( newExpanded ) ) ;
54
- } } >
75
+ localStorage . setItem (
76
+ 'expandedEnabled' ,
77
+ JSON . stringify ( newExpanded ) ,
78
+ ) ;
79
+ } }
80
+ >
55
81
{ `Enabled (${ enabled . length } )` }
56
- { expandedEnabled ? < KeyboardArrowDownIcon fontSize = "small" /> : < KeyboardArrowRightIcon fontSize = "small" /> }
57
- </ Typography >
82
+ { expandedEnabled ? (
83
+ < KeyboardArrowDownIcon fontSize = "small" />
84
+ ) : (
85
+ < KeyboardArrowRightIcon fontSize = "small" />
86
+ ) }
87
+ </ Typography >
58
88
59
89
< Collapse in = { expandedEnabled } >
60
90
< Grid2 container spacing = { 1 } sx = { CATALOG_LAYOUT_SX } >
@@ -65,6 +95,8 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
65
95
item = { catalogItem }
66
96
client = { client }
67
97
registryLoading = { registryLoading }
98
+ setSelectedItem = { setSelectedItem }
99
+ setShowConfigModal = { setShowConfigModal }
68
100
/>
69
101
</ Grid2 >
70
102
) ;
@@ -75,15 +107,29 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
75
107
) }
76
108
77
109
< Typography
78
- variant = 'subtitle2'
79
- sx = { { color : "text.secondary" , display : "flex" , alignItems : "center" , cursor : "pointer" , width : 'fit-content' } }
110
+ variant = "subtitle2"
111
+ sx = { {
112
+ color : 'text.secondary' ,
113
+ display : 'flex' ,
114
+ alignItems : 'center' ,
115
+ cursor : 'pointer' ,
116
+ width : 'fit-content' ,
117
+ } }
80
118
onClick = { ( ) => {
81
- const newExpanded = ! expandedNotEnabled
119
+ const newExpanded = ! expandedNotEnabled ;
82
120
setExpandedNotEnabled ( newExpanded ) ;
83
- localStorage . setItem ( 'expandedNotEnabled' , JSON . stringify ( newExpanded ) ) ;
84
- } } >
121
+ localStorage . setItem (
122
+ 'expandedNotEnabled' ,
123
+ JSON . stringify ( newExpanded ) ,
124
+ ) ;
125
+ } }
126
+ >
85
127
{ `All (${ all . length } )` }
86
- { expandedNotEnabled ? < KeyboardArrowDownIcon fontSize = "small" /> : < KeyboardArrowRightIcon fontSize = "small" /> }
128
+ { expandedNotEnabled ? (
129
+ < KeyboardArrowDownIcon fontSize = "small" />
130
+ ) : (
131
+ < KeyboardArrowRightIcon fontSize = "small" />
132
+ ) }
87
133
</ Typography >
88
134
89
135
< Collapse in = { expandedNotEnabled } >
@@ -95,6 +141,8 @@ const ToolCatalog: React.FC<ToolCatalogProps> = ({
95
141
item = { catalogItem }
96
142
client = { client }
97
143
registryLoading = { registryLoading }
144
+ setSelectedItem = { setSelectedItem }
145
+ setShowConfigModal = { setShowConfigModal }
98
146
/>
99
147
</ Grid2 >
100
148
) ;
0 commit comments