From 2e690bce245d03cce4933c4d90e68556de215cd2 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sun, 11 Aug 2024 17:36:00 -0700 Subject: [PATCH] repo table just show repo and branch --- .../src/components/resources/repo/actions.tsx | 10 ++-- .../src/components/resources/repo/index.tsx | 50 ++++++++++++------- .../src/components/resources/repo/table.tsx | 26 +--------- frontend/src/pages/resource.tsx | 2 +- 4 files changed, 42 insertions(+), 46 deletions(-) diff --git a/frontend/src/components/resources/repo/actions.tsx b/frontend/src/components/resources/repo/actions.tsx index 4315bc182..ac047a4d8 100644 --- a/frontend/src/components/resources/repo/actions.tsx +++ b/frontend/src/components/resources/repo/actions.tsx @@ -12,14 +12,16 @@ import { Types } from "@monitor/client"; import { useBuilder } from "../builder"; export const CloneRepo = ({ id }: { id: string }) => { - const hash = useRepo(id)?.info.latest_hash; - const isCloned = (hash?.length || 0) > 0; const { mutate, isPending } = useExecute("CloneRepo"); const cloning = useRead( "GetRepoActionState", { repo: id }, { refetchInterval: 5000 } ).data?.cloning; + const info = useRepo(id)?.info; + if (!info?.server_id) return null; + const hash = info?.latest_hash; + const isCloned = (hash?.length || 0) > 0; const pending = isPending || cloning; return ( { { repo: id }, { refetchInterval: 5000 } ).data?.pulling; - const hash = useRepo(id)?.info.latest_hash; + const info = useRepo(id)?.info; + if (!info?.server_id) return null; + const hash = info?.latest_hash; const isCloned = (hash?.length || 0) > 0; if (!isCloned) return null; const pending = isPending || pulling; diff --git a/frontend/src/components/resources/repo/index.tsx b/frontend/src/components/resources/repo/index.tsx index eba620971..d847c9aea 100644 --- a/frontend/src/components/resources/repo/index.tsx +++ b/frontend/src/components/resources/repo/index.tsx @@ -2,6 +2,7 @@ import { useInvalidate, useRead, useWrite } from "@lib/hooks"; import { RequiredResourceComponents } from "@types"; import { Card } from "@ui/card"; import { + Factory, FolderGit, GitBranch, Loader2, @@ -25,6 +26,7 @@ import { StatusBadge } from "@components/util"; import { Badge } from "@ui/badge"; import { useToast } from "@ui/use-toast"; import { Button } from "@ui/button"; +import { useBuilder } from "../builder"; export const useRepo = (id?: string) => useRead("ListRepos", {}, { refetchInterval: 5000 }).data?.find( @@ -195,6 +197,30 @@ export const RepoComponents: RequiredResourceComponents = { }, Info: { + Server: ({ id }) => { + const info = useRepo(id)?.info; + const server = useServer(info?.server_id); + return server?.id ? ( + + ) : ( +
+ +
No Server
+
+ ); + }, + Builder: ({ id }) => { + const info = useRepo(id)?.info; + const builder = useBuilder(info?.builder_id); + return builder?.id ? ( + + ) : ( +
+ +
No Builder
+
+ ); + }, Repo: ({ id }) => { const repo = useRepo(id)?.info.repo; return ( @@ -204,24 +230,12 @@ export const RepoComponents: RequiredResourceComponents = { ); }, - // Branch: ({ id }) => { - // const branch = useRepo(id)?.info.branch; - // return ( - //
- // - // {branch} - //
- // ); - // }, - Server: ({ id }) => { - const info = useRepo(id)?.info; - const server = useServer(info?.server_id); - return server?.id ? ( - - ) : ( -
- -
Unknown Server
+ Branch: ({ id }) => { + const branch = useRepo(id)?.info.branch; + return ( +
+ + {branch}
); }, diff --git a/frontend/src/components/resources/repo/table.tsx b/frontend/src/components/resources/repo/table.tsx index 711a819f5..77589c726 100644 --- a/frontend/src/components/resources/repo/table.tsx +++ b/frontend/src/components/resources/repo/table.tsx @@ -1,17 +1,10 @@ -import { useRead } from "@lib/hooks"; import { DataTable, SortableHeader } from "@ui/data-table"; import { ResourceLink } from "../common"; import { TableTags } from "@components/tags"; import { RepoComponents } from "."; import { Types } from "@monitor/client"; -import { useCallback } from "react"; export const RepoTable = ({ repos }: { repos: Types.RepoListItem[] }) => { - const servers = useRead("ListServers", {}).data; - const serverName = useCallback( - (id: string) => servers?.find((server) => server.id === id)?.name, - [servers] - ); return ( { size: 200, }, { - accessorKey: "info.server_id", - sortingFn: (a, b) => { - const sa = serverName(a.original.info.server_id); - const sb = serverName(b.original.info.server_id); - - if (!sa && !sb) return 0; - if (!sa) return -1; - if (!sb) return 1; - - if (sa > sb) return 1; - else if (sa < sb) return -1; - else return 0; - }, + accessorKey: "info.branch", header: ({ column }) => ( - - ), - cell: ({ row }) => ( - + ), size: 200, }, diff --git a/frontend/src/pages/resource.tsx b/frontend/src/pages/resource.tsx index 3fa65f9ca..c0e240e86 100644 --- a/frontend/src/pages/resource.tsx +++ b/frontend/src/pages/resource.tsx @@ -139,7 +139,7 @@ const ResourceHeader = ({ type, id }: { type: UsableResource; id: string }) => { {infoEntries.map(([key, Info]) => (