diff --git a/ui/console-src/composables/use-setting-form.ts b/ui/console-src/composables/use-setting-form.ts index 9e5e4c9e2..837731597 100644 --- a/ui/console-src/composables/use-setting-form.ts +++ b/ui/console-src/composables/use-setting-form.ts @@ -2,185 +2,11 @@ // types import { computed, watch, type ComputedRef, type Ref } from "vue"; import { ref } from "vue"; -import { apiClient } from "@/utils/api-client"; // libs -import { cloneDeep, merge } from "lodash-es"; +import { cloneDeep } from "lodash-es"; import type { ConfigMap, Setting, SettingForm } from "@halo-dev/api-client"; import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core"; -import { Toast } from "@halo-dev/components"; -import { useI18n } from "vue-i18n"; - -const initialConfigMap: ConfigMap = { - apiVersion: "v1alpha1", - kind: "ConfigMap", - metadata: { - name: "", - }, - data: {}, -}; - -interface useSettingFormReturn { - setting: Ref; - configMap: Ref; - configMapFormData: Ref> | undefined>; - saving: Ref; - handleFetchSettings: () => void; - handleFetchConfigMap: () => void; - handleSaveConfigMap: () => void; - handleReset: () => void; -} - -export function useSettingForm( - settingName: Ref, - configMapName: Ref -): useSettingFormReturn { - const { t } = useI18n(); - - const setting = ref(); - const configMap = ref(cloneDeep(initialConfigMap)); - const configMapFormData = ref< - Record> | undefined - >(); - - const saving = ref(false); - - const handleFetchSettings = async () => { - if (!settingName.value) { - setting.value = undefined; - return; - } - try { - const { data } = await apiClient.extension.setting.getv1alpha1Setting({ - name: settingName.value, - }); - setting.value = data; - - // init configMapFormData - if (!configMapFormData.value) { - const { forms } = setting.value.spec; - const initialConfigMapFormData: Record< - string, - Record - > = {}; - forms.forEach((form) => { - initialConfigMapFormData[form.group] = {}; - const formSchema = form.formSchema as ( - | FormKitSchemaCondition - | FormKitSchemaNode - )[]; - formSchema.forEach((schema) => { - // @ts-ignore - if ("name" in schema && "$formkit" in schema) { - initialConfigMapFormData[form.group][schema.name] = - schema.value || undefined; - } - }); - }); - configMapFormData.value = cloneDeep(initialConfigMapFormData); - } - } catch (e) { - console.error("Failed to fetch setting", e); - } - }; - - const handleFetchConfigMap = async () => { - if (!configMapName.value) { - configMap.value = cloneDeep(initialConfigMap); - configMapFormData.value = undefined; - return; - } - try { - const response = await apiClient.extension.configMap.getv1alpha1ConfigMap( - { - name: configMapName.value, - }, - { - mute: true, - } - ); - - configMap.value = response.data; - - const { data } = configMap.value; - - if (data) { - // merge objects value - const { forms } = setting.value?.spec || {}; - - forms?.forEach((form) => { - if (!configMapFormData.value) { - return; - } - configMapFormData.value[form.group] = merge( - configMapFormData.value[form.group] || {}, - JSON.parse(data[form.group] || "{}") - ); - }); - } - } catch (e) { - console.error("Failed to fetch configMap", e); - } - }; - - const handleSaveConfigMap = async () => { - try { - saving.value = true; - - if (!configMap.value.metadata.name && configMapName.value) { - configMap.value.metadata.name = configMapName.value; - } - - setting.value?.spec.forms.forEach((item: SettingForm) => { - // @ts-ignore - configMap.value.data[item.group] = JSON.stringify( - configMapFormData?.value?.[item.group] - ); - }); - - if (!configMap.value.metadata.creationTimestamp) { - const { data } = - await apiClient.extension.configMap.createv1alpha1ConfigMap({ - configMap: configMap.value, - }); - - configMapName.value = data.metadata.name; - } else { - const { data } = - await apiClient.extension.configMap.updatev1alpha1ConfigMap({ - configMap: configMap.value, - name: configMap.value.metadata.name, - }); - configMapName.value = data.metadata.name; - } - - Toast.success(t("core.common.toast.save_success")); - } catch (e) { - console.error("Failed to save configMap", e); - } finally { - await handleFetchSettings(); - await handleFetchConfigMap(); - saving.value = false; - } - }; - - const handleReset = () => { - setting.value = undefined; - configMap.value = cloneDeep(initialConfigMap); - configMapFormData.value = undefined; - }; - - return { - setting, - configMap, - configMapFormData, - saving, - handleFetchSettings, - handleFetchConfigMap, - handleSaveConfigMap, - handleReset, - }; -} interface useSettingFormConvertReturn { formSchema: ComputedRef< diff --git a/ui/console-src/modules/contents/attachments/AttachmentList.vue b/ui/console-src/modules/contents/attachments/AttachmentList.vue index a12f6cb28..460ecfeed 100644 --- a/ui/console-src/modules/contents/attachments/AttachmentList.vue +++ b/ui/console-src/modules/contents/attachments/AttachmentList.vue @@ -4,28 +4,29 @@ import { IconArrowRight, IconCheckboxFill, IconDatabase2Line, + IconFolder, IconGrid, IconList, - IconUpload, IconRefreshLine, + IconUpload, + Toast, VButton, VCard, + VDropdown, + VDropdownItem, + VEmpty, + VLoading, VPageHeader, VPagination, VSpace, - VEmpty, - IconFolder, - VLoading, - Toast, - VDropdown, - VDropdownItem, } from "@halo-dev/components"; import LazyImage from "@/components/image/LazyImage.vue"; import AttachmentDetailModal from "./components/AttachmentDetailModal.vue"; import AttachmentUploadModal from "./components/AttachmentUploadModal.vue"; import AttachmentPoliciesModal from "./components/AttachmentPoliciesModal.vue"; import AttachmentGroupList from "./components/AttachmentGroupList.vue"; -import { computed, onMounted, ref, watch } from "vue"; +import type { Ref } from "vue"; +import { computed, onMounted, provide, ref, watch } from "vue"; import type { Attachment, Group } from "@halo-dev/api-client"; import { useFetchAttachmentPolicy } from "./composables/use-attachment-policy"; import { useAttachmentControl } from "./composables/use-attachment"; @@ -37,8 +38,6 @@ import { useFetchAttachmentGroup } from "./composables/use-attachment-group"; import { useI18n } from "vue-i18n"; import { useLocalStorage } from "@vueuse/core"; import UserFilterDropdown from "@/components/filter/UserFilterDropdown.vue"; -import { provide } from "vue"; -import type { Ref } from "vue"; import AttachmentListItem from "./components/AttachmentListItem.vue"; const { t } = useI18n(); @@ -50,7 +49,7 @@ const detailVisible = ref(false); const { policies } = useFetchAttachmentPolicy(); const { groups, handleFetchGroups } = useFetchAttachmentGroup(); -const selectedGroup = ref(); +const selectedGroup = useRouteQuery("group"); // Filter const keyword = useRouteQuery("keyword", ""); @@ -111,12 +110,8 @@ const { isChecked, handleReset, } = useAttachmentControl({ - group: selectedGroup, - policy: computed(() => { - return policies.value?.find( - (policy) => policy.metadata.name === selectedPolicy.value - ); - }), + groupName: selectedGroup, + policyName: selectedPolicy, user: selectedUser, accepts: computed(() => { if (!selectedAccepts.value) { @@ -187,6 +182,7 @@ const onDetailModalClose = () => { const onUploadModalClose = () => { routeQueryAction.value = undefined; handleFetchAttachments(); + uploadVisible.value = false; }; // View type @@ -258,11 +254,11 @@ onMounted(() => { - + -