mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-17 06:24:32 +00:00
♻️ delete resource policy endpoint
This commit is contained in:
@@ -191,6 +191,8 @@
|
|||||||
"notProtected": "Not Protected",
|
"notProtected": "Not Protected",
|
||||||
"resourceMessageRemove": "Once removed, the resource will no longer be accessible. All targets associated with the resource will also be removed.",
|
"resourceMessageRemove": "Once removed, the resource will no longer be accessible. All targets associated with the resource will also be removed.",
|
||||||
"resourceQuestionRemove": "Are you sure you want to remove the resource from the organization?",
|
"resourceQuestionRemove": "Are you sure you want to remove the resource from the organization?",
|
||||||
|
"resourcePolicyMessageRemove": "Once removed, the resource policy will no longer be accessible. All resources associated with the resource will be unlinked and left without authentication.",
|
||||||
|
"resourcePolicyQuestionRemove": "Are you sure you want to remove the resource policy from the organization?",
|
||||||
"resourceHTTP": "HTTPS Resource",
|
"resourceHTTP": "HTTPS Resource",
|
||||||
"resourceHTTPDescription": "Proxy requests over HTTPS using a fully qualified domain name.",
|
"resourceHTTPDescription": "Proxy requests over HTTPS using a fully qualified domain name.",
|
||||||
"resourceRaw": "Raw TCP/UDP Resource",
|
"resourceRaw": "Raw TCP/UDP Resource",
|
||||||
@@ -231,6 +233,8 @@
|
|||||||
"resourceLearnRaw": "Learn how to configure TCP/UDP resources",
|
"resourceLearnRaw": "Learn how to configure TCP/UDP resources",
|
||||||
"resourceBack": "Back to Resources",
|
"resourceBack": "Back to Resources",
|
||||||
"resourceGoTo": "Go to Resource",
|
"resourceGoTo": "Go to Resource",
|
||||||
|
"resourcePolicyDelete": "Delete Resource Policy",
|
||||||
|
"resourcePolicyDeleteConfirm": "Confirm Delete Resource Policy",
|
||||||
"resourceDelete": "Delete Resource",
|
"resourceDelete": "Delete Resource",
|
||||||
"resourceDeleteConfirm": "Confirm Delete Resource",
|
"resourceDeleteConfirm": "Confirm Delete Resource",
|
||||||
"visibility": "Visibility",
|
"visibility": "Visibility",
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ const deleteResourcePolicySchema = z.strictObject({
|
|||||||
|
|
||||||
registry.registerPath({
|
registry.registerPath({
|
||||||
method: "delete",
|
method: "delete",
|
||||||
path: "/resource/{resourceId}",
|
path: "/resource-policy/{resourcePolicyId}",
|
||||||
description: "Delete a resource.",
|
description: "Delete a resource policy.",
|
||||||
tags: [OpenAPITags.PublicResource],
|
tags: [OpenAPITags.Policy],
|
||||||
request: {
|
request: {
|
||||||
params: deleteResourcePolicySchema
|
params: deleteResourcePolicySchema
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import { useNavigationContext } from "@app/hooks/useNavigationContext";
|
import { useNavigationContext } from "@app/hooks/useNavigationContext";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
import { createApiClient } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import type {
|
import type {
|
||||||
AttachedResource,
|
AttachedResource,
|
||||||
ListResourcePoliciesResponse
|
ListResourcePoliciesResponse
|
||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useTransition } from "react";
|
import { useState, useTransition } from "react";
|
||||||
import { useDebouncedCallback } from "use-debounce";
|
import { useDebouncedCallback } from "use-debounce";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
import { ControlledDataTable } from "./ui/controlled-data-table";
|
import { ControlledDataTable } from "./ui/controlled-data-table";
|
||||||
@@ -28,8 +28,7 @@ import {
|
|||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger
|
||||||
} from "./ui/dropdown-menu";
|
} from "./ui/dropdown-menu";
|
||||||
import type { targets } from "@server/db";
|
import ConfirmDeleteDialog from "./ConfirmDeleteDialog";
|
||||||
import type { TargetHealth } from "./ProxyResourcesTable";
|
|
||||||
|
|
||||||
type ResourcePolicyRow = ListResourcePoliciesResponse["policies"][number];
|
type ResourcePolicyRow = ListResourcePoliciesResponse["policies"][number];
|
||||||
|
|
||||||
@@ -58,6 +57,27 @@ export function ResourcePoliciesTable({
|
|||||||
|
|
||||||
const api = createApiClient({ env });
|
const api = createApiClient({ env });
|
||||||
|
|
||||||
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const [selectedResourcePolicy, setSelectedResourcePolicy] =
|
||||||
|
useState<ResourcePolicyRow | null>(null);
|
||||||
|
|
||||||
|
const deleteResourcePolicy = async (resourcePolicyId: number) => {
|
||||||
|
await api
|
||||||
|
.delete(`/resource-policy/${resourcePolicyId}`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(t("resourceErrorDelte"), e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: t("resourceErrorDelte"),
|
||||||
|
description: formatAxiosError(e, t("resourceErrorDelte"))
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
router.refresh();
|
||||||
|
setIsDeleteModalOpen(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const [isRefreshing, startTransition] = useTransition();
|
const [isRefreshing, startTransition] = useTransition();
|
||||||
const [isNavigatingToAddPage, startNavigation] = useTransition();
|
const [isNavigatingToAddPage, startNavigation] = useTransition();
|
||||||
|
|
||||||
@@ -191,8 +211,8 @@ export function ResourcePoliciesTable({
|
|||||||
</Link>
|
</Link>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// setSelectedResource(resourceRow);
|
setSelectedResourcePolicy(policyRow);
|
||||||
// setIsDeleteModalOpen(true);
|
setIsDeleteModalOpen(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="text-red-500">
|
<span className="text-red-500">
|
||||||
@@ -233,6 +253,29 @@ export function ResourcePoliciesTable({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{selectedResourcePolicy && (
|
||||||
|
<ConfirmDeleteDialog
|
||||||
|
open={isDeleteModalOpen}
|
||||||
|
setOpen={(val) => {
|
||||||
|
setIsDeleteModalOpen(val);
|
||||||
|
setSelectedResourcePolicy(null);
|
||||||
|
}}
|
||||||
|
dialog={
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p>{t("resourcePolicyQuestionRemove")}</p>
|
||||||
|
<p>{t("resourcePolicyMessageRemove")}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
buttonText={t("resourcePolicyDeleteConfirm")}
|
||||||
|
onConfirm={async () =>
|
||||||
|
deleteResourcePolicy(
|
||||||
|
selectedResourcePolicy.resourcePolicyId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
string={selectedResourcePolicy.name}
|
||||||
|
title={t("resourcePolicyDelete")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<ControlledDataTable
|
<ControlledDataTable
|
||||||
columns={proxyColumns}
|
columns={proxyColumns}
|
||||||
rows={policies}
|
rows={policies}
|
||||||
|
|||||||
Reference in New Issue
Block a user