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/utils": "^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/console-shared": "workspace:*",
"@halo-dev/richtext-editor": "^0.0.0-alpha.16",

View File

@ -12,7 +12,7 @@ importers:
'@formkit/themes': ^1.0.0-beta.12
'@formkit/utils': ^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/console-shared': workspace:*
'@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/utils': 1.0.0-beta.12-e579559
'@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/console-shared': link:packages/shared
'@halo-dev/richtext-editor': 0.0.0-alpha.16_vue@3.2.45
@ -1962,8 +1962,8 @@ packages:
- windicss
dev: false
/@halo-dev/api-client/0.0.55:
resolution: {integrity: sha512-n/XjFhCgUYYo3mrVsuCa11iyXkbBgcRGIT8fDfdkuLjzfXamxt0eJMFbz8lpH85pTh7O7xTQzCxvi5YIi7zBLw==}
/@halo-dev/api-client/0.0.56:
resolution: {integrity: sha512-Htwyk+pFNVGRrOLcabyNTPc5RQS/RwdUizrGWxRErBCXj4NIQyMYv3owcNS1lOMtsKXyfG1NX/cJKIw3g9y1WQ==}
dev: false
/@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 {
const promises = Array.from(selectedAttachments.value).map((attachment) => {
const attachmentToUpdate = cloneDeep(attachment);
attachmentToUpdate.spec.groupRef = {
name: group.metadata.name,
};
attachmentToUpdate.spec.groupName = group.metadata.name;
return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment(
{
name: attachment.metadata.name,
@ -727,9 +725,7 @@ onMounted(() => {
</template>
<template #end>
<VEntityField
:description="
getPolicyName(attachment.spec.policyRef?.name)
"
:description="getPolicyName(attachment.spec.policyName)"
/>
<VEntityField>
<template #description>
@ -737,12 +733,12 @@ onMounted(() => {
:to="{
name: 'UserDetail',
params: {
name: attachment.spec.uploadedBy?.name,
name: attachment.spec.ownerName,
},
}"
class="text-xs text-gray-500"
>
{{ attachment.spec.uploadedBy?.name }}
{{ attachment.spec.ownerName }}
</RouterLink>
</template>
</VEntityField>

View File

@ -34,13 +34,13 @@ const onlyPreview = ref(false);
watchEffect(async () => {
if (props.attachment) {
const { policyRef } = props.attachment.spec;
if (!policyRef) {
const { policyName } = props.attachment.spec;
if (!policyName) {
return;
}
const { data } =
await apiClient.extension.storage.policy.getstorageHaloRunV1alpha1Policy({
name: policyRef.name,
name: policyName,
});
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">
<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">
{{ getGroupName(attachment?.spec.groupRef?.name) || "未分组" }}
{{ getGroupName(attachment?.spec.groupName) || "未分组" }}
</dd>
</div>
<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">
<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">
{{ attachment?.spec.uploadedBy?.name }}
{{ attachment?.spec.ownerName }}
</dd>
</div>
<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
const moveToUnGroupRequests = data.items.map((attachment) => {
attachment.spec.groupRef = undefined;
attachment.spec.groupName = undefined;
return apiClient.extension.storage.attachment.updatestorageHaloRunV1alpha1Attachment(
{
name: attachment.metadata.name,

View File

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

View File

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

View File

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