mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-28 05:46:36 +08:00
fix(cloudflare): deduplicate batch member ids and guard move dialog dismiss during pending
This commit is contained in:
@@ -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'>
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user