|
| 1 | +import EyeIcon from "@/assets/icons/eye.svg?react"; |
| 2 | +import KeyIcon from "@/assets/icons/key-icon.svg?react"; |
| 3 | +import { ColumnDef } from "@tanstack/react-table"; |
| 4 | +import { useState } from "react"; // Import useState for local state |
| 5 | +import { SecretTooltip } from "../SecretTooltip"; |
| 6 | +import SecretTableDropDown from "./SecretTableDropDown"; |
| 7 | + |
| 8 | +const ValueCell: React.FC<{ value: unknown }> = ({ value }) => { |
| 9 | + const [isVisible, setIsVisible] = useState(false); |
| 10 | + const valueStr = typeof value === "string" ? value : ""; |
| 11 | + const dots = "•".repeat(valueStr.length); |
| 12 | + |
| 13 | + return ( |
| 14 | + <div className="flex items-center gap-2 space-x-2"> |
| 15 | + <EyeIcon onClick={() => setIsVisible(!isVisible)} className="h-4 w-4 flex-shrink-0" /> |
| 16 | + <span>{isVisible ? valueStr : dots}</span> |
| 17 | + </div> |
| 18 | + ); |
| 19 | +}; |
| 20 | + |
| 21 | +export function getSecretDetailColumn( |
| 22 | + secretId: string, |
| 23 | + name: string |
| 24 | +): ColumnDef<{ key: string; value: string }>[] { |
| 25 | + return [ |
| 26 | + { |
| 27 | + id: "key", |
| 28 | + header: "Key", |
| 29 | + accessorKey: "key", |
| 30 | + cell: ({ row }) => { |
| 31 | + const code = `from zenml.client import Client |
| 32 | +secret = Client().get_secret(${name}) |
| 33 | + |
| 34 | +# 'secret.secret_values' will contain a dictionary with all key-value pairs within your secret. |
| 35 | +secret.secret_values["${row.original.key}"] |
| 36 | + `; |
| 37 | + return ( |
| 38 | + <div className="flex items-center space-x-2"> |
| 39 | + <KeyIcon className="h-5 w-5 flex-shrink-0 fill-primary-400" /> |
| 40 | + <div className="flex flex-col"> |
| 41 | + <div className="flex items-center space-x-1"> |
| 42 | + <div className="flex items-center space-x-1"> |
| 43 | + <span className="text-text-md font-semibold text-theme-text-primary"> |
| 44 | + {row.original.key} |
| 45 | + </span> |
| 46 | + <SecretTooltip code={code} /> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + ); |
| 52 | + } |
| 53 | + }, |
| 54 | + { |
| 55 | + id: "value", |
| 56 | + header: "Value", |
| 57 | + accessorKey: "value", |
| 58 | + cell: ({ row }) => <ValueCell value={row.getValue("value")} /> |
| 59 | + }, |
| 60 | + { |
| 61 | + id: "actions", |
| 62 | + header: "", |
| 63 | + cell: ({ row }) => <SecretTableDropDown secretId={secretId} keyName={row.original.key} /> |
| 64 | + } |
| 65 | + ]; |
| 66 | +} |
0 commit comments