fix: prevent "Allow All" resource group from being set as default

This commit is contained in:
lcx committed 2026-01-07 16:49:59 +08:00
1 parent 8394afe581
commit 060bcf7f73
3 files changed
+26 -11

No files matched your search

@@ -5,6 +5,7 @@ interface AddServerModalProps {
isOpen: boolean;
onClose: () => void;
name: string;
id: string;
onSaveServer: (name: string, isDefault: boolean) => Promise<void>;
type: "add" | "edit";
isDefault: boolean;
@@ -13,6 +14,7 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
isOpen,
onClose,
name,
id,
onSaveServer,
type,
isDefault,
@@ -49,12 +51,16 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
{type === "add" ? t("Create New Resource Group") : t("Edit Resource Group")}
</ModalHeader>
<ModalBody>
<Input
label={t("Resource Group Name")}
value={serverName}
placeholder={t("Edit Resource Group Name")}
onChange={(e) => setServerName(e.target.value)}
/>
{
id !== 'allow-all' && <>
<Input
label={t("Resource Group Name")}
value={serverName}
placeholder={t("Edit Resource Group Name")}
onChange={(e) => setServerName(e.target.value)}
/>
</>
}
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-lg">
<div className="flex flex-col gap-1">
<span className="text-sm font-medium">
@@ -73,9 +79,9 @@ export const AddServerModal: React.FC<AddServerModalProps> = ({
</div>
</ModalBody>
<ModalFooter>
<Button
color="danger"
variant="light"
<Button
color="danger"
variant="light"
onPress={onClose}
isDisabled={isLoading}
>
@@ -84,6 +84,12 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
return !['allow-all', 'deny-all'].includes(resourceGroupDetail.id);
}, [resourceGroupDetail]);
// 是否展示编辑按钮
const showEditOptions = useMemo(() => {
if (!resourceGroupDetail) return false;
return !['deny-all'].includes(resourceGroupDetail.id);
}, [resourceGroupDetail]);
const getResourceGroup = async (groupId: string) => {
const response = await fetchResourceGroupDetail(groupId);
if (response) {
@@ -106,7 +112,7 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
{resourceGroupDetail?.name}
</h2>
<div className="flex gap-2 h-[32px]">
{showOptions && currentGroupId && <>
{showEditOptions && currentGroupId && <>
<Button
isIconOnly
size="sm"
@@ -114,7 +120,9 @@ const GroupServiceTable: React.FC<GroupServiceTableProps> = ({
onPress={() => onEditGroup(currentGroupId)}
>
<Edit2 size={18} />
</Button>
</Button></>
}
{showOptions && currentGroupId && <>
<Button
isIconOnly
size="sm"
@@ -330,6 +330,7 @@ const ResourceGroupManagement: React.FC = () => {
setEditingGroup(null);
}}
name={editingGroup?.name || ""}
id={editingGroup?.id || ""}
isDefault={editingGroup?.isDefault || false}
onSaveServer={handleSaveGroup}
type={editingGroup ? "edit" : "add"}