refactor: simplify references in Attachment (#729)

#### What type of PR is this?

/kind improvement
/milestone 2.0

#### What this PR does / why we need it:

重构附件、存储策略、附件分组之间的关联方式。适配:https://github.com/halo-dev/halo/pull/2800

#### Special notes for your reviewer:

测试方式:

1. Halo 需要切换到 https://github.com/halo-dev/halo/pull/2800 分支。
2. Console 需要 `pnpm install`
3. 测试附件相关功能。

#### Does this PR introduce a user-facing change?

```release-note
None
```
pull/730/head^2
Ryan Wang 2022-11-30 10:23:46 +08:00 committed by GitHub
parent e7ed52b596
commit ed5b3c1496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 51 deletions

View File

@ -32,7 +32,7 @@
"@formkit/themes": "^1.0.0-beta.12", "@formkit/themes": "^1.0.0-beta.12",
"@formkit/utils": "^1.0.0-beta.12", "@formkit/utils": "^1.0.0-beta.12",
"@formkit/vue": "^1.0.0-beta.12", "@formkit/vue": "^1.0.0-beta.12",
"@halo-dev/api-client": "^0.0.55", "@halo-dev/api-client": "^0.0.56",
"@halo-dev/components": "workspace:*", "@halo-dev/components": "workspace:*",
"@halo-dev/console-shared": "workspace:*", "@halo-dev/console-shared": "workspace:*",
"@halo-dev/richtext-editor": "^0.0.0-alpha.16", "@halo-dev/richtext-editor": "^0.0.0-alpha.16",

View File

@ -12,7 +12,7 @@ importers:
'@formkit/themes': ^1.0.0-beta.12 '@formkit/themes': ^1.0.0-beta.12
'@formkit/utils': ^1.0.0-beta.12 '@formkit/utils': ^1.0.0-beta.12
'@formkit/vue': ^1.0.0-beta.12 '@formkit/vue': ^1.0.0-beta.12
'@halo-dev/api-client': ^0.0.55 '@halo-dev/api-client': ^0.0.56
'@halo-dev/components': workspace:* '@halo-dev/components': workspace:*
'@halo-dev/console-shared': workspace:* '@halo-dev/console-shared': workspace:*
'@halo-dev/richtext-editor': ^0.0.0-alpha.16 '@halo-dev/richtext-editor': ^0.0.0-alpha.16
@ -104,7 +104,7 @@ importers:
'@formkit/themes': 1.0.0-beta.12-e579559_tailwindcss@3.2.4 '@formkit/themes': 1.0.0-beta.12-e579559_tailwindcss@3.2.4
'@formkit/utils': 1.0.0-beta.12-e579559 '@formkit/utils': 1.0.0-beta.12-e579559
'@formkit/vue': 1.0.0-beta.12-e579559_ior6jr3fpijijuwpr34w2i25va '@formkit/vue': 1.0.0-beta.12-e579559_ior6jr3fpijijuwpr34w2i25va
'@halo-dev/api-client': 0.0.55 '@halo-dev/api-client': 0.0.56
'@halo-dev/components': link:packages/components '@halo-dev/components': link:packages/components
'@halo-dev/console-shared': link:packages/shared '@halo-dev/console-shared': link:packages/shared
'@halo-dev/richtext-editor': 0.0.0-alpha.16_vue@3.2.45 '@halo-dev/richtext-editor': 0.0.0-alpha.16_vue@3.2.45
@ -1962,8 +1962,8 @@ packages:
- windicss - windicss
dev: false dev: false
/@halo-dev/api-client/0.0.55: /@halo-dev/api-client/0.0.56:
resolution: {integrity: sha512-n/XjFhCgUYYo3mrVsuCa11iyXkbBgcRGIT8fDfdkuLjzfXamxt0eJMFbz8lpH85pTh7O7xTQzCxvi5YIi7zBLw==} resolution: {integrity: sha512-Htwyk+pFNVGRrOLcabyNTPc5RQS/RwdUizrGWxRErBCXj4NIQyMYv3owcNS1lOMtsKXyfG1NX/cJKIw3g9y1WQ==}
dev: false dev: false
/@halo-dev/richtext-editor/0.0.0-alpha.16_vue@3.2.45: /@halo-dev/richtext-editor/0.0.0-alpha.16_vue@3.2.45:

View File

@ -164,9 +164,7 @@ const handleMove = async (group: Group) => {
try { try {
const promises = Array.from(selectedAttachments.value).map((attachment) => { const promises = Array.from(selectedAttachments.value).map((attachment) => {
const attachmentToUpdate = cloneDeep(attachment); const attachmentToUpdate = cloneDeep(attachment);
attachmentToUpdate.spec.groupRef = { attachmentToUpdate.spec.groupName = group.metadata.name;
name: group.metadata.name,
};
return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment( return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment(
{ {
name: attachment.metadata.name, name: attachment.metadata.name,
@ -727,9 +725,7 @@ onMounted(() => {
</template> </template>
<template #end> <template #end>
<VEntityField <VEntityField
:description=" :description="getPolicyName(attachment.spec.policyName)"
getPolicyName(attachment.spec.policyRef?.name)
"
/> />
<VEntityField> <VEntityField>
<template #description> <template #description>
@ -737,12 +733,12 @@ onMounted(() => {
:to="{ :to="{
name: 'UserDetail', name: 'UserDetail',
params: { params: {
name: attachment.spec.uploadedBy?.name, name: attachment.spec.ownerName,
}, },
}" }"
class="text-xs text-gray-500" class="text-xs text-gray-500"
> >
{{ attachment.spec.uploadedBy?.name }} {{ attachment.spec.ownerName }}
</RouterLink> </RouterLink>
</template> </template>
</VEntityField> </VEntityField>

View File

@ -34,13 +34,13 @@ const onlyPreview = ref(false);
watchEffect(async () => { watchEffect(async () => {
if (props.attachment) { if (props.attachment) {
const { policyRef } = props.attachment.spec; const { policyName } = props.attachment.spec;
if (!policyRef) { if (!policyName) {
return; return;
} }
const { data } = const { data } =
await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy({ await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy({
name: policyRef.name, name: policyName,
}); });
policy.value = data; policy.value = data;
} }
@ -129,7 +129,7 @@ const onVisibleChange = (visible: boolean) => {
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium text-gray-900">所在分组</dt> <dt class="text-sm font-medium text-gray-900">所在分组</dt>
<dd class="mt-1 text-sm text-gray-900 sm:col-span-2 sm:mt-0"> <dd class="mt-1 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
{{ getGroupName(attachment?.spec.groupRef?.name) || "未分组" }} {{ getGroupName(attachment?.spec.groupName) || "未分组" }}
</dd> </dd>
</div> </div>
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
@ -153,7 +153,7 @@ const onVisibleChange = (visible: boolean) => {
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium text-gray-900">上传者</dt> <dt class="text-sm font-medium text-gray-900">上传者</dt>
<dd class="mt-1 text-sm text-gray-900 sm:col-span-2 sm:mt-0"> <dd class="mt-1 text-sm text-gray-900 sm:col-span-2 sm:mt-0">
{{ attachment?.spec.uploadedBy?.name }} {{ attachment?.spec.ownerName }}
</dd> </dd>
</div> </div>
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6"> <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">

View File

@ -108,7 +108,7 @@ const handleDelete = (group: Group) => {
// move attachments to none group // move attachments to none group
const moveToUnGroupRequests = data.items.map((attachment) => { const moveToUnGroupRequests = data.items.map((attachment) => {
attachment.spec.groupRef = undefined; attachment.spec.groupName = undefined;
return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment( return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment(
{ {
name: attachment.metadata.name, name: attachment.metadata.name,

View File

@ -60,12 +60,8 @@ const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
selectedPolicy.value = { selectedPolicy.value = {
spec: { spec: {
displayName: "", displayName: "",
templateRef: { templateName: policyTemplate.metadata.name,
name: policyTemplate.metadata.name, configMapName: "",
},
configMapRef: {
name: "",
},
}, },
apiVersion: "storage.halo.run/v1alpha1", apiVersion: "storage.halo.run/v1alpha1",
kind: "Policy", kind: "Policy",
@ -195,7 +191,7 @@ watch(
<template #start> <template #start>
<VEntityField <VEntityField
:title="policy.spec.displayName" :title="policy.spec.displayName"
:description="policy.spec.templateRef?.name" :description="policy.spec.templateName"
></VEntityField> ></VEntityField>
</template> </template>
<template #end> <template #end>

View File

@ -32,12 +32,8 @@ const emit = defineEmits<{
const initialFormState: Policy = { const initialFormState: Policy = {
spec: { spec: {
displayName: "", displayName: "",
templateRef: { templateName: "",
name: "", configMapName: "",
},
configMapRef: {
name: "",
},
}, },
apiVersion: "storage.halo.run/v1alpha1", apiVersion: "storage.halo.run/v1alpha1",
kind: "Policy", kind: "Policy",
@ -50,18 +46,14 @@ const initialFormState: Policy = {
const formState = ref<Policy>(cloneDeep(initialFormState)); const formState = ref<Policy>(cloneDeep(initialFormState));
const policyTemplate = ref<PolicyTemplate | undefined>(); const policyTemplate = ref<PolicyTemplate | undefined>();
const settingName = computed( const settingName = computed(() => policyTemplate.value?.spec?.settingName);
() => policyTemplate.value?.spec?.settingRef?.name
);
const configMapName = computed({ const configMapName = computed({
get() { get() {
return formState.value.spec.configMapRef?.name; return formState.value.spec.configMapName;
}, },
set(value) { set(value) {
formState.value.spec.configMapRef = { formState.value.spec.configMapName = value;
name: value as string,
};
}, },
}); });
@ -128,9 +120,7 @@ const handleSave = async () => {
} }
); );
} else { } else {
formState.value.spec.configMapRef = { formState.value.spec.configMapName = configMap.value.metadata.name;
name: configMap.value.metadata.name,
};
await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy( await apiClient.extension.storage.policy.createstorageHaloRunV1alpha1Policy(
{ {
policy: formState.value, policy: formState.value,
@ -173,12 +163,14 @@ watch(
if (policy) { if (policy) {
formState.value = cloneDeep(policy); formState.value = cloneDeep(policy);
const { templateName } = formState.value.spec;
// Get policy template // Get policy template
if (formState.value.spec.templateRef?.name) { if (templateName) {
const { data } = const { data } =
await apiClient.extension.storage.policyTemplate.getstorageHaloRunV1alpha1PolicyTemplate( await apiClient.extension.storage.policyTemplate.getstorageHaloRunV1alpha1PolicyTemplate(
{ {
name: formState.value.spec.templateRef.name, name: templateName,
} }
); );
policyTemplate.value = data; policyTemplate.value = data;

View File

@ -63,12 +63,8 @@ const handleOpenCreateNewPolicyModal = (policyTemplate: PolicyTemplate) => {
policyToCreate.value = { policyToCreate.value = {
spec: { spec: {
displayName: "", displayName: "",
templateRef: { templateName: policyTemplate.metadata.name,
name: policyTemplate.metadata.name, configMapName: "",
},
configMapRef: {
name: "",
},
}, },
apiVersion: "storage.halo.run/v1alpha1", apiVersion: "storage.halo.run/v1alpha1",
kind: "Policy", kind: "Policy",
@ -137,7 +133,7 @@ watch(
{{ policy.spec.displayName }} {{ policy.spec.displayName }}
</span> </span>
<span class="text-xs"> <span class="text-xs">
{{ policy.spec.templateRef?.name }} {{ policy.spec.templateName }}
</span> </span>
</div> </div>
</div> </div>