Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 2x 2x | import { FileText, Link as LinkIcon, Server, Settings } from "lucide-react";
import React from "react";
import { CopyButton } from "@/components/detail";
// ─── Source type helpers ──────────────────────────────────────────────────────
const SENSITIVE_KEYS = new Set([
"password",
"pass",
"secret",
"token",
"key",
"auth_value",
"connection_string",
]);
function isSensitive(key: string) {
return [...SENSITIVE_KEYS].some((s) => key.toLowerCase().includes(s));
}
function configIcon(key: string): React.ElementType {
if (key.includes("url") || key.includes("endpoint") || key.includes("host"))
return LinkIcon;
if (key.includes("path")) return FileText;
if (key.includes("auth") || key.includes("header")) return Settings;
if (key.includes("connect") || key.includes("db")) return Server;
return Settings;
}
// ─── Primitives ───────────────────────────────────────────────────────────────
// ─── Config field renderer ────────────────────────────────────────────────────
const ConfigField: React.FC<{ fieldKey: string; value: unknown }> = ({
fieldKey,
value,
}) => {
const Icon = configIcon(fieldKey);
const sensitive = isSensitive(fieldKey);
const label = fieldKey.replace(/_/g, " ");
const renderValue = () => {
if (sensitive) {
return (
<span className="text-xs font-mono text-gray-400 dark:text-gray-500 italic">
••••••••
</span>
);
}
if (Array.isArray(value)) {
return (
<div className="flex flex-col gap-1">
{(value as string[]).map((v, i) => (
<div key={i} className="flex items-center justify-between group">
<code className="text-xs font-mono text-gray-700 dark:text-gray-300 bg-gray-50 dark:bg-gray-700 px-2 py-0.5 rounded truncate max-w-sm">
{v}
</code>
<div className="opacity-0 group-hover:opacity-100 transition-opacity">
<CopyButton value={v} />
</div>
</div>
))}
</div>
);
}
if (typeof value === "number") {
return (
<span className="text-xs font-semibold text-gray-800 dark:text-gray-200 tabular-nums">
{value}
</span>
);
}
return (
<div className="flex items-center justify-between group">
<code className="text-xs font-mono text-gray-700 dark:text-gray-300 bg-gray-50 dark:bg-gray-700 px-2 py-0.5 rounded truncate max-w-sm">
{String(value ?? "—")}
</code>
{!!value && (
<div className="opacity-0 group-hover:opacity-100 transition-opacity">
<CopyButton value={String(value)} />
</div>
)}
</div>
);
};
return (
<div className="flex items-start gap-3 py-2.5 border-b border-gray-50 dark:border-gray-700/50 last:border-0">
<div className="flex items-center gap-1.5 w-36 shrink-0">
<Icon className="size-3 text-gray-400 dark:text-gray-500 shrink-0" />
<span className="text-xs text-gray-500 dark:text-gray-400 capitalize">
{label}
</span>
</div>
<div className="flex-1 min-w-0">{renderValue()}</div>
</div>
);
};
export default ConfigField;
|