2022-07-21 06:16:51 +00:00
|
|
|
<script lang="ts" setup>
|
2022-08-04 04:04:42 +00:00
|
|
|
// core libs
|
2023-03-29 13:26:13 +00:00
|
|
|
import { inject, ref, type Ref, computed } from "vue";
|
2022-08-04 04:04:42 +00:00
|
|
|
|
|
|
|
// hooks
|
2023-11-09 06:56:06 +00:00
|
|
|
import { useSettingFormConvert } from "@console/composables/use-setting-form";
|
2024-06-25 04:31:44 +00:00
|
|
|
import { consoleApiClient } from "@halo-dev/api-client";
|
2022-08-04 04:04:42 +00:00
|
|
|
|
|
|
|
// components
|
2023-02-28 14:36:28 +00:00
|
|
|
import { Toast, VButton } from "@halo-dev/components";
|
2022-08-04 04:04:42 +00:00
|
|
|
|
|
|
|
// types
|
2023-01-30 06:38:12 +00:00
|
|
|
import type { ConfigMap, Plugin, Setting } from "@halo-dev/api-client";
|
2023-03-23 08:54:33 +00:00
|
|
|
import { useI18n } from "vue-i18n";
|
2023-03-29 13:26:13 +00:00
|
|
|
import { useQuery, useQueryClient } from "@tanstack/vue-query";
|
2023-04-03 03:48:13 +00:00
|
|
|
import { toRaw } from "vue";
|
2023-11-27 09:38:08 +00:00
|
|
|
import StickyBlock from "@/components/sticky-block/StickyBlock.vue";
|
2023-03-23 08:54:33 +00:00
|
|
|
|
|
|
|
const { t } = useI18n();
|
2023-03-29 13:26:13 +00:00
|
|
|
const queryClient = useQueryClient();
|
2022-07-21 06:16:51 +00:00
|
|
|
|
2023-07-16 15:34:17 +00:00
|
|
|
const group = inject<Ref<string>>("activeTab", ref("basic"));
|
2023-01-30 06:38:12 +00:00
|
|
|
const plugin = inject<Ref<Plugin | undefined>>("plugin");
|
2023-03-29 13:26:13 +00:00
|
|
|
const setting = inject<Ref<Setting | undefined>>("setting", ref());
|
2023-01-30 06:38:12 +00:00
|
|
|
const saving = ref(false);
|
2023-03-29 13:26:13 +00:00
|
|
|
|
2023-07-07 04:38:11 +00:00
|
|
|
const { data: configMap } = useQuery<ConfigMap>({
|
2023-03-29 13:26:13 +00:00
|
|
|
queryKey: ["plugin-configMap", plugin],
|
|
|
|
queryFn: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } = await consoleApiClient.plugin.plugin.fetchPluginConfig({
|
2023-03-29 13:26:13 +00:00
|
|
|
name: plugin?.value?.metadata.name as string,
|
|
|
|
});
|
|
|
|
return data;
|
|
|
|
},
|
|
|
|
enabled: computed(() => {
|
|
|
|
return !!setting.value && !!plugin?.value;
|
|
|
|
}),
|
|
|
|
});
|
2022-09-10 09:23:51 +00:00
|
|
|
|
2023-01-30 06:38:12 +00:00
|
|
|
const { configMapFormData, formSchema, convertToSave } = useSettingFormConvert(
|
2022-09-22 08:26:13 +00:00
|
|
|
setting,
|
2023-01-30 06:38:12 +00:00
|
|
|
configMap,
|
|
|
|
group
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleSaveConfigMap = async () => {
|
|
|
|
saving.value = true;
|
|
|
|
const configMapToUpdate = convertToSave();
|
|
|
|
if (!configMapToUpdate || !plugin?.value) {
|
|
|
|
saving.value = false;
|
2022-07-21 06:16:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-25 04:31:44 +00:00
|
|
|
await consoleApiClient.plugin.plugin.updatePluginConfig({
|
2023-01-30 06:38:12 +00:00
|
|
|
name: plugin.value.metadata.name,
|
|
|
|
configMap: configMapToUpdate,
|
|
|
|
});
|
2022-09-10 09:23:51 +00:00
|
|
|
|
2023-03-23 08:54:33 +00:00
|
|
|
Toast.success(t("core.common.toast.save_success"));
|
2023-02-28 14:36:28 +00:00
|
|
|
|
2023-03-29 13:26:13 +00:00
|
|
|
queryClient.invalidateQueries({ queryKey: ["plugin-configMap"] });
|
|
|
|
|
2023-01-30 06:38:12 +00:00
|
|
|
saving.value = false;
|
2022-09-10 09:23:51 +00:00
|
|
|
};
|
2022-07-21 06:16:51 +00:00
|
|
|
</script>
|
|
|
|
<template>
|
2022-12-07 04:26:54 +00:00
|
|
|
<Transition mode="out-in" name="fade">
|
2023-11-27 09:04:08 +00:00
|
|
|
<div class="rounded-b-base bg-white p-4">
|
2022-11-24 03:46:10 +00:00
|
|
|
<div>
|
|
|
|
<FormKit
|
2023-03-29 13:26:13 +00:00
|
|
|
v-if="group && formSchema && configMapFormData?.[group]"
|
2022-11-24 03:46:10 +00:00
|
|
|
:id="group"
|
|
|
|
v-model="configMapFormData[group]"
|
|
|
|
:name="group"
|
|
|
|
:actions="false"
|
|
|
|
:preserve="true"
|
|
|
|
type="form"
|
|
|
|
@submit="handleSaveConfigMap"
|
2022-07-21 06:16:51 +00:00
|
|
|
>
|
2022-11-24 03:46:10 +00:00
|
|
|
<FormKitSchema
|
2023-04-03 03:48:13 +00:00
|
|
|
:schema="toRaw(formSchema)"
|
2022-11-24 03:46:10 +00:00
|
|
|
:data="configMapFormData[group]"
|
|
|
|
/>
|
|
|
|
</FormKit>
|
|
|
|
</div>
|
2023-11-27 09:38:08 +00:00
|
|
|
|
|
|
|
<StickyBlock
|
|
|
|
v-permission="['system:plugins:manage']"
|
|
|
|
class="-mx-4 -mb-4 rounded-b-base rounded-t-lg bg-white p-4 pt-5"
|
|
|
|
position="bottom"
|
|
|
|
>
|
|
|
|
<VButton
|
|
|
|
:loading="saving"
|
|
|
|
type="secondary"
|
|
|
|
@click="$formkit.submit(group || '')"
|
|
|
|
>
|
|
|
|
{{ $t("core.common.buttons.save") }}
|
|
|
|
</VButton>
|
|
|
|
</StickyBlock>
|
2022-07-21 06:16:51 +00:00
|
|
|
</div>
|
2022-11-24 03:46:10 +00:00
|
|
|
</Transition>
|
2022-07-21 06:16:51 +00:00
|
|
|
</template>
|