({
worksheet,
forceNewTab,
mode,
}: {
worksheet: string;
forceNewTab: boolean;
mode?: SQLEditorTabMode;
})
| 1108 | // ---- openWorksheetByName (unchanged behavior) ------------------------------ |
| 1109 | |
| 1110 | export const openWorksheetByName = async ({ |
| 1111 | worksheet, |
| 1112 | forceNewTab, |
| 1113 | mode, |
| 1114 | }: { |
| 1115 | worksheet: string; |
| 1116 | forceNewTab: boolean; |
| 1117 | mode?: SQLEditorTabMode; |
| 1118 | }) => { |
| 1119 | const sheet = await useAppStore |
| 1120 | .getState() |
| 1121 | .getOrFetchWorksheetByName(worksheet); |
| 1122 | if (!sheet) return undefined; |
| 1123 | |
| 1124 | if (!isWorksheetReadableV1(sheet)) { |
| 1125 | useAppStore.getState().notify({ |
| 1126 | module: "bytebase", |
| 1127 | style: "CRITICAL", |
| 1128 | title: i18n.t("common.access-denied"), |
| 1129 | }); |
| 1130 | return undefined; |
| 1131 | } |
| 1132 | |
| 1133 | const tabsState = getSQLEditorTabsState(); |
| 1134 | const openingSheetTab = (() => { |
| 1135 | for (const persisted of tabsState.openTmpTabList) { |
| 1136 | const tab = tabsState.tabsById.get(persisted.id); |
| 1137 | if (tab?.worksheet === sheet.name) return tab; |
| 1138 | } |
| 1139 | return undefined; |
| 1140 | })(); |
| 1141 | |
| 1142 | if (openingSheetTab && !forceNewTab) { |
| 1143 | tabsState.setCurrentTabId(openingSheetTab.id); |
| 1144 | if (mode && mode !== openingSheetTab.mode) { |
| 1145 | tabsState.updateTab(openingSheetTab.id, { mode }); |
| 1146 | } |
| 1147 | return openingSheetTab; |
| 1148 | } |
| 1149 | |
| 1150 | const statement = getSheetStatement(sheet); |
| 1151 | const connection = await extractWorksheetConnection(sheet); |
| 1152 | const newTab: Partial<SQLEditorTab> = { |
| 1153 | connection, |
| 1154 | worksheet: sheet.name, |
| 1155 | title: sheet.title, |
| 1156 | statement, |
| 1157 | status: "CLEAN", |
| 1158 | mode: mode ?? "WORKSHEET", |
| 1159 | }; |
| 1160 | |
| 1161 | return tabsState.addTab(newTab, forceNewTab /* beside */); |
| 1162 | }; |
| 1163 | |
| 1164 | // Touch the editor store import so it's eagerly evaluated alongside the |
| 1165 | // tab store (matches the historical Pinia-era load order). |
no test coverage detected