@ -1,65 +1,67 @@
< script lang = "ts" setup >
/ / c o r e l i b s
import { compu ted , r ef } from "vue" ;
import { inje ct, r ef, type R ef } from "vue" ;
/ / h o o k s
import { useSettingForm } from "@/composables/use-setting-form" ;
import { useSettingForm Convert } from "@/composables/use-setting-form" ;
import { apiClient } from "@/utils/api-client" ;
/ / c o m p o n e n t s
import { VButton } from "@halo-dev/components" ;
/ / t y p e s
import type { Plugin } from "@halo-dev/api-client" ;
import type { ConfigMap, Plugin, Setting } from "@halo-dev/api-client" ;
import { useRouteParams } from "@vueuse/router" ;
import type { FormKitSchemaCondition , FormKitSchemaNode } from "@formkit/core" ;
const name = useRouteParams < string > ( "name" ) ;
const group = useRouteParams < string > ( "group" ) ;
const plugin = ref < Plugin | undefined > ( ) ;
const plugin = inject < Ref < Plugin | undefined > > ( "plugin" ) ;
const saving = ref ( false ) ;
const setting = ref < Setting > ( ) ;
const configMap = ref < ConfigMap > ( ) ;
const settingName = computed ( ( ) => plugin ? . value ? . spec . settingName ) ;
const configMapName = computed ( ( ) => plugin ? . value ? . spec . configMapName ) ;
const {
const { configMapFormData , formSchema , convertToSave } = useSettingFormConvert (
setting ,
configMapFormData ,
saving ,
handleFetchSettings ,
handleFetchConfigMap ,
handleSaveConfigMap ,
} = useSettingForm ( settingName , configMapName ) ;
configMap ,
group
) ;
const handleFetchSettings = async ( ) => {
if ( ! plugin ? . value ) return ;
const { data } = await apiClient . plugin . fetchPluginSetting ( {
name : plugin . value . metadata . name ,
} ) ;
setting . value = data ;
} ;
const handleFetchConfigMap = async ( ) => {
if ( ! plugin ? . value ) return ;
const { data } = await apiClient . plugin . fetchPluginConfig ( {
name : plugin . value . metadata . name ,
} ) ;
configMap . value = data ;
} ;
const formSchema = computed ( ( ) => {
if ( ! setting . value ) {
const handleSaveConfigMap = async ( ) => {
saving . value = true ;
const configMapToUpdate = convertToSave ( ) ;
if ( ! configMapToUpdate || ! plugin ? . value ) {
saving . value = false ;
return ;
}
const { forms } = setting . value . spec ;
return forms . find ( ( item ) => item . group === group . value ) ? . formSchema as (
| FormKitSchemaCondition
| FormKitSchemaNode
) [ ] ;
} ) ;
const handleFetchPlugin = async ( ) => {
try {
const { data } =
await apiClient . extension . plugin . getpluginHaloRunV1alpha1Plugin ( {
name : name . value ,
const { data : newConfigMap } = await apiClient . plugin . updatePluginConfig ( {
name : plugin . value . metadata . name ,
configMap : configMapToUpdate ,
} ) ;
plugin . value = data ;
if ( settingName . value && configMapName . value ) {
await handleFetchSettings ( ) ;
await handleFetchConfigMap ( ) ;
}
} catch ( e ) {
console . error ( "Failed to fetch plugin and settings" , e ) ;
}
configMap . value = newConfigMap ;
saving . value = false ;
} ;
await handleFetchPlugin ( ) ;
await handleFetchSettings ( ) ;
await handleFetchConfigMap ( ) ;
< / script >
< template >
< Transition mode = "out-in" name = "fade" >
@ -81,7 +83,7 @@ await handleFetchPlugin();
/ >
< / FormKit >
< / div >
< div v-permission ="['system: configmap s:manage']" class="pt-5">
< div v-permission ="['system: plugin s:manage']" class="pt-5">
< div class = "flex justify-start" >
< VButton
: loading = "saving"