Refactor attachment policy form (#7790)

#### What type of PR is this?

/area ui
/milestone 2.22.x

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

Refactored AttachmentPolicyEditingModal.vue to group policy config fields under a 'config' group and improved the update logic to use JSON patch for displayName

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

```release-note
None
```
pull/7792/head
Ryan Wang 2025-10-03 11:42:26 +08:00 committed by GitHub
parent 41005f2c0e
commit 838b97b812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 18 deletions

View File

@ -112,9 +112,8 @@ const isSubmitting = ref(false);
const handleSave = async (data: { const handleSave = async (data: {
displayName: string; displayName: string;
[key: string]: unknown; config: Record<string, unknown>;
}) => { }) => {
console.log(data);
try { try {
isSubmitting.value = true; isSubmitting.value = true;
if (isUpdateMode.value) { if (isUpdateMode.value) {
@ -125,18 +124,18 @@ const handleSave = async (data: {
await consoleApiClient.storage.policy.updatePolicyConfigByGroup({ await consoleApiClient.storage.policy.updatePolicyConfigByGroup({
name: policy.value.metadata.name, name: policy.value.metadata.name,
group: CONFIG_MAP_GROUP, group: CONFIG_MAP_GROUP,
body: data, body: data.config,
}); });
await coreApiClient.storage.policy.updatePolicy({ await coreApiClient.storage.policy.patchPolicy({
name: policy.value.metadata.name, name: policy.value.metadata.name,
policy: { jsonPatchInner: [
...policy.value, {
spec: { op: "add",
...policy.value.spec, path: "/spec/displayName",
displayName: data.displayName, value: data.displayName,
}, },
}, ],
}); });
} else { } else {
const { data: policies } = const { data: policies } =
@ -157,7 +156,7 @@ const handleSave = async (data: {
await coreApiClient.configMap.createConfigMap({ await coreApiClient.configMap.createConfigMap({
configMap: { configMap: {
data: { data: {
[CONFIG_MAP_GROUP]: JSON.stringify(data), [CONFIG_MAP_GROUP]: JSON.stringify(data.config || {}),
}, },
apiVersion: "v1alpha1", apiVersion: "v1alpha1",
kind: "ConfigMap", kind: "ConfigMap",
@ -207,16 +206,14 @@ const modalTitle = props.policy
ref="modal" ref="modal"
mount-to-body mount-to-body
:title="modalTitle" :title="modalTitle"
:width="600" :width="650"
@close="emit('close')" @close="emit('close')"
> >
<div> <div>
<VLoading v-if="isLoading" /> <VLoading v-if="isLoading" />
<template v-else> <template v-else>
<FormKit <FormKit
v-if="formSchema && configMapGroupData"
id="attachment-policy-form" id="attachment-policy-form"
:value="toRaw(configMapGroupData) || {}"
name="attachment-policy-form" name="attachment-policy-form"
:preserve="true" :preserve="true"
type="form" type="form"
@ -235,10 +232,20 @@ const modalTitle = props.policy
name="displayName" name="displayName"
validation="required|length:0,50" validation="required|length:0,50"
></FormKit> ></FormKit>
<FormKitSchema <FormKit
:schema="toRaw(formSchema)" v-if="formSchema && configMapGroupData"
:data="toRaw(configMapGroupData) || {}" :value="toRaw(configMapGroupData) || {}"
/> type="group"
name="config"
:label="
$t('core.attachment.policy_editing_modal.fields.config.label')
"
>
<FormKitSchema
:schema="toRaw(formSchema)"
:data="toRaw(configMapGroupData) || {}"
/>
</FormKit>
</FormKit> </FormKit>
</template> </template>
</div> </div>

View File

@ -234,6 +234,9 @@ core:
toast: toast:
group_name_exists: Group name already exists group_name_exists: Group name already exists
policy_editing_modal: policy_editing_modal:
fields:
config:
label: Policy configuration
toast: toast:
policy_name_exists: Storage policy name already exists policy_name_exists: Storage policy name already exists
upload_modal: upload_modal:

View File

@ -750,6 +750,8 @@ core:
fields: fields:
display_name: display_name:
label: Display name label: Display name
config:
label: Policy configuration
toast: toast:
policy_name_exists: Storage policy name already exists policy_name_exists: Storage policy name already exists
upload_modal: upload_modal:

View File

@ -704,6 +704,8 @@ core:
fields: fields:
display_name: display_name:
label: 名称 label: 名称
config:
label: 策略配置
toast: toast:
policy_name_exists: 存储策略名称已存在 policy_name_exists: 存储策略名称已存在
upload_modal: upload_modal:

View File

@ -689,6 +689,8 @@ core:
fields: fields:
display_name: display_name:
label: 名稱 label: 名稱
config:
label: 策略配置
toast: toast:
policy_name_exists: 儲存策略名稱已存在 policy_name_exists: 儲存策略名稱已存在
upload_modal: upload_modal: