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

Function hydrateProjectTabs

frontend/src/react/stores/sqlEditor/tab.ts:412–468  ·  view source on GitHub ↗
(project: string)

Source from the content-addressed store, hash-verified

410// it with in-flight dedup; uses the store's external setState/getState
411// (immer-enabled) rather than the action closure's set/get.
412const hydrateProjectTabs = async (project: string): Promise<void> => {
413 await migrateDraftsFromCache(project);
414 migrateTabViewState(project);
415
416 // Ensure the current user is loaded so tab storage is scoped to the
417 // right email — the SQL editor route doesn't otherwise populate it.
418 await useAppStore.getState().loadCurrentUser();
419 const state = useAppStore.getState();
420 const email = state.currentUser?.email ?? "";
421 const wsScope = workspaceCacheScope(
422 state.isSaaSMode(),
423 state.currentUser?.workspace ?? ""
424 );
425
426 const storedTabs = readOpenTabs(wsScope, project, email);
427
428 const hydratedTabs: SQLEditorTab[] = [];
429 const validPersistent: PersistentTab[] = [];
430 const seen = new Set<string>();
431
432 for (const persisted of storedTabs) {
433 if (seen.has(persisted.id)) continue;
434 if (!persisted.worksheet) continue;
435
436 const worksheet = await useAppStore
437 .getState()
438 .getOrFetchWorksheetByName(persisted.worksheet, true);
439 if (!worksheet) continue;
440
441 const statement = getSheetStatement(worksheet);
442 const connection = await extractWorksheetConnection(worksheet);
443
444 const fullTab: SQLEditorTab = {
445 ...defaultSQLEditorTab(),
446 ...omitBy(persisted, isUndefined),
447 connection,
448 worksheet: worksheet.name,
449 title: worksheet.title,
450 statement,
451 status: "CLEAN",
452 databaseQueryContexts: undefined,
453 };
454
455 seen.add(persisted.id);
456 validPersistent.push(persisted);
457 hydratedTabs.push(fullTab);
458 }
459
460 useSQLEditorTabsStore.setState({
461 tabsById: new Map(hydratedTabs.map((t) => [t.id, t])),
462 openTmpTabList: validPersistent,
463 currentTabId: head(validPersistent)?.id ?? "",
464 });
465
466 persistOpenTabs(validPersistent);
467 persistCurrentTabId(useSQLEditorTabsStore.getState().currentTabId);
468};
469

Callers 1

initProjectFunction · 0.85

Calls 10

migrateDraftsFromCacheFunction · 0.90
migrateTabViewStateFunction · 0.90
workspaceCacheScopeFunction · 0.90
getSheetStatementFunction · 0.90
defaultSQLEditorTabFunction · 0.90
readOpenTabsFunction · 0.85
persistOpenTabsFunction · 0.85
persistCurrentTabIdFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected