MCPcopy Index your code
hub / github.com/bytebase/bytebase / reloadFromStorage

Function reloadFromStorage

frontend/src/views/sql-editor/Sheet/context.ts:294–356  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

292 "showDraft" in v;
293
294const reloadFromStorage = () => {
295 const scope = currentScope();
296 if (!scope) return;
297
298 const filter = safeReadJSON(
299 storageKeySqlEditorWorksheetFilter(
300 scope.wsScope,
301 scope.project,
302 scope.email
303 ),
304 (v) => (isWorksheetFilter(v) ? v : undefined)
305 ) ?? { ...INITIAL_FILTER };
306
307 const expandedArray = safeReadJSON<string[]>(
308 storageKeySqlEditorWorksheetTree(scope.wsScope, scope.project, scope.email),
309 (v) =>
310 Array.isArray(v) && v.every((entry) => typeof entry === "string")
311 ? (v as string[])
312 : undefined
313 );
314 const expandedKeys = expandedArray
315 ? new Set(expandedArray)
316 : new Set<string>([
317 rootPathFor("my"),
318 rootPathFor("shared"),
319 rootPathFor("draft"),
320 ]);
321 expandedKeys.add(rootPathFor("my"));
322 expandedKeys.add(rootPathFor("shared"));
323 expandedKeys.add(rootPathFor("draft"));
324
325 const viewStates: Record<SheetViewMode, ViewState> = {
326 my: emptyViewState("my"),
327 shared: emptyViewState("shared"),
328 draft: emptyViewState("draft"),
329 };
330
331 for (const view of ["my", "shared", "draft"] as const) {
332 const folders = safeReadJSON<string[]>(
333 storageKeySqlEditorWorksheetFolder(
334 scope.wsScope,
335 scope.project,
336 view,
337 scope.email
338 ),
339 (v) =>
340 Array.isArray(v) && v.every((entry) => typeof entry === "string")
341 ? (v as string[])
342 : undefined
343 );
344 const set = new Set(folders ?? []);
345 set.add(rootPathFor(view));
346 viewStates[view].folders = sortBy([...set]);
347 }
348
349 useSheetContextStore.getState().hydrate({
350 filter,
351 expandedKeys,

Callers 1

bindWatchersFunction · 0.85

Calls 9

safeReadJSONFunction · 0.85
isWorksheetFilterFunction · 0.85
rootPathForFunction · 0.85
emptyViewStateFunction · 0.85
addMethod · 0.80
currentScopeFunction · 0.70

Tested by

no test coverage detected