|
| 1 | +import { CopyButton } from "@/components/CopyButton"; |
| 2 | +import { DisplayDate } from "@/components/DisplayDate"; |
| 3 | +import { InlineAvatar } from "@/components/InlineAvatar"; |
| 4 | +import { ComponentBadge } from "@/components/stack-components/ComponentBadge"; |
| 5 | +import { ComponentFallbackDialog } from "@/components/stack-components/ComponentFallbackDialog"; |
| 6 | +import { snakeCaseToTitleCase } from "@/lib/strings"; |
| 7 | +import { sanitizeUrl } from "@/lib/url"; |
| 8 | +import { getUsername } from "@/lib/user"; |
| 9 | +import { StackComponent } from "@/types/components"; |
| 10 | +import { ColumnDef } from "@tanstack/react-table"; |
| 11 | +import { Tag } from "@zenml-io/react-component-library/components/server"; |
| 12 | + |
| 13 | +export function getComponentList(): ColumnDef<StackComponent>[] { |
| 14 | + return [ |
| 15 | + { |
| 16 | + id: "name", |
| 17 | + header: "Component", |
| 18 | + accessorKey: "name", |
| 19 | + cell: ({ row }) => { |
| 20 | + const id = row.original.id; |
| 21 | + const name = row.original.name; |
| 22 | + return ( |
| 23 | + <div className="group/copybutton flex items-center gap-2"> |
| 24 | + <img |
| 25 | + width={32} |
| 26 | + height={32} |
| 27 | + src={sanitizeUrl(row.original.body?.logo_url || "")} |
| 28 | + alt="Flavor Icon" |
| 29 | + /> |
| 30 | + <div> |
| 31 | + <div className="flex items-center gap-1"> |
| 32 | + <ComponentFallbackDialog |
| 33 | + name={name} |
| 34 | + type={row.original.body?.type || "orchestrator"} |
| 35 | + > |
| 36 | + <button> |
| 37 | + <h2 className="text-text-md font-semibold">{name}</h2> |
| 38 | + </button> |
| 39 | + </ComponentFallbackDialog> |
| 40 | + <CopyButton copyText={name} /> |
| 41 | + </div> |
| 42 | + <div className="flex items-center gap-1"> |
| 43 | + <p className="text-text-xs text-theme-text-secondary">{id.split("-")[0]}</p> |
| 44 | + <CopyButton copyText={id} /> |
| 45 | + </div> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + ); |
| 49 | + } |
| 50 | + }, |
| 51 | + { |
| 52 | + id: "type", |
| 53 | + header: "Component Type", |
| 54 | + accessorFn: (row) => row.body?.type, |
| 55 | + cell: ({ row }) => { |
| 56 | + const type = row.original.body?.type || "orchestrator"; |
| 57 | + return <ComponentBadge type={type}>{snakeCaseToTitleCase(type)}</ComponentBadge>; |
| 58 | + } |
| 59 | + }, |
| 60 | + { |
| 61 | + id: "flavor", |
| 62 | + header: "Flavor", |
| 63 | + accessorFn: (row) => row.body?.flavor, |
| 64 | + cell: ({ row }) => { |
| 65 | + const flavor = row.original.body?.flavor; |
| 66 | + return ( |
| 67 | + <Tag |
| 68 | + rounded={false} |
| 69 | + className="w-fit gap-1 text-theme-text-primary" |
| 70 | + color="grey" |
| 71 | + emphasis="minimal" |
| 72 | + > |
| 73 | + <img |
| 74 | + width={20} |
| 75 | + height={20} |
| 76 | + src={sanitizeUrl(row.original.body?.logo_url || "")} |
| 77 | + alt="Flavor Icon of Component" |
| 78 | + /> |
| 79 | + <p>{flavor}</p> |
| 80 | + </Tag> |
| 81 | + ); |
| 82 | + } |
| 83 | + }, |
| 84 | + { |
| 85 | + id: "author", |
| 86 | + header: "Author", |
| 87 | + accessorFn: (row) => row.body?.user?.name, |
| 88 | + cell: ({ row }) => { |
| 89 | + const author = row.original.body?.user; |
| 90 | + if (!author) return null; |
| 91 | + return <InlineAvatar username={getUsername(author)} />; |
| 92 | + } |
| 93 | + }, |
| 94 | + { |
| 95 | + id: "created", |
| 96 | + header: "Created at", |
| 97 | + accessorFn: (row) => row.body?.created, |
| 98 | + cell: ({ row }) => ( |
| 99 | + <p className="text-text-sm text-theme-text-secondary"> |
| 100 | + <DisplayDate dateString={row.original.body?.created || ""} /> |
| 101 | + </p> |
| 102 | + ) |
| 103 | + } |
| 104 | + ]; |
| 105 | +} |
0 commit comments