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

Function upsertOpenTabDraft

frontend/src/react/stores/sqlEditor/tab.ts:488–507  ·  view source on GitHub ↗
(
  state: { openTmpTabList: PersistentTab[]; currentTabId: string },
  tab: SQLEditorTab,
  beside: boolean
)

Source from the content-addressed store, hash-verified

486};
487
488const upsertOpenTabDraft = (
489 state: { openTmpTabList: PersistentTab[]; currentTabId: string },
490 tab: SQLEditorTab,
491 beside: boolean
492) => {
493 const persistent = pick(tab, ...PERSISTENT_TAB_FIELDS) as PersistentTab;
494 const position = state.openTmpTabList.findIndex((item) => item.id === tab.id);
495 if (position >= 0) {
496 Object.assign(state.openTmpTabList[position], persistent);
497 return;
498 }
499 const currentPosition = state.openTmpTabList.findIndex(
500 (item) => item.id === state.currentTabId
501 );
502 if (beside && currentPosition >= 0) {
503 state.openTmpTabList.splice(currentPosition + 1, 0, persistent);
504 } else {
505 state.openTmpTabList.push(persistent);
506 }
507};
508
509/**
510 * Direct (non-React) accessor. Mirrors Zustand's `getState()`.

Callers 2

addTabFunction · 0.85
updateTabFunction · 0.85

Calls 1

findIndexMethod · 0.45

Tested by

no test coverage detected