From d3d28dd3daa7c70a28f03550a004ecf3fcb3ade7 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 4 Nov 2022 16:30:10 +0800 Subject: [PATCH] perf: optimize the creation of attachment storage policies (#681) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement /milestone 2.0 #### What this PR does / why we need it: 优化首次上传附件时,创建存储策略的流程,现在可以直接打开新建策略的表单。 #### Screenshots: before: image after: image #### Special notes for your reviewer: /cc @halo-dev/sig-halo-console 测试方式: 1. 测试在上传弹窗中新建存储策略。 #### Does this PR introduce a user-facing change? ```release-note 优化首次上传附件时,创建存储策略的流程。 ``` --- .../components/src/components/alert/Alert.vue | 4 +- .../components/AttachmentPoliciesModal.vue | 29 ++-- .../AttachmentPolicyEditingModal.vue | 4 +- .../components/AttachmentSelectorModal.vue | 15 +- .../components/AttachmentUploadModal.vue | 128 ++++++++++++------ .../CoreSelectorProvider.vue | 3 +- .../composables/use-attachment-policy.ts | 40 +++++- 7 files changed, 154 insertions(+), 69 deletions(-) diff --git a/packages/components/src/components/alert/Alert.vue b/packages/components/src/components/alert/Alert.vue index 06efd9e2..49b80f35 100644 --- a/packages/components/src/components/alert/Alert.vue +++ b/packages/components/src/components/alert/Alert.vue @@ -95,7 +95,7 @@ const handleClose = () => { mr-3 flex-1 font-medium - text-base; + text-sm; } .alert-close { @@ -113,7 +113,7 @@ const handleClose = () => { } .alert-description { - @apply text-sm + @apply text-xs mt-2; } diff --git a/src/modules/contents/attachments/components/AttachmentPoliciesModal.vue b/src/modules/contents/attachments/components/AttachmentPoliciesModal.vue index 4ac5d8b3..e71a7109 100644 --- a/src/modules/contents/attachments/components/AttachmentPoliciesModal.vue +++ b/src/modules/contents/attachments/components/AttachmentPoliciesModal.vue @@ -10,10 +10,12 @@ import { import AttachmentPolicyEditingModal from "./AttachmentPolicyEditingModal.vue"; import { ref, watch } from "vue"; import type { Policy, PolicyTemplate } from "@halo-dev/api-client"; -import { apiClient } from "@/utils/api-client"; import { v4 as uuid } from "uuid"; import { formatDatetime } from "@/utils/date"; -import { useFetchAttachmentPolicy } from "../composables/use-attachment-policy"; +import { + useFetchAttachmentPolicy, + useFetchAttachmentPolicyTemplate, +} from "../composables/use-attachment-policy"; const props = withDefaults( defineProps<{ @@ -30,22 +32,15 @@ const emit = defineEmits<{ }>(); const { policies, loading, handleFetchPolicies } = useFetchAttachmentPolicy(); +const { policyTemplates, handleFetchPolicyTemplates } = + useFetchAttachmentPolicyTemplate({ + fetchOnMounted: false, + }); -const selectedPolicy = ref(null); -const policyTemplates = ref([] as PolicyTemplate[]); +const selectedPolicy = ref(); const policyEditingModal = ref(false); -const handleFetchPolicyTemplates = async () => { - try { - const { data } = - await apiClient.extension.storage.policyTemplate.liststorageHaloRunV1alpha1PolicyTemplate(); - policyTemplates.value = data.items; - } catch (e) { - console.error("Failed to fetch attachment policy templates", e); - } -}; - function onVisibleChange(visible: boolean) { emit("update:visible", visible); if (!visible) { @@ -79,14 +74,14 @@ const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => { }; const onEditingModalClose = () => { - selectedPolicy.value = null; + selectedPolicy.value = undefined; handleFetchPolicies(); }; watch( () => props.visible, - (newValue) => { - if (newValue) { + (visible) => { + if (visible) { handleFetchPolicyTemplates(); handleFetchPolicies(); } diff --git a/src/modules/contents/attachments/components/AttachmentPolicyEditingModal.vue b/src/modules/contents/attachments/components/AttachmentPolicyEditingModal.vue index 408bd817..82b090f9 100644 --- a/src/modules/contents/attachments/components/AttachmentPolicyEditingModal.vue +++ b/src/modules/contents/attachments/components/AttachmentPolicyEditingModal.vue @@ -17,11 +17,11 @@ import { setFocus } from "@/formkit/utils/focus"; const props = withDefaults( defineProps<{ visible: boolean; - policy: Policy | null; + policy?: Policy; }>(), { visible: false, - policy: null, + policy: undefined, } ); diff --git a/src/modules/contents/attachments/components/AttachmentSelectorModal.vue b/src/modules/contents/attachments/components/AttachmentSelectorModal.vue index ad82477b..5ffa6086 100644 --- a/src/modules/contents/attachments/components/AttachmentSelectorModal.vue +++ b/src/modules/contents/attachments/components/AttachmentSelectorModal.vue @@ -52,6 +52,18 @@ const onVisibleChange = (visible: boolean) => { } }; +const onChangeProvider = (providerId: string) => { + const provider = attachmentSelectorPublicState.value.providers.find( + (provider) => provider.id === providerId + ); + + if (!provider) { + return; + } + + activeId.value = providerId; +}; + const handleConfirm = () => { emit("select", Array.from(selected.value)); onVisibleChange(false); @@ -69,7 +81,7 @@ const handleConfirm = () => { @@ -83,6 +95,7 @@ const handleConfirm = () => { :is="provider.component" v-if="activeId === provider.id" v-model:selected="selected" + @change-provider="onChangeProvider" > diff --git a/src/modules/contents/attachments/components/AttachmentUploadModal.vue b/src/modules/contents/attachments/components/AttachmentUploadModal.vue index eb540665..546f0963 100644 --- a/src/modules/contents/attachments/components/AttachmentUploadModal.vue +++ b/src/modules/contents/attachments/components/AttachmentUploadModal.vue @@ -1,16 +1,14 @@