@@ -4,12 +4,10 @@ import { useEffect, useState } from "react";
44import { CatalogItemWithName } from "./tile/Tile" ;
55import Secrets from "../Secrets" ;
66import { 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" ;
108import { useCatalogContext } from "../context/CatalogContext" ;
9+ import { useConfigContext } from "../context/ConfigContext" ;
1110import { DeepObject , mergeDeep } from "../MergeDeep" ;
12- import { githubLightTheme , NodeData , githubDarkTheme , JsonEditor } from "json-edit-react" ;
1311
1412// Styles for the tab panel
1513interface TabPanelProps {
@@ -142,7 +140,8 @@ const ConfigurationModal = ({
142140 catalogItem,
143141 client,
144142} : ConfigurationModalProps ) => {
145- const { config, startPull, registryItems, tryUpdateSecrets, secrets } = useCatalogContext ( ) ;
143+ const { startPull, registryItems, tryUpdateSecrets, secrets } = useCatalogContext ( ) ;
144+ const { config, configLoading, saveConfig } = useConfigContext ( ) ;
146145 const theme = useTheme ( ) ;
147146
148147 // State for tabs
@@ -154,7 +153,6 @@ const ConfigurationModal = ({
154153 const [ secretLoading , setSecretLoading ] = useState ( false ) ;
155154
156155 // State for config
157- const [ configLoading , setConfigLoading ] = useState ( true ) ;
158156 const [ loadedConfig , setLoadedConfig ] = useState < { [ key : string ] : any } > ( { } ) ;
159157
160158 // Load assigned secrets
@@ -171,7 +169,6 @@ const ConfigurationModal = ({
171169 } catch ( error ) {
172170 console . error ( error ) ;
173171 }
174- setConfigLoading ( false ) ;
175172 } , [ catalogItem , config ] ) ;
176173
177174 // Handle tab change
@@ -181,33 +178,14 @@ const ConfigurationModal = ({
181178
182179 // Save config to YAML
183180 const saveConfigToYaml = async ( newConfig : { [ key : string ] : any } ) => {
184- if ( ! registryItems || ! config ) {
181+ if ( ! registryItems ) {
185182 return ;
186183 }
187184 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 ) ;
202186 await startPull ( ) ;
203- console . log ( 'Syncing complete' ) ;
204- client . desktopUI . toast . success ( 'Config saved successfully.' ) ;
205- setTimeout ( ( ) => {
206- setConfigLoading ( false ) ;
207- } , 500 ) ;
208187 } catch ( error ) {
209188 client . desktopUI . toast . error ( 'Failed to update config: ' + error ) ;
210- setConfigLoading ( false ) ;
211189 }
212190 } ;
213191
0 commit comments