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 { RefreshCcw } from "lucide-react";
import { useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { HumanizeTs } from "@/components/HumanizeTs";
import { Button } from "@/components/ui/button";
import { Tooltip } from "@/components/ui/tooltip";
import { cn } from "@/lib/utils";
import { useConnectionOfCurrentSQLEditorTab } from "@/modules/sql-editor/hooks/useSQLEditorState";
import { useAppStore } from "@/stores/app";
import { getTimeForPbTimestampProtoEs, isValidDatabaseName } from "@/types";
/**
* RefreshCcw button with a hover tooltip showing the last sync time +
* click-to-sync hint.
*
* - Disabled when the active tab has no valid database connection (no
* `database.name`) or while a sync is in flight.
* - On click, calls the app store's `syncDatabase(name, refresh=true)`,
* then `getOrFetchDatabaseMetadata({ skipCache: true })` so the
* SchemaPane reactively rebuilds with the fresh metadata.
* - Spinner: the icon spins while `isSyncing` is true.
*/
export function SyncSchemaButton({ className }: { className?: string }) {
const { t } = useTranslation();
const { database } = useConnectionOfCurrentSQLEditorTab();
const [isSyncing, setIsSyncing] = useState(false);
const disabled = !isValidDatabaseName(database.name);
const syncNow = async () => {
if (disabled) return;
setIsSyncing(true);
try {
const appStore = useAppStore.getState();
await appStore.syncDatabase(database.name, true);
await appStore.getOrFetchDatabaseMetadata({
database: database.name,
skipCache: true,
});
} finally {
setIsSyncing(false);
}
};
const lastSyncMs = getTimeForPbTimestampProtoEs(database.successfulSyncTime);
const button = (
<Button
appearance="outline"
size="sm"
type="button"
disabled={disabled || isSyncing}
onClick={syncNow}
className={cn("px-1.5", className)}
>
<RefreshCcw
className={cn(
"size-4",
isSyncing && "animate-[spin_2s_linear_infinite]"
)}
/>
</Button>
);
if (disabled) {
// No tooltip when disabled, so we don't surface a "last synced" tooltip
// with stale-looking placeholder data.
return button;
}
return (
<Tooltip
side="bottom"
content={
<div className="flex flex-col gap-1">
{lastSyncMs !== undefined ? (
<Trans
t={t}
i18nKey="sql-editor.last-synced"
components={{ time: <HumanizeTs tsMs={lastSyncMs} /> }}
/>
) : null}
<div>
{isSyncing
? t("sql-editor.sync-in-progress")
: t("sql-editor.click-to-sync-now")}
</div>
</div>
}
>
{button}
</Tooltip>
);
}