Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add name existence check before creating attachment group and storage policy #6959

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ const modalTitle = props.group
const handleSave = async () => {
try {
isSubmitting.value = true;
const existingGroupsResponse =
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
await coreApiClient.storage.group.listGroup();
const existingGroups = existingGroupsResponse.data.items || [];
const nameExists = existingGroups.some(
(group) => group.spec.displayName === formState.value.spec.displayName
);

if (nameExists) {
alert("该分组名称已存在,请重新创建!");
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (props.group) {
await coreApiClient.storage.group.updateGroup({
name: formState.value.metadata.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ const formState = ref<Policy>({

const isUpdateMode = !!props.policy;

const { data: policies } = useQuery({
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
queryKey: ["core:attachment:policies"],
queryFn: async () => {
const { data } = await coreApiClient.storage.policy.listPolicy(); // 修改为 listPolicy
return data;
},
});

onMounted(async () => {
if (props.policy) {
formState.value = cloneDeep(props.policy);
Expand Down Expand Up @@ -135,6 +143,14 @@ const submitting = ref(false);
const handleSave = async () => {
try {
submitting.value = true;
const nameExists = policies.value?.items.some(
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
(policy) => policy.spec.displayName === formState.value.spec.displayName
);

if (nameExists) {
alert("该存储策略名称已存在,请重新创建!");
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const configMapToUpdate = convertToSave();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ const onGroupEditingModalClose = async () => {
@click="selectedGroupName = group.metadata.name"
/>

<AttachmentGroupBadge @click="handleOpenCreateNewGroupModal">
<AttachmentPolicyBadge @click="handleOpenCreateNewGroupModal">
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
<template #text>
<span>{{ $t("core.common.buttons.new") }}</span>
</template>
<template #actions>
<IconAddCircle />
</template>
</AttachmentGroupBadge>
</AttachmentPolicyBadge>
</div>
<UppyUpload
endpoint="/apis/api.console.halo.run/v1alpha1/attachments/upload"
Expand Down
Loading