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

Function useDatabaseCatalog

frontend/src/react/hooks/useDatabaseCatalog.ts:18–52  ·  view source on GitHub ↗
(
  database: string,
  skipCache: boolean
)

Source from the content-addressed store, hash-verified

16// catalog (gated by permission) and reactively returns the cached entry,
17// falling back to a stable empty catalog so the selector never loops.
18export function useDatabaseCatalog(
19 database: string,
20 skipCache: boolean
21): DatabaseCatalog {
22 useEffect(() => {
23 if (
24 extractDatabaseResourceName(database).databaseName === String(UNKNOWN_ID)
25 ) {
26 return;
27 }
28 void (async () => {
29 const db = await useAppStore
30 .getState()
31 .getOrFetchDatabaseByName(database);
32 if (
33 hasProjectPermissionV2(
34 getDatabaseProject(db),
35 "bb.databaseCatalogs.get"
36 )
37 ) {
38 await useAppStore
39 .getState()
40 .getOrFetchDatabaseCatalog({ database, skipCache });
41 }
42 })();
43 }, [database, skipCache]);
44
45 const cached = useAppStore(
46 (state) => state.catalogsByName[catalogResourceName(database)]
47 );
48 return useMemo(
49 () => cached ?? emptyDatabaseCatalog(database),
50 [cached, database]
51 );
52}

Callers 4

DatabaseCatalogPanelFunction · 0.90
NoSQLCatalogEditorFunction · 0.90
DatabaseObjectExplorerFunction · 0.90
TableMetadataTableFunction · 0.90

Calls 6

hasProjectPermissionV2Function · 0.90
getDatabaseProjectFunction · 0.90
catalogResourceNameFunction · 0.90
emptyDatabaseCatalogFunction · 0.90
useAppStoreFunction · 0.50

Tested by

no test coverage detected