From 082a76bfb77c8b65a60202700839a842dfb322a3 Mon Sep 17 00:00:00 2001 From: karamvir Date: Tue, 25 Jul 2023 16:06:37 -0700 Subject: [PATCH] improve updates --- frontend/src/components/updates/desktop.tsx | 4 +- frontend/src/components/updates/details.tsx | 172 +++++++++++++++++ frontend/src/components/updates/update.tsx | 193 +++----------------- frontend/src/components/updates/updates.tsx | 36 ---- frontend/src/util/helpers.ts | 4 + 5 files changed, 207 insertions(+), 202 deletions(-) create mode 100644 frontend/src/components/updates/details.tsx delete mode 100644 frontend/src/components/updates/updates.tsx diff --git a/frontend/src/components/updates/desktop.tsx b/frontend/src/components/updates/desktop.tsx index 14063218f..1acf792d1 100644 --- a/frontend/src/components/updates/desktop.tsx +++ b/frontend/src/components/updates/desktop.tsx @@ -6,7 +6,7 @@ import { DropdownMenuTrigger, } from "@ui/dropdown"; import { Bell } from "lucide-react"; -import { SingleUpdate } from "./updates"; +import { SingleUpdate } from "./update"; import { Button } from "@ui/button"; export const DesktopUpdates = () => { @@ -22,7 +22,7 @@ export const DesktopUpdates = () => { {updates?.map((update) => ( -
+
))} diff --git a/frontend/src/components/updates/details.tsx b/frontend/src/components/updates/details.tsx new file mode 100644 index 000000000..bb7808cfb --- /dev/null +++ b/frontend/src/components/updates/details.tsx @@ -0,0 +1,172 @@ +import { + Sheet, + SheetContent, + SheetDescription, + SheetHeader, + SheetTitle, + SheetTrigger, +} from "@ui/sheet"; +import { Update } from "@monitor/client/dist/types"; +import { + readableDuration, + readableVersion, + version_to_string, +} from "@util/helpers"; +import { + Calendar, + Clock, + Hammer, + Milestone, + Rocket, + Server, + User, +} from "lucide-react"; +// import { UpdateUser } from "."; +import { + Card, + CardContent, + CardDescription, + CardHeader, + CardTitle, +} from "@ui/card"; +import { ReactNode } from "react"; +import { useNavigate } from "react-router-dom"; +import { ServerName } from "@resources/server/util"; +import { DeploymentName } from "@resources/deployment/util"; +import { BuildName } from "@resources/build/util"; +// import { useRead } from "@hooks"; + +export const UpdateUser = ({ userId }: { userId: string }) => { + // const { data } = useRead({ type: "GetUser", params: {} }); + if (userId === "github") return <>GitHub; + if (userId === "auto redeploy") return <>Auto Redeploy; + return <>{userId.slice(0, 10)}...; +}; + +export const UpdateDetails = ({ + update, + children, +}: { + update: Update; + children: ReactNode; +}) => { + const nav = useNavigate(); + return ( + + {children} + + + + {update.operation + .split("_") + .map((s) => s[0].toUpperCase() + s.slice(1)) + .join(" ")}{" "} + {version_to_string(update.version)} + + +
+ + +
+
+
{ + update.target.id + ? nav( + `/${update.target.type.toLowerCase()}s/${ + update.target.id + }` + ) + : null; + }} + > + {update.target.type === "Server" && ( + <> + + + + )} + {update.target.type === "Deployment" && ( + <> + + + + )} + {update.target.type === "Build" && ( + <> + + + + )} +
+ {update.version && ( +
+ + {readableVersion(update.version)} +
+ )} +
+
+
+ + {new Date(update.start_ts).toLocaleString()} +
+
+ + {update.end_ts + ? readableDuration(update.start_ts, update.end_ts) + : "ongoing"} +
+
+
+
+
+ {update.logs.map((log, i) => ( + + + {log.stage} + + + Stage {i + 1} of {update.logs.length} + + | + + + {readableDuration(log.start_ts, log.end_ts)} + + + + + {log.command && ( +
+ command +
+                      {log.command}
+                    
+
+ )} + {log.stdout && ( +
+ stdout +
+                      {log.stdout}
+                    
+
+ )} + {log.stderr && ( +
+ stdout +
+                      {log.stderr}
+                    
+
+ )} +
+
+ ))} +
+
+
+ ); +}; diff --git a/frontend/src/components/updates/update.tsx b/frontend/src/components/updates/update.tsx index 882e2aec7..f50e55586 100644 --- a/frontend/src/components/updates/update.tsx +++ b/frontend/src/components/updates/update.tsx @@ -1,168 +1,33 @@ -import { - Sheet, - SheetContent, - SheetDescription, - SheetHeader, - SheetTitle, - SheetTrigger, -} from "@ui/sheet"; +import { version_to_string } from "@util/helpers"; +import { Calendar, User } from "lucide-react"; +import { UpdateDetails, UpdateUser } from "./details"; import { Update } from "@monitor/client/dist/types"; -import { - readableDuration, - readableVersion, - version_to_string, -} from "@util/helpers"; -import { - Calendar, - Clock, - Hammer, - Milestone, - Rocket, - Server, - User, -} from "lucide-react"; -// import { UpdateUser } from "."; -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@ui/card"; -import { ReactNode } from "react"; -import { useNavigate } from "react-router-dom"; -import { ServerName } from "@resources/server/util"; -import { DeploymentName } from "@resources/deployment/util"; -import { BuildName } from "@resources/build/util"; -// import { useRead } from "@hooks"; -export const UpdateUser = ({ userId }: { userId: string }) => { - // const { data } = useRead({ type: "GetUser", params: {} }); - if (userId === "github") return <>GitHub; - if (userId === "auto redeploy") return <>Auto Redeploy; - return <>{userId.slice(0, 10)}...; -}; +const fmt_date = (d: Date) => + `${d.getDate()}/${d.getMonth()} @ ${d.getHours()}:${d.getMinutes()}`; -export const UpdateDetails = ({ - update, - children, -}: { - update: Update; - children: ReactNode; -}) => { - const nav = useNavigate(); - return ( - - {children} - - - - {update.operation - .split("_") - .map((s) => s[0].toUpperCase() + s.slice(1)) - .join(" ")}{" "} - {version_to_string(update.version)} - - -
{ - update.target.id - ? nav( - `/${update.target.type.toLowerCase()}s/${ - update.target.id - }` - ) - : null; - }} - > - {update.target.type === "Server" && ( - <> - - - - )} - {update.target.type === "Deployment" && ( - <> - - - - )} - {update.target.type === "Build" && ( - <> - - - - )} -
-
- - {new Date(update.start_ts).toLocaleString()} -
-
- - {update.end_ts - ? readableDuration(update.start_ts, update.end_ts) - : "ongoing"} -
-
- - -
- {update.version && ( -
- - {readableVersion(update.version)} -
- )} -
-
-
- {update.logs.map((log, i) => ( - - - {log.stage} - - - Stage {i + 1} of {update.logs.length} - - | - - - {readableDuration(log.start_ts, log.end_ts)} - - - - - {log.command && ( -
- command -
-                      {log.command}
-                    
-
- )} - {log.stdout && ( -
- stdout -
-                      {log.stdout}
-                    
-
- )} - {log.stderr && ( -
- stdout -
-                      {log.stderr}
-                    
-
- )} -
-
- ))} +export const SingleUpdate = ({ update }: { update: Update }) => ( + +
+
+ +
+ {update.end_ts ? fmt_date(new Date(update.end_ts)) : "ongoing"}
- - - ); -}; +
+ +
+ {update.operation.match(/[A-Z][a-z]+|[0-9]+/g)?.join(" ")}{" "} + {version_to_string(update.version)} +
+ +
+ + +
+
+
+); diff --git a/frontend/src/components/updates/updates.tsx b/frontend/src/components/updates/updates.tsx deleted file mode 100644 index 457d65ee0..000000000 --- a/frontend/src/components/updates/updates.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { version_to_string } from "@util/helpers"; -import { Calendar, User } from "lucide-react"; -import { UpdateDetails, UpdateUser } from "./update"; -import { Update } from "@monitor/client/dist/types"; - -const fmt_date = (d: Date) => - `${d.getDate()}/${d.getMonth()} @ ${d.getHours()}:${d.getMinutes()}`; - -export const SingleUpdate = ({ update }: { update: Update }) => ( - -
-
- -
- {update.end_ts ? fmt_date(new Date(update.end_ts)) : "ongoing"} -
-
- -
- {update.operation - .split("_") - .map((s) => s[0].toUpperCase() + s.slice(1)) - .join(" ")}{" "} - {version_to_string(update.version)} -
- -
- - -
-
-
-); diff --git a/frontend/src/util/helpers.ts b/frontend/src/util/helpers.ts index 014c3d706..783ae0507 100644 --- a/frontend/src/util/helpers.ts +++ b/frontend/src/util/helpers.ts @@ -196,8 +196,12 @@ export function deploymentHeaderStateClass(state: Types.DockerContainerState) { } } +export const keys = (o: T): (keyof T)[] => + Object.keys(o) as (keyof T)[]; + export function version_to_string(version: Types.Version | undefined) { if (!version) return; + if (!keys(version).some((k) => !!version[k])) return; return `v${version.major}.${version.minor}.${version.patch}`; }