From 24365e92551ffda5ece65123bdaee9e7f95aed93 Mon Sep 17 00:00:00 2001 From: Partha Date: Sat, 4 Jan 2025 19:07:43 +0530 Subject: [PATCH 1/2] removed console.log and added route list page --- crates/webapp/src/components/ui/alert.tsx | 59 ++++++ .../src/pages/api/details/createRoute.tsx | 2 +- crates/webapp/src/pages/api/details/index.tsx | 172 ++++++++++++++++-- .../webapp/src/pages/api/details/settings.tsx | 59 +++--- .../src/pages/components/details/info.tsx | 1 - .../src/pages/components/details/settings.tsx | 14 +- .../src/pages/components/details/update.tsx | 1 - crates/webapp/src/pages/plugin/create.tsx | 2 - .../webapp/src/pages/workers/create/index.tsx | 1 - .../src/pages/workers/details/index.tsx | 4 - .../src/pages/workers/details/invoke.tsx | 4 - .../webapp/src/pages/workers/details/live.tsx | 1 - crates/webapp/src/service/client.ts | 66 ++++--- crates/webapp/src/service/wss.ts | 2 - crates/webapp/src/types/api.ts | 15 ++ crates/webapp/src/types/component.ts | 1 + 16 files changed, 300 insertions(+), 104 deletions(-) create mode 100644 crates/webapp/src/components/ui/alert.tsx diff --git a/crates/webapp/src/components/ui/alert.tsx b/crates/webapp/src/components/ui/alert.tsx new file mode 100644 index 0000000000..5afd41d142 --- /dev/null +++ b/crates/webapp/src/components/ui/alert.tsx @@ -0,0 +1,59 @@ +import * as React from "react" +import { cva, type VariantProps } from "class-variance-authority" + +import { cn } from "@/lib/utils" + +const alertVariants = cva( + "relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7", + { + variants: { + variant: { + default: "bg-background text-foreground", + destructive: + "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", + }, + }, + defaultVariants: { + variant: "default", + }, + } +) + +const Alert = React.forwardRef< + HTMLDivElement, + React.HTMLAttributes & VariantProps +>(({ className, variant, ...props }, ref) => ( +
+)) +Alert.displayName = "Alert" + +const AlertTitle = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertTitle.displayName = "AlertTitle" + +const AlertDescription = React.forwardRef< + HTMLParagraphElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)) +AlertDescription.displayName = "AlertDescription" + +export { Alert, AlertTitle, AlertDescription } diff --git a/crates/webapp/src/pages/api/details/createRoute.tsx b/crates/webapp/src/pages/api/details/createRoute.tsx index 6624825093..19965f3aac 100644 --- a/crates/webapp/src/pages/api/details/createRoute.tsx +++ b/crates/webapp/src/pages/api/details/createRoute.tsx @@ -256,7 +256,7 @@ const CreateRoute = () => { }`} > - {version} + V{version} diff --git a/crates/webapp/src/pages/api/details/index.tsx b/crates/webapp/src/pages/api/details/index.tsx index a04f91c154..db2b75c210 100644 --- a/crates/webapp/src/pages/api/details/index.tsx +++ b/crates/webapp/src/pages/api/details/index.tsx @@ -1,6 +1,8 @@ import { useParams, useNavigate } from "react-router-dom"; import { useEffect, useState } from "react"; -import { Plus } from "lucide-react"; +// import {Globe, Link2 } from "lucide-react" +import { Trash2, Plus } from "lucide-react"; + import { Select, SelectContent, @@ -11,14 +13,31 @@ import { import ApiLeftNav from "./apiLeftNav.tsx"; import { API } from "@/service"; import { Api } from "@/types/api"; -import { Button } from "@/components/ui/button.tsx"; import ErrorBoundary from "@/components/errorBoundary.tsx"; +import { Badge } from "@/components/ui/badge"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; const APIDetails = () => { const { apiName } = useParams(); const navigate = useNavigate(); const [apiDetails, setApiDetails] = useState([] as Api[]); const [activeApiDetails, setActiveApiDetails] = useState({} as Api); + // const [deployments] = useState([ + // { + // domain: "api.golem.cloud", + // id: "abcd", + // status: "Active", + // }, + // ]); useEffect(() => { if (apiName) { @@ -29,6 +48,22 @@ const APIDetails = () => { } }, [apiName]); + const handleDeleteRoute = (index: number) => { + const newRoutes = [...activeApiDetails.routes]; + newRoutes.splice(index, 1); + const newApiDetails = { + ...activeApiDetails, + routes: newRoutes, + }; + API.putApi( + activeApiDetails.id, + activeApiDetails.version, + newApiDetails + ).then(() => { + setActiveApiDetails(newApiDetails); + }); + }; + return (
@@ -71,22 +106,123 @@ const APIDetails = () => {
-
-
-
-

Routes

- -
-
- No routes defined for this API version. -
+
+
+ + +
+ Routes + +
+
+ + {activeApiDetails?.routes?.length === 0 ? ( +
+ No routes defined for this API version +
+ ) : ( +
+ {activeApiDetails?.routes?.map((route, index) => ( +
+
+
+ {route.method} + + {route.path} + +
+
+

+ Component ID:{" "} + {route.binding.componentId.componentId} +

+

+ Version ID: {route.binding.componentId.version} +

+

+ Worker: {route.binding.workerName} +

+

+ Response: {route.binding.response || "N/A"} +

+
+
+ + + + + + + Delete Route + + Are you sure you want to delete the route{" "} + {route.method} {route.path}? This action + cannot be undone. + + +
+ +
+
+
+
+ ))} +
+ )} +
+
+ {/* + + Active Deployments + + + + {deployments.map((deployment) => ( +
+
+
+ + + {deployment.domain} + +
+
+ + {deployment.id} +
+
+ {deployment.status} +
+ ))} +
+
*/}
diff --git a/crates/webapp/src/pages/api/details/settings.tsx b/crates/webapp/src/pages/api/details/settings.tsx index bc6dc52333..45dddd67a6 100644 --- a/crates/webapp/src/pages/api/details/settings.tsx +++ b/crates/webapp/src/pages/api/details/settings.tsx @@ -27,6 +27,7 @@ export default function APISettings() { const navigate = useNavigate(); const [showConfirmDialog, setShowConfirmDialog] = useState(false); const [showConfirmAllDialog, setShowConfirmAllDialog] = useState(false); + const [showConfirmAllRoutes, setShowConfirmAllRoutes] = useState(false); const [isDeleting, setIsDeleting] = useState(false); const { apiName } = useParams(); const [apiDetails, setApiDetails] = useState([] as Api[]); @@ -60,8 +61,7 @@ export default function APISettings() { setShowConfirmDialog(false); setIsDeleting(false); }) - .catch((error) => { - console.error(error); + .catch(() => { setIsDeleting(false); }); }; @@ -79,27 +79,32 @@ export default function APISettings() { }); setShowConfirmAllDialog(false); navigate(`/apis`); + setIsDeleting(false); }) - .catch((error) => { - console.error(error); + .catch(() => { setIsDeleting(false); }); }; const handleDeleteAllRoutes = async () => { + setIsDeleting(true); const payload = { ...activeApiDetails, routes: [], }; - API.putApi(activeApiDetails.id, activeApiDetails.version, payload).then( - () => { + API.putApi(activeApiDetails.id, activeApiDetails.version, payload) + .then(() => { toast({ title: "All routes deleted", description: "All routes have been deleted successfully.", }); navigate(`/apis/${apiName}`); - } - ); + setShowConfirmAllRoutes(false); + setIsDeleting(false); + }) + .catch(() => { + setIsDeleting(false); + }); }; return ( @@ -209,7 +214,7 @@ export default function APISettings() { @@ -217,7 +222,6 @@ export default function APISettings() {
- {/* Confirmation Dialog for Single Version Delete */} - - {/* Confirmation Dialog for Delete All */} + + + + + + + + + Are you sure you want to delete all routes? + + + This action cannot be undone. This will permanently delete + all routes and remove all associated data. + + +