MCPcopy Create free account
hub / github.com/bytebase/bytebase / TableSchemaViewer

Function TableSchemaViewer

frontend/src/react/components/TableSchemaViewer.tsx:33–99  ·  view source on GitHub ↗
({
  database,
  schema,
  object,
  type,
  className,
}: Props)

Source from the content-addressed store, hash-verified

31 * engines without schemas) breadcrumb plus a Copy-to-clipboard button.
32 */
33export function TableSchemaViewer({
34 database,
35 schema,
36 object,
37 type,
38 className,
39}: Props) {
40 const { t } = useTranslation();
41 const [schemaString, setSchemaString] = useState<string>("");
42
43 const engine = getInstanceResource(database).engine;
44 const resourceName = object
45 ? hasSchemaProperty(engine)
46 ? `${schema}.${object}`
47 : object
48 : schema || database.name;
49
50 useEffect(() => {
51 let cancelled = false;
52 const request = create(GetSchemaStringRequestSchema, {
53 name: `${database.name}/schemaString`,
54 type,
55 schema,
56 object,
57 });
58 void databaseServiceClientConnect
59 .getSchemaString(request)
60 .then((response) => {
61 if (cancelled) return;
62 setSchemaString(response.schemaString.trim());
63 });
64 return () => {
65 cancelled = true;
66 };
67 }, [database.name, schema, object, type]);
68
69 const handleCopy = async () => {
70 await writeTextToClipboard(schemaString);
71 };
72
73 return (
74 <div
75 className={`w-full h-auto flex flex-col justify-start items-center ${className ?? ""}`}
76 >
77 <div className="w-full flex flex-row justify-between items-center gap-x-2 mb-2">
78 <div className="text-sm text-control flex-1 truncate">
79 {resourceName}
80 </div>
81 <Tooltip content={t("common.copy")}>
82 <Button
83 type="button"
84 variant="ghost"
85 size="sm"
86 disabled={!schemaString}
87 onClick={handleCopy}
88 >
89 <Copy className="size-4" />
90 </Button>

Callers

nothing calls this directly

Calls 3

getInstanceResourceFunction · 0.90
hasSchemaPropertyFunction · 0.90
tFunction · 0.50

Tested by

no test coverage detected