@@ -27,81 +27,35 @@ const LoadingState = () => {
27
27
}
28
28
29
29
const ConfigEditor = ( { catalogItem, client } : { catalogItem : CatalogItemRichened , client : v1 . DockerDesktopClient } ) => {
30
- const configSchema = catalogItem . config ;
30
+ const configSchema = catalogItem . configSchema ;
31
31
32
- const { config : existingConfig , saveConfig : updateExistingConfig , configLoading, tryLoadConfig } = useConfig ( client ) ;
32
+ const { config, saveConfig : updateExistingConfig , configLoading } = useConfig ( client ) ;
33
33
34
- const existingConfigForItem = existingConfig ?. [ catalogItem . name ] ;
34
+ const existingConfigForItem = catalogItem . configValue || { } ;
35
35
36
- // Create a key that changes whenever existingConfigForItem changes
37
- const configKey = useMemo ( ( ) =>
38
- existingConfigForItem ? JSON . stringify ( existingConfigForItem ) : 'empty-config' ,
39
- [ existingConfigForItem ] ) ;
40
36
41
37
const [ localConfig , setLocalConfig ] = useState < { [ key : string ] : any } | undefined > ( undefined ) ;
42
- const [ config , setConfig ] = useState < any > ( undefined ) ;
43
38
const [ savingKeys , setSavingKeys ] = useState < Set < string > > ( new Set ( ) ) ;
44
39
45
40
// Use memoized flattenedConfig to ensure it only updates when config changes
46
41
// This MUST be called before any early returns to avoid conditional hook calls
47
42
const flattenedConfig = useMemo ( ( ) =>
48
- config ? deepFlattenObject ( config ) : { } ,
49
- [ config ] ) ;
43
+ configSchema ? deepFlattenObject ( { ... catalogItem . configTemplate , ... existingConfigForItem } ) : { } ,
44
+ [ catalogItem . configTemplate , existingConfigForItem , configSchema ] ) ;
50
45
51
46
// Reset local config when the existing config changes
52
47
useEffect ( ( ) => {
53
48
if ( ! configSchema ) return ;
54
-
55
- try {
56
- const template = getTemplateForItem ( catalogItem , existingConfigForItem ) ;
57
- setConfig ( template ) ;
58
- setLocalConfig ( deepFlattenObject ( template ) ) ;
59
- } catch ( error ) {
60
- console . error ( "Error processing config schema:" , error ) ;
61
- }
62
- } , [ existingConfig , existingConfigForItem , configSchema , configKey ] ) ;
63
-
64
- // Handle saving a config item
65
- const handleSaveConfig = async ( key : string ) => {
66
- if ( savingKeys . has ( key ) ) return ;
67
-
68
- try {
69
- setSavingKeys ( prev => new Set ( [ ...prev , key ] ) ) ;
70
- const updatedConfig = deepSet ( existingConfigForItem || { } , key , localConfig ?. [ key ] ) ;
71
-
72
- // Force a deep clone to ensure we're sending a new object reference
73
- const cleanConfig = JSON . parse ( JSON . stringify ( updatedConfig ) ) ;
74
-
75
- // Wait for the config update to complete
76
- await updateExistingConfig ( catalogItem . name , cleanConfig ) ;
77
-
78
- // Also update our local state to match the new saved state
79
- const schema = new JsonSchema . Draft2019 ( configSchema [ 0 ] ) ;
80
- const newTemplate = schema . getTemplate ( cleanConfig ) ;
81
- setConfig ( newTemplate ) ;
82
-
83
- // Reset localConfig to match the new template
84
- setLocalConfig ( deepFlattenObject ( newTemplate ) ) ;
85
-
86
- // After saving, force a refetch to ensure UI is in sync
87
- await tryLoadConfig ( ) ;
88
- } catch ( error ) {
89
- console . error ( "Error saving config:" , error ) ;
90
- } finally {
91
- setSavingKeys ( prev => {
92
- const updated = new Set ( [ ...prev ] ) ;
93
- updated . delete ( key ) ;
94
- return updated ;
95
- } ) ;
96
- }
97
- } ;
49
+ if ( localConfig ) return ;
50
+ setLocalConfig ( flattenedConfig ) ;
51
+ } , [ flattenedConfig ] ) ;
98
52
99
53
// Early returns
100
54
if ( ! configSchema ) {
101
55
return < EmptyState /> ;
102
56
}
103
57
104
- if ( ! existingConfig && ! configLoading ) {
58
+ if ( ! config && ! configLoading ) {
105
59
return < EmptyState /> ;
106
60
}
107
61
@@ -133,22 +87,15 @@ const ConfigEditor = ({ catalogItem, client }: { catalogItem: CatalogItemRichene
133
87
{ isSaving ? (
134
88
< CircularProgress size = { 24 } />
135
89
) : (
136
- < IconButton onClick = { ( ) => handleSaveConfig ( key ) } >
137
- < CheckOutlined sx = { { color : 'success.main' } } />
90
+ < IconButton onClick = { ( ) => setLocalConfig ( {
91
+ ...localConfig ,
92
+ [ key ] : flattenedConfig [ key ]
93
+ } ) }
94
+ disabled = { isSaving }
95
+ >
96
+ < CloseOutlined sx = { { color : 'error.main' } } />
138
97
</ IconButton >
139
98
) }
140
- < IconButton
141
- onClick = { ( ) => {
142
- // Reset this field to match the original config
143
- setLocalConfig ( {
144
- ...localConfig ,
145
- [ key ] : flattenedConfig [ key ]
146
- } ) ;
147
- } }
148
- disabled = { isSaving }
149
- >
150
- < CloseOutlined sx = { { color : 'error.main' } } />
151
- </ IconButton >
152
99
</ Stack > }
153
100
</ Stack >
154
101
)
0 commit comments