Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

2.4 KB
Raw Blame
import { useTranslation } from "react-i18next";
import { EngineIcon } from "@/components/EngineIcon";
import { useAppDatabase } from "@/hooks/useAppDatabase";
import { useAppStore } from "@/stores/app";
import { Engine } from "@/types/proto-es/v1/common_pb";
import { bytesToString, getInstanceResource } from "@/utils";
import { engineNameV1 } from "@/utils/v1/instance";
import { InfoItem } from "./InfoItem";

type Props = {
  readonly database: string;
  readonly schema?: string;
  readonly table: string;
};

/**
 * Index size and collation are hidden for ClickHouse + Snowflake; collation
 * is also hidden for Postgres because the engine reports it at the column
 * level instead of the table level. Comment is shown only when present.
 */
export function TableInfo({ database, schema, table }: Props) {
  const { t } = useTranslation();
  const databaseEntity = useAppDatabase(database);
  const tableMetadata = useAppStore((s) =>
    s.getTableMetadata({ database, schema, table })
  );
  const instanceEngine = getInstanceResource(databaseEntity).engine;

  const indexSize =
    instanceEngine === Engine.CLICKHOUSE || instanceEngine === Engine.SNOWFLAKE
      ? ""
      : bytesToString(Number(tableMetadata.indexSize));
  const collation =
    instanceEngine === Engine.CLICKHOUSE ||
    instanceEngine === Engine.SNOWFLAKE ||
    instanceEngine === Engine.POSTGRES
      ? ""
      : tableMetadata.collation;
  const comment = tableMetadata.comment;

  return (
    <div className="min-w-56 max-w-[18rem] gap-y-1">
      <InfoItem title={t("common.name")}>{tableMetadata.name}</InfoItem>
      <InfoItem title={t("database.engine")}>
        <span className="flex items-center gap-x-1">
          <EngineIcon engine={instanceEngine} className="size-4" />
          {engineNameV1(instanceEngine)}
        </span>
      </InfoItem>
      <InfoItem title={t("database.row-count-estimate")}>
        {String(tableMetadata.rowCount)}
      </InfoItem>
      <InfoItem title={t("database.data-size")}>
        {bytesToString(Number(tableMetadata.dataSize))}
      </InfoItem>
      {indexSize ? (
        <InfoItem title={t("database.index-size")}>{indexSize}</InfoItem>
      ) : null}
      {collation ? (
        <InfoItem title={t("db.collation")}>{collation}</InfoItem>
      ) : null}
      {comment ? (
        <InfoItem title={t("database.comment")}>{comment}</InfoItem>
      ) : null}
    </div>
  );
}