@@ -4,12 +4,10 @@ import { useEffect, useState } from "react";
4
4
import { CatalogItemWithName } from "./tile/Tile" ;
5
5
import Secrets from "../Secrets" ;
6
6
import { v1 } from "@docker/extension-api-client-types" ;
7
- import { getStoredConfig , syncRegistryWithConfig } from "../Registry" ;
8
- import { stringify } from "yaml" ;
9
- import { escapeJSONForPlatformShell , tryRunImageSync } from "../FileWatcher" ;
7
+ import { githubLightTheme , NodeData , githubDarkTheme , JsonEditor } from "json-edit-react" ;
10
8
import { useCatalogContext } from "../context/CatalogContext" ;
9
+ import { useConfigContext } from "../context/ConfigContext" ;
11
10
import { DeepObject , mergeDeep } from "../MergeDeep" ;
12
- import { githubLightTheme , NodeData , githubDarkTheme , JsonEditor } from "json-edit-react" ;
13
11
14
12
// Styles for the tab panel
15
13
interface TabPanelProps {
@@ -142,7 +140,8 @@ const ConfigurationModal = ({
142
140
catalogItem,
143
141
client,
144
142
} : ConfigurationModalProps ) => {
145
- const { config, startPull, registryItems, tryUpdateSecrets, secrets } = useCatalogContext ( ) ;
143
+ const { startPull, registryItems, tryUpdateSecrets, secrets } = useCatalogContext ( ) ;
144
+ const { config, configLoading, saveConfig } = useConfigContext ( ) ;
146
145
const theme = useTheme ( ) ;
147
146
148
147
// State for tabs
@@ -154,7 +153,6 @@ const ConfigurationModal = ({
154
153
const [ secretLoading , setSecretLoading ] = useState ( false ) ;
155
154
156
155
// State for config
157
- const [ configLoading , setConfigLoading ] = useState ( true ) ;
158
156
const [ loadedConfig , setLoadedConfig ] = useState < { [ key : string ] : any } > ( { } ) ;
159
157
160
158
// Load assigned secrets
@@ -171,7 +169,6 @@ const ConfigurationModal = ({
171
169
} catch ( error ) {
172
170
console . error ( error ) ;
173
171
}
174
- setConfigLoading ( false ) ;
175
172
} , [ catalogItem , config ] ) ;
176
173
177
174
// Handle tab change
@@ -181,33 +178,14 @@ const ConfigurationModal = ({
181
178
182
179
// Save config to YAML
183
180
const saveConfigToYaml = async ( newConfig : { [ key : string ] : any } ) => {
184
- if ( ! registryItems || ! config ) {
181
+ if ( ! registryItems ) {
185
182
return ;
186
183
}
187
184
try {
188
- setConfigLoading ( true ) ;
189
- const currentStoredConfig = config ;
190
- console . log ( 'currentStoredConfig' , currentStoredConfig ) ;
191
- currentStoredConfig [ catalogItem . name ] = newConfig ;
192
- console . log ( 'newConfig' , newConfig ) ;
193
- const payload = escapeJSONForPlatformShell ( {
194
- files : [ {
195
- path : 'config.yaml' ,
196
- content : stringify ( currentStoredConfig )
197
- } ]
198
- } , client . host . platform ) ;
199
- await tryRunImageSync ( client , [ '--rm' , '-v' , 'docker-prompts:/docker-prompts' , '--workdir' , '/docker-prompts' , 'vonwig/function_write_files:latest' , payload ] ) ;
200
- console . log ( 'Config saved successfully, syncing' ) ;
201
- await syncRegistryWithConfig ( client , registryItems , currentStoredConfig ) ;
185
+ await saveConfig ( catalogItem . name , newConfig ) ;
202
186
await startPull ( ) ;
203
- console . log ( 'Syncing complete' ) ;
204
- client . desktopUI . toast . success ( 'Config saved successfully.' ) ;
205
- setTimeout ( ( ) => {
206
- setConfigLoading ( false ) ;
207
- } , 500 ) ;
208
187
} catch ( error ) {
209
188
client . desktopUI . toast . error ( 'Failed to update config: ' + error ) ;
210
- setConfigLoading ( false ) ;
211
189
}
212
190
} ;
213
191
0 commit comments