fix(cloudflare): deduplicate batch member ids and guard move dialog dismiss during pending

This commit is contained in:
ryan
2026-09-26 15:39:10 +08:00
parent 2b3be6f3a3
commit c3606bc6f6
2 changed files with 36 additions and 4 deletions
@@ -70,8 +70,22 @@ export function MemberMoveDialog({
: t('moveDialog.targetGroupLabel'); : t('moveDialog.targetGroupLabel');
return ( return (
<Dialog open={open} onOpenChange={onOpenChange}> <Dialog
<DialogContent> open={open}
onOpenChange={(next) => {
if (!pending) {
onOpenChange(next);
}
}}
>
<DialogContent
onPointerDownOutside={(e) => {
if (pending) e.preventDefault();
}}
onEscapeKeyDown={(e) => {
if (pending) e.preventDefault();
}}
>
<DialogHeader> <DialogHeader>
<DialogTitle>{title}</DialogTitle> <DialogTitle>{title}</DialogTitle>
<DialogDescription className='line-clamp-2'> <DialogDescription className='line-clamp-2'>
+20 -2
View File
@@ -436,7 +436,7 @@ func BatchMoveMembers(ctx context.Context, sourceGroupID uint, input MemberBatch
} }
return err return err
} }
for _, memberID := range input.MemberIDs { for _, memberID := range uniqueIDs(input.MemberIDs) {
member, getErr := repository.GetCFPointingMember(ctx, sourceGroupID, memberID) member, getErr := repository.GetCFPointingMember(ctx, sourceGroupID, memberID)
if getErr != nil { if getErr != nil {
continue continue
@@ -462,7 +462,7 @@ func BatchRemoveMembers(ctx context.Context, sourceGroupID uint, input MemberBat
if len(input.MemberIDs) == 0 { if len(input.MemberIDs) == 0 {
return errors.New(errNoMembersSelected) return errors.New(errNoMembersSelected)
} }
for _, memberID := range input.MemberIDs { for _, memberID := range uniqueIDs(input.MemberIDs) {
member, err := repository.GetCFPointingMember(ctx, sourceGroupID, memberID) member, err := repository.GetCFPointingMember(ctx, sourceGroupID, memberID)
if err != nil { if err != nil {
continue continue
@@ -477,6 +477,24 @@ func BatchRemoveMembers(ctx context.Context, sourceGroupID uint, input MemberBat
return nil return nil
} }
func uniqueIDs(ids []uint) []uint {
if len(ids) == 0 {
return ids
}
seen := make(map[uint]struct{}, len(ids))
result := make([]uint, 0, len(ids))
for _, id := range ids {
if id == 0 {
continue
}
if _, exists := seen[id]; !exists {
seen[id] = struct{}{}
result = append(result, id)
}
}
return result
}
// DeleteGroup removes every managed remote A record and then local state. // DeleteGroup removes every managed remote A record and then local state.
func DeleteGroup(ctx context.Context, groupID uint) error { func DeleteGroup(ctx context.Context, groupID uint) error {
if _, err := repository.GetCFPointingGroup(ctx, groupID); err != nil { if _, err := repository.GetCFPointingGroup(ctx, groupID); err != nil {