Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
import { create } from "@bufbuild/protobuf";
import { ChevronRight } from "lucide-react";
import { EngineIcon } from "@/components/EngineIcon";
import { HighlightLabelText } from "@/components/HighlightLabelText";
import { Checkbox } from "@/components/ui/checkbox";
import { Tooltip } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
import { RequestQueryButton } from "@/modules/sql-editor/components/RequestQueryButton";
import { useSupportBatchMode } from "@/modules/sql-editor/store/tab";
import type { SQLEditorTreeNode } from "@/types";
import { PermissionDeniedDetailSchema } from "@/types/proto-es/v1/common_pb";
import {
extractDatabaseResourceName,
getInstanceResource,
instanceV1Name,
isDatabaseV1Queryable,
} from "@/utils";
type Props = {
readonly node: SQLEditorTreeNode;
readonly keyword: string;
readonly checked?: boolean;
readonly checkDisabled?: boolean;
readonly checkTooltip?: string;
readonly onCheckedChange?: (checked: boolean) => void;
};
/**
* Shows an optional batch-mode checkbox, an inline "Instance → Database"
* breadcrumb (engine icon + instance name, chevron, database name), and a
* RequestQueryButton when the current user can't query this database.
*
* The breadcrumb is purely presentational — clicks bubble to the parent
* row so the row-level handler (TreeRow → onConnect → connect()) runs.
* Only interactive children (checkbox, RequestQueryButton) stop
* propagation locally to avoid double-firing the row click.
*/
export function DatabaseNode({
node,
keyword,
checked,
checkDisabled,
checkTooltip,
onCheckedChange,
}: Props) {
const supportBatchMode = useSupportBatchMode();
const database = (node as SQLEditorTreeNode<"database">).meta.target;
const instance = getInstanceResource(database);
const databaseName = extractDatabaseResourceName(database.name).databaseName;
const canQuery = isDatabaseV1Queryable(database);
// Wrappers around interactive controls (checkbox / RequestQueryButton)
// are marked with `data-row-interactive` so the parent `TreeRow`'s
// mousedown-target check skips row activation when the press starts
// anywhere inside — including on a tooltip-trigger `<span>` that
// wraps a disabled control (which `closest('button')` misses because
// closest walks UP the DOM and the disabled `<button>` is a
// descendant of the span).
//
// We only stop `onClick` propagation here, NOT `mousedown`/`mouseup` —
// the row's mousedown listener needs to see the press to record that
// it started on an interactive child (so it can skip `onMouseUp`-driven
// row activation even when the cursor drifts off the wrapper before
// release). Stopping `onClick` is enough to keep checkbox clicks from
// leaking to ancestor React onClick handlers.
const checkbox = supportBatchMode ? (
<span data-row-interactive onClick={(e) => e.stopPropagation()}>
<Tooltip content={checkTooltip ?? ""}>
<Checkbox
checked={!!checked}
className="mr-2"
disabled={checkDisabled}
onCheckedChange={(checked) => onCheckedChange?.(checked)}
/>
</Tooltip>
</span>
) : null;
return (
<div className="flex items-center w-full max-w-full overflow-hidden gap-x-1">
{checkbox}
<div
className={cn(
"cursor-pointer tree-node-database",
"flex flex-row justify-start items-center gap-x-1 min-w-0"
)}
>
<div className="flex flex-row items-center gap-x-1 min-w-0">
<EngineIcon engine={instance.engine} className="size-4" />
<span className="truncate">{instanceV1Name(instance)}</span>
</div>
<ChevronRight className="size-3 shrink-0" />
<span className="truncate">
<HighlightLabelText text={databaseName} keyword={keyword} />
</span>
</div>
{!canQuery && (
<div
className="ml-auto shrink-0"
data-row-interactive
onClick={(e) => e.stopPropagation()}
>
<RequestQueryButton
size="sm"
text
permissionDeniedDetail={create(PermissionDeniedDetailSchema, {
resources: [database.name],
requiredPermissions: ["bb.sql.select"],
})}
/>
</div>
)}
</div>
);
}