Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: migrate part of sheet logic to v1 api (#6239)
ecmadao413e4d9880be
diff --git a/frontend/src/components/Issue/IssueTaskStatementPanel.vue b/frontend/src/components/Issue/IssueTaskStatementPanel.vueindex 05082052db..df19d0eb0a 100644--- a/frontend/src/components/Issue/IssueTaskStatementPanel.vue+++ b/frontend/src/components/Issue/IssueTaskStatementPanel.vue@@ -130,6 +130,8 @@ import {useDBSchemaStore,useSheetStore,useUIStateStore,+ useDatabaseStore,+ useSheetV1Store,} from "@/store";import { useIssueLogic } from "./logic";import {@@ -137,7 +139,6 @@ import {dialectOfEngine,Issue,SheetCreate,- SheetId,SQLDialect,Task,TaskCreate,@@ -146,16 +147,17 @@ import {} from "@/types";import {getBacktracePayloadWithIssue,- sheetIdOfTask,+ sheetNameOfTask,useInstanceEditorLanguage,} from "@/utils";import { TableMetadata } from "@/types/proto/store/database";import MonacoEditor from "../MonacoEditor/MonacoEditor.vue";import { useSQLAdviceMarkers } from "./logic/useSQLAdviceMarkers";import UploadProgressButton from "../misc/UploadProgressButton.vue";+import { getSheetPathByLegacyProject } from "@/store/modules/v1/common";interface LocalState {- taskSheetId?: SheetId;+ taskSheetName?: string;editing: boolean;editStatement: string;isUploadingFile: boolean;@@ -195,6 +197,7 @@ const overrideSQLDialog = useDialog();const uiStateStore = useUIStateStore();const dbSchemaStore = useDBSchemaStore();const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const editorRef = ref<InstanceType<typeof MonacoEditor>>();const state = reactive<LocalState>({@@ -294,11 +297,17 @@ const useTempEditState = (state: LocalState) => {useTempEditState(state);-const getOrFetchSheetStatementById = async (sheetId: SheetId) => {- if (!sheetId || sheetId === UNKNOWN_ID) {+const getOrFetchSheetStatementByName = async (+ sheetName: string | undefined+) => {+ if (!sheetName) {return "";}- return (await sheetStore.getOrFetchSheetById(sheetId)).statement;+ const sheet = await sheetV1Store.getOrFetchSheetByName(sheetName);+ if (!sheet) {+ return "";+ }+ return new TextDecoder().decode(sheet.content);};const readonly = computed(() => {@@ -326,12 +335,17 @@ const formatOnSave = computed({const allowFormatOnSave = computed(() => language.value === "sql");const isTaskSheetOversize = computed(() => {- if (!state.taskSheetId || state.taskSheetId === UNKNOWN_ID) {+ if (!state.taskSheetName) {return false;}- const taskSheet = sheetStore.getSheetById(state.taskSheetId);- return taskSheet.statement.length < taskSheet.size;+ const taskSheet = sheetV1Store.getSheetByName(state.taskSheetName);+ if (!taskSheet) {+ return false;+ }+ return (+ new TextDecoder().decode(taskSheet.content).length < taskSheet.contentSize+ );});const shouldShowStatementEditButtonForUI = computed(() => {@@ -356,9 +370,9 @@ onMounted(async () => {if (create.value) {state.editing = true;} else {- const sheetId = sheetIdOfTask(selectedTask.value as Task);- if (sheetId && sheetId !== UNKNOWN_ID) {- state.taskSheetId = sheetId;+ const sheetName = sheetNameOfTask(selectedTask.value as Task);+ if (sheetName) {+ state.taskSheetName = sheetName;}}});@@ -382,13 +396,25 @@ watch(selectedTask,async () => {const task = selectedTask.value;- const sheetId = create.value- ? (task as TaskCreate).sheetId- : sheetIdOfTask(task as Task);- if (sheetId && sheetId !== UNKNOWN_ID) {- state.taskSheetId = sheetId;++ // TODO: remove legacy logic.+ let sheetName;+ if (create.value) {+ const taskCreate = task as TaskCreate;+ if (taskCreate.databaseId) {+ const db = await useDatabaseStore().getOrFetchDatabaseById(+ taskCreate.databaseId+ );+ sheetName = getSheetPathByLegacyProject(db.project, taskCreate.sheetId);+ }+ } else {+ sheetName = sheetNameOfTask(task as Task);+ }++ if (sheetName) {+ state.taskSheetName = sheetName;} else {- state.taskSheetId = undefined;+ state.taskSheetName = undefined;}},{@@ -398,11 +424,11 @@ watch();watch(- () => state.taskSheetId,+ () => state.taskSheetName,async () => {- if (state.taskSheetId && state.taskSheetId !== UNKNOWN_ID) {- state.editStatement = await getOrFetchSheetStatementById(- state.taskSheetId+ if (state.taskSheetName) {+ state.editStatement = await getOrFetchSheetStatementByName(+ state.taskSheetName);}},@@ -427,8 +453,8 @@ const saveEdit = async () => {};const cancelEdit = async () => {- state.editStatement = await getOrFetchSheetStatementById(- state.taskSheetId || UNKNOWN_ID+ state.editStatement = await getOrFetchSheetStatementByName(+ state.taskSheetName);state.editing = false;};diff --git a/frontend/src/components/Issue/activity/ActionSentence.vue b/frontend/src/components/Issue/activity/ActionSentence.vueindex 01b7888a94..376a8211b9 100644--- a/frontend/src/components/Issue/activity/ActionSentence.vue+++ b/frontend/src/components/Issue/activity/ActionSentence.vue@@ -24,7 +24,7 @@ import {findTaskById,issueActivityActionSentence,} from "@/utils";-import { useSheetStore } from "@/store";+import { useSheetStore, useSheetById } from "@/store";import TaskName from "./TaskName.vue";import SQLPreviewPopover from "@/components/misc/SQLPreviewPopover.vue";import StageName from "./StageName.vue";@@ -184,10 +184,10 @@ const renderActionSentence = () => {case "bb.pipeline.task.statement.update": {const payload = activity.payload as ActivityTaskStatementUpdatePayload;const oldStatement =- sheetStore.getSheetById(payload.oldSheetId || UNKNOWN_ID).statement ||+ useSheetById(payload.oldSheetId || UNKNOWN_ID).value.statement ||payload.oldStatement;const newStatement =- sheetStore.getSheetById(payload.newSheetId || UNKNOWN_ID).statement ||+ useSheetById(payload.newSheetId || UNKNOWN_ID).value.statement ||payload.newStatement;return h("span",diff --git a/frontend/src/components/Issue/logic/GhostModeProvider.ts b/frontend/src/components/Issue/logic/GhostModeProvider.tsindex 6498323c41..333cbad943 100644--- a/frontend/src/components/Issue/logic/GhostModeProvider.ts+++ b/frontend/src/components/Issue/logic/GhostModeProvider.ts@@ -18,7 +18,12 @@ import {SheetId,UNKNOWN_ID,} from "@/types";-import { useDatabaseStore, useSheetStore, useTaskStore } from "@/store";+import {+ useDatabaseStore,+ useSheetStore,+ useSheetById,+ useTaskStore,+} from "@/store";import { sheetIdOfTask } from "@/utils";export default defineComponent({@@ -37,7 +42,6 @@ export default defineComponent({} = useIssueLogic();const databaseStore = useDatabaseStore();const taskStore = useTaskStore();- const sheetStore = useSheetStore();const selectedStatement = computed(() => {if (isTenantMode.value) {@@ -46,15 +50,14 @@ export default defineComponent({const issueCreate = issue.value as IssueCreate;const context = issueCreate.createContext as MigrationContext;return (- sheetStore.getSheetById(context.detailList[0].sheetId)?.statement ||- ""+ useSheetById(context.detailList[0].sheetId).value?.statement || "");} else {const issueEntity = issue.value as Issue;const task = issueEntity.pipeline.stageList[0].taskList[0];const payload =task.payload as TaskDatabaseSchemaUpdateGhostSyncPayload;- return sheetStore.getSheetById(payload.sheetId)?.statement || "";+ return useSheetById(payload.sheetId).value?.statement || "";}} else {// In standard pipeline, each ghost-sync task can hold its own@@ -65,13 +68,13 @@ export default defineComponent({let statement = (task as TaskCreate).statement;if ((task as TaskCreate).sheetId !== UNKNOWN_ID) {statement =- sheetStore.getSheetById((task as TaskCreate).sheetId)- ?.statement || "";+ useSheetById((task as TaskCreate).sheetId).value?.statement ||+ "";}return statement;} else {return (- sheetStore.getSheetById(sheetIdOfTask(task as Task) || UNKNOWN_ID)+ useSheetById(sheetIdOfTask(task as Task) || UNKNOWN_ID).value?.statement || "");}diff --git a/frontend/src/components/Issue/logic/TenantModeProvider.ts b/frontend/src/components/Issue/logic/TenantModeProvider.tsindex efd91d14b4..a731c38c26 100644--- a/frontend/src/components/Issue/logic/TenantModeProvider.ts+++ b/frontend/src/components/Issue/logic/TenantModeProvider.ts@@ -1,6 +1,11 @@import { computed, defineComponent } from "vue";import { cloneDeep, head } from "lodash-es";-import { useDatabaseStore, useSheetStore, useTaskStore } from "@/store";+import {+ useDatabaseStore,+ useSheetStore,+ useTaskStore,+ useSheetById,+} from "@/store";import {Issue,IssueCreate,@@ -50,9 +55,8 @@ export default defineComponent({const payload = task.payload as TaskDatabaseSchemaUpdatePayload;const selectedTaskSheetId = sheetIdOfTask(selectedTask.value as Task);return (- useSheetStore().getSheetById(- selectedTaskSheetId || payload.sheetId || UNKNOWN_ID- )?.statement || ""+ useSheetById(selectedTaskSheetId || payload.sheetId || UNKNOWN_ID)+ .value?.statement || "");}});diff --git a/frontend/src/components/Issue/logic/base.ts b/frontend/src/components/Issue/logic/base.tsindex dc69b44e11..5060c52a2b 100644--- a/frontend/src/components/Issue/logic/base.ts+++ b/frontend/src/components/Issue/logic/base.ts@@ -29,6 +29,7 @@ import {useIssueStore,useProjectV1Store,useSheetStore,+ useSheetById,} from "@/store";import { flattenTaskList, TaskTypeWithStatement } from "./common";import { maybeCreateBackTraceComments } from "../rollback/common";@@ -229,12 +230,12 @@ export const useBaseIssueLogic = (params: {if (create.value) {const taskCreate = task as TaskCreate;if (taskCreate.sheetId && taskCreate.sheetId !== UNKNOWN_ID) {- return sheetStore.getSheetById(taskCreate.sheetId)?.statement || "";+ return useSheetById(taskCreate.sheetId).value?.statement || "";}return (task as TaskCreate).statement;}return (- sheetStore.getSheetById(sheetIdOfTask(task as Task) || UNKNOWN_ID)+ useSheetById(sheetIdOfTask(task as Task) || UNKNOWN_ID).value?.statement || "");});diff --git a/frontend/src/components/Issue/logic/common.ts b/frontend/src/components/Issue/logic/common.tsindex c2449cde2d..71db32567d 100644--- a/frontend/src/components/Issue/logic/common.ts+++ b/frontend/src/components/Issue/logic/common.ts@@ -247,7 +247,7 @@ export const useCommonLogic = () => {};// Create a new sheet to save statement.if (!taskCreate.sheetId || taskCreate.sheetId === UNKNOWN_ID) {- const sheet = await useSheetStore().createSheet({+ const sheet = await sheetStore.createSheet({projectId: issueCreate.projectId,name: issueCreate.name + " - " + db.name,statement: statement,@@ -258,7 +258,7 @@ export const useCommonLogic = () => {migrationDetail.sheetId = sheet.id;} else {const sheetId = taskCreate.sheetId;- const sheet = sheetStore.getSheetById(sheetId);+ const sheet = await sheetStore.getOrFetchSheetById(sheetId);if (sheet.statement.length === sheet.size) {await sheetStore.patchSheetById({id: sheetId,diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vueindex 88518c747e..d6830534a8 100644--- a/frontend/src/components/ProvideSQLEditorContext.vue+++ b/frontend/src/components/ProvideSQLEditorContext.vue@@ -10,13 +10,14 @@ import {useDatabaseStore,useSQLEditorStore,useTabStore,- useSheetStore,useDebugStore,useInstanceStore,pushNotification,useConnectionTreeStore,useProjectV1Store,useCurrentUserV1,+ useSheetV1Store,+ useInstanceV1Store,} from "@/store";import {Connection,@@ -30,9 +31,10 @@ import { ConnectionTreeState, UNKNOWN_ID, DEFAULT_PROJECT_ID } from "@/types";import {emptyConnection,idFromSlug,- sheetSlug as makeSheetSlug,+ sheetNameFromSlug,+ sheetSlugV1,connectionSlug as makeConnectionSlug,- isSheetReadable,+ isSheetReadableV1,isDatabaseAccessible,getDefaultTabNameFromConnection,isSimilarTab,@@ -45,6 +47,7 @@ import {PolicyResourceType,} from "@/types/proto/v1/org_policy_service";import { useSettingV1Store } from "@/store/modules/v1/setting";+import { getInstanceAndDatabaseId } from "@/store/modules/v1/common";const route = useRoute();const router = useRouter();@@ -57,7 +60,7 @@ const policyV1Store = usePolicyV1Store();const sqlEditorStore = useSQLEditorStore();const connectionTreeStore = useConnectionTreeStore();const tabStore = useTabStore();-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const prepareAccessControlPolicy = async () => {connectionTreeStore.accessControlPolicyList =@@ -180,29 +183,27 @@ const prepareConnectionTree = async () => {const prepareSheet = async () => {const sheetSlug = (route.params.sheetSlug as string) || "";- const sheetId = idFromSlug(sheetSlug);- if (Number.isNaN(sheetId)) {- return false;- }++ const sheetName = sheetNameFromSlug(sheetSlug);const openingSheetTab = tabStore.tabList.find(- (tab) => tab.sheetId === sheetId+ (tab) => tab.sheetName == sheetName);sqlEditorStore.isFetchingSheet = true;- const sheet = await sheetStore.getOrFetchSheetById(sheetId);+ const sheet = await sheetV1Store.getOrFetchSheetByName(sheetName);sqlEditorStore.isFetchingSheet = false;- if (sheet.id === UNKNOWN_ID) {+ if (!sheet) {if (openingSheetTab) {// If a sheet is open in a tab but it returns 404 NOT_FOUND// that means the sheet has been deleted somewhere else.// We need to turn the sheet to an unsaved tab.- openingSheetTab.sheetId = undefined;+ openingSheetTab.sheetName = undefined;openingSheetTab.isSaved = false;}return false;}- if (!isSheetReadable(sheet)) {+ if (!isSheetReadableV1(sheet)) {pushNotification({module: "bytebase",style: "CRITICAL",@@ -216,15 +217,30 @@ const prepareSheet = async () => {} else {// Open the sheet in a "temp" tab otherwise.tabStore.selectOrAddTempTab();++ let insId = UNKNOWN_ID,+ dbId = UNKNOWN_ID;+ if (sheet.database) {+ const [instanceName, databaseId] = getInstanceAndDatabaseId(+ sheet.database+ );+ const ins = await useInstanceV1Store().getOrFetchInstanceByName(+ `instances/${instanceName}`+ );+ insId = Number(ins.uid);+ dbId = Number(databaseId);+ }+tabStore.updateCurrentTab({- sheetId: sheet.id,+ sheetName,name: sheet.name,- statement: sheet.statement,+ statement: new TextDecoder().decode(sheet.content),isSaved: true,connection: {...emptyConnection(),- instanceId: sheet.database?.instanceId || UNKNOWN_ID,- databaseId: sheet.databaseId || UNKNOWN_ID,+ // TODO: legacy instance id.+ instanceId: insId,+ databaseId: dbId,},});}@@ -244,7 +260,7 @@ const prepareConnectionSlug = async () => {const connect = (connection: Connection) => {const tab = tabStore.currentTab;- if (tab.sheetId) {+ if (tab.sheetName) {// Don't touch a saved sheet.tabStore.selectOrAddTempTab();return;@@ -315,22 +331,22 @@ const syncURLWithConnection = () => {[() => connection.value.instanceId,() => connection.value.databaseId,- () => tabStore.currentTab.sheetId,+ () => tabStore.currentTab.sheetName,],- ([instanceId, databaseId, sheetId]) => {- if (sheetId && sheetId !== UNKNOWN_ID) {- const sheet = sheetStore.sheetById.get(sheetId);+ ([instanceId, databaseId, sheetName]) => {+ if (sheetName) {+ const sheet = sheetV1Store.getSheetByName(sheetName);if (sheet) {router.replace({name: "sql-editor.share",params: {- sheetSlug: makeSheetSlug(sheet),+ sheetSlug: sheetSlugV1(sheet),},});} else {// A sheet is not found, fallback to an unsaved tab.tabStore.updateCurrentTab({- sheetId: undefined,+ sheetName: undefined,isSaved: false,});}diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex f68e0bd49a..98c537cdcd 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -27,6 +27,7 @@ import {hasPermissionInProjectV1,hasWorkspacePermissionV1,idFromSlug,+ sheetNameFromSlug,migrationHistoryIdFromSlug,roleListInProjectV1,} from "../utils";@@ -41,7 +42,7 @@ import {useDataSourceStore,useSQLReviewStore,useLegacyProjectStore,- useSheetStore,+ useSheetV1Store,useAuthStore,useActuatorStore,useDatabaseStore,@@ -1612,9 +1613,9 @@ router.beforeEach((to, from, next) => {}if (sheetSlug) {- const sheetId = idFromSlug(sheetSlug);- useSheetStore()- .fetchSheetById(sheetId)+ const sheetName = sheetNameFromSlug(sheetSlug);+ useSheetV1Store()+ .fetchSheetByName(sheetName).then(() => next()).catch(() => next());return;diff --git a/frontend/src/store/modules/sheet.ts b/frontend/src/store/modules/sheet.tsindex 9f3d056e73..029c073c7c 100644--- a/frontend/src/store/modules/sheet.ts+++ b/frontend/src/store/modules/sheet.ts@@ -1,6 +1,6 @@import { defineStore } from "pinia";+import { computed, unref, watchEffect } from "vue";import axios, { type AxiosRequestConfig } from "axios";-import { isEmpty } from "lodash-es";import {Sheet,SheetId,@@ -14,20 +14,14 @@ import {UNKNOWN_ID,SheetCreate,SheetOrganizerUpsert,- ProjectId,SheetUpsert,SheetPayload,+ MaybeRef,} from "@/types";import { getPrincipalFromIncludedList } from "./principal";-import { useCurrentUserV1 } from "./auth";import { useDatabaseStore } from "./database";import { useLegacyProjectStore } from "./project";-import { useTabStore } from "./tab";-import {- extractUserUID,- getDefaultSheetPayloadWithSource,- isSheetWritable,-} from "@/utils";+import { getDefaultSheetPayloadWithSource } from "@/utils";function convertSheetPayload(resourceObj: ResourceObject,@@ -92,59 +86,6 @@ export const useSheetStore = defineStore("sheet", {sheetById: new Map(),}),- getters: {- currentSheet(state) {- const currentTab = useTabStore().currentTab;-- if (!currentTab || isEmpty(currentTab)) {- return unknown("SHEET");- }-- const sheetId = currentTab.sheetId || UNKNOWN_ID;-- return state.sheetById.get(sheetId) || unknown("SHEET");- },- isCreator() {- const currentUserV1 = useCurrentUserV1();- const currentSheet = this.currentSheet as Sheet;-- if (!currentSheet) return false;-- return (- extractUserUID(currentUserV1.value.name) ===- String(currentSheet.creator.id)- );- },- /**- * Check the sheet whether is read-only.- * 1. If the sheet is not created yet, it cannot be edited.- * 2. If the sheet is created by the current user, it can be edited.- * 3. If the sheet is created by other user, will be checked the visibility of the sheet.- * a) If the sheet's visibility is private or public, it can be edited only if the current user is the creator of the sheet.- * b) If the sheet's visibility is project, will be checked whether the current user is the `OWNER` of the project, only the current user is the `OWNER` of the project, it can be edited.- */- isReadOnly() {- const currentSheet = this.currentSheet as Sheet;-- // We don't have a selected sheet, we've got nothing to edit.- if (!currentSheet) {- return true;- }-- // The tab is not saved yet, it is editable.- if (currentSheet.id === UNKNOWN_ID) {- return false;- }-- // Incomplete sheets should be read-only. e.g. 100MB sheet from issue task.- if (currentSheet.statement.length !== currentSheet.size) {- return true;- }-- return !isSheetWritable(currentSheet);- },- },-actions: {getSheetById(sheetId: SheetId) {const sheet = this.sheetById.get(sheetId);@@ -267,20 +208,16 @@ export const useSheetStore = defineStore("sheet", {},});},- async deleteSheetById(sheetId: SheetId) {- await axios.delete(`/api/sheet/${sheetId}`);-- const idx = this.sheetList.findIndex((sheet) => sheet.id === sheetId);- if (idx !== -1) {- this.sheetList.splice(idx, 1);- }-- if (this.sheetById.has(sheetId)) {- this.sheetById.delete(sheetId);- }- },- async syncSheetFromVCS(projectId: ProjectId) {- await axios.post(`/api/project/${projectId}/sync-sheet`);- },},});++export const useSheetById = (sheetId: MaybeRef<SheetId>) => {+ const store = useSheetStore();+ watchEffect(async () => {+ await store.getOrFetchSheetById(unref(sheetId));+ });++ return computed(() => {+ return store.getSheetById(unref(sheetId));+ });+};diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.tsindex fdccf9546a..a3e5f0401c 100644--- a/frontend/src/store/modules/tab.ts+++ b/frontend/src/store/modules/tab.ts@@ -12,7 +12,7 @@ import {WebStorageHelper,} from "@/utils";import { useInstanceStore } from "./instance";-import { useSheetStore } from "./sheet";+import { useSheetV1Store } from "./v1/sheet";import { useWebTerminalStore } from "./webTerminal";const LOCAL_STORAGE_KEY_PREFIX = "bb.sql-editor.tab-list";@@ -31,7 +31,7 @@ const PERSISTENT_TASK_FIELDS = ["isSaved","savedAt","statement",- "sheetId",+ "sheetName","mode",] as const;type PersistentTaskInfo = Pick<TabInfo, typeof PERSISTENT_TASK_FIELDS[number]>;@@ -216,10 +216,10 @@ export const useTabStore = defineStore("tab", () => {});// Fetch opening sheets if needed- const sheetStore = useSheetStore();+ const sheetV1Store = useSheetV1Store();tabList.value.forEach((tab) => {- if (tab.sheetId && tab.sheetId !== UNKNOWN_ID) {- sheetStore.getOrFetchSheetById(tab.sheetId);+ if (tab.sheetName) {+ sheetV1Store.getOrFetchSheetByName(tab.sheetName);}});diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.tsindex 91d6156f88..25a52181f2 100644--- a/frontend/src/store/modules/v1/common.ts+++ b/frontend/src/store/modules/v1/common.ts@@ -3,7 +3,9 @@ import {UNKNOWN_ID,Instance,Database,+ Project,Environment,+ SheetId,} from "@/types";export const userNamePrefix = "users/";@@ -50,15 +52,24 @@ export const getProjectAndSheetId = (name: string): string[] => {sheetNamePrefix,]);+ if (tokens.length != 2) {+ return ["", ""];+ }+return tokens;};-export const getDatabaseId = (name: string): string => {- const sections = name.split(databaseNamePrefix);- if (sections.length != 2) {- return "";+export const getInstanceAndDatabaseId = (name: string): string[] => {+ const tokens = getNameParentTokens(name, [+ instanceNamePrefix,+ databaseNamePrefix,+ ]);++ if (tokens.length != 2) {+ return ["", ""];}- return sections[1];++ return tokens;};export const getUserEmailFromIdentifier = (identifier: string): string => {@@ -85,3 +96,10 @@ export const getDatabasePathByLegacyDatabase = (database: Database): string => {database.instance)}/${databaseNamePrefix}${database.name}`;};++export const getSheetPathByLegacyProject = (+ project: Project,+ sheetId: SheetId+): string => {+ return `${projectNamePrefix}${project.resourceId}/${sheetNamePrefix}${sheetId}`;+};diff --git a/frontend/src/store/modules/v1/index.ts b/frontend/src/store/modules/v1/index.tsindex 833758251e..960f0c8ffe 100644--- a/frontend/src/store/modules/v1/index.ts+++ b/frontend/src/store/modules/v1/index.ts@@ -4,3 +4,7 @@ export * from "./projectIamPolicy";export * from "./projectWebhook";export * from "./deploymentConfig";export * from "./databaseSecret";+export * from "./sheet";+export * from "./policy";+export * from "./setting";+export * from "./instance";diff --git a/frontend/src/store/modules/v1/sheet.ts b/frontend/src/store/modules/v1/sheet.tsindex 87eba1ca3e..098f3db8c8 100644--- a/frontend/src/store/modules/v1/sheet.ts+++ b/frontend/src/store/modules/v1/sheet.ts@@ -3,14 +3,8 @@ import { sheetServiceClient } from "@/grpcweb";import { isEqual, isUndefined, isEmpty } from "lodash-es";import { Sheet } from "@/types/proto/v1/sheet_service";import { useTabStore } from "../tab";-import { SheetId, UNKNOWN_ID } from "@/types";import { useCurrentUserV1 } from "../auth";-import {- getUserEmailFromIdentifier,- sheetNamePrefix,- projectNamePrefix,- getProjectAndSheetId,-} from "./common";+import { getUserEmailFromIdentifier, projectNamePrefix } from "./common";import { isSheetReadableV1 } from "@/utils";interface SheetState {@@ -30,14 +24,11 @@ export const useSheetV1Store = defineStore("sheet_v1", {return;}- // TODO: use resource id instead- const sheetId = currentTab.sheetId || UNKNOWN_ID;- for (const [_, sheet] of state.sheetByName) {- const [_, uid] = getProjectAndSheetId(sheet.name);- if (uid == sheetId) {- return sheet;- }+ const sheetName = currentTab.sheetName;+ if (!sheetName) {+ return;}+ return state.sheetByName.get(sheetName);},isCreator() {const currentUserV1 = useCurrentUserV1();@@ -89,18 +80,26 @@ export const useSheetV1Store = defineStore("sheet_v1", {this.sheetByName.set(createdSheet.name, createdSheet);return createdSheet;},- async upsertSheet(parentPath: string, sheet: Partial<Sheet>) {- if (sheet.name) {- const exist = this.sheetByName.get(sheet.name);- if (!exist) {- return;- }- return this.patchSheetById(getUpdateMaskForSheet(exist, sheet), sheet);+ async patchSheet(sheet: Partial<Sheet>) {+ if (!sheet.name) {+ return;+ }+ const exist = this.sheetByName.get(sheet.name);+ if (!exist) {+ return;}- return this.createSheet(parentPath, sheet);+ const updatedSheet = await this.patchSheetWithUpdateMask(+ getUpdateMaskForSheet(exist, sheet),+ sheet+ );+ this.sheetByName.set(updatedSheet.name, updatedSheet);+ return updatedSheet;},- async patchSheetById(updateMask: string[], sheet: Partial<Sheet>) {+ async patchSheetWithUpdateMask(+ updateMask: string[],+ sheet: Partial<Sheet>+ ) {const updatedSheet = await sheetServiceClient.updateSheet({sheet,updateMask,@@ -108,35 +107,27 @@ export const useSheetV1Store = defineStore("sheet_v1", {this.sheetByName.set(updatedSheet.name, updatedSheet);return updatedSheet;},- async fetchSheetById({- parentPath,- sheetId,- }: {- parentPath: string;- sheetId: SheetId;- }) {- const sheet = await sheetServiceClient.getSheet({- name: `${parentPath}/${sheetNamePrefix}${sheetId}`,- });- this.sheetByName.set(sheet.name, sheet);+ async fetchSheetByName(name: string) {+ try {+ const sheet = await sheetServiceClient.getSheet({+ name,+ });+ this.sheetByName.set(sheet.name, sheet);+ return sheet;+ } catch {+ return;+ }+ },+ getSheetByName(name: string) {+ const sheet = this.sheetByName.get(name);return sheet;},- async getOrFetchSheetById({- parentPath,- sheetId,- }: {- parentPath: string;- sheetId: SheetId;- }) {- const name = `${parentPath}/${sheetNamePrefix}${sheetId}`;+ async getOrFetchSheetByName(name: string) {const storedSheet = this.sheetByName.get(name);if (storedSheet) {return storedSheet;}- return this.fetchSheetById({- parentPath,- sheetId,- });+ return this.fetchSheetByName(name);},async fetchSharedSheetList() {const currentUserV1 = useCurrentUserV1();diff --git a/frontend/src/types/sheet.ts b/frontend/src/types/sheet.tsindex 4f98785581..b02e479d2e 100644--- a/frontend/src/types/sheet.ts+++ b/frontend/src/types/sheet.ts@@ -9,6 +9,7 @@ import {PrincipalId,IssueId,} from ".";+import { Sheet_Visibility } from "@/types/proto/v1/sheet_service";export type SheetVisibility = "PRIVATE" | "PROJECT" | "PUBLIC";@@ -111,5 +112,5 @@ export interface SheetPatch {export type AccessOption = {label: string;description: string;- value: SheetVisibility;+ value: Sheet_Visibility;};diff --git a/frontend/src/types/tab.ts b/frontend/src/types/tab.tsindex 813597b462..ac6cbc2b0f 100644--- a/frontend/src/types/tab.ts+++ b/frontend/src/types/tab.ts@@ -1,10 +1,4 @@-import {- Advice,- DatabaseId,- InstanceId,- SheetId,- SQLResultSet,-} from "../types";+import { Advice, DatabaseId, InstanceId, SQLResultSet } from "../types";export type ExecuteConfig = {databaseType: string;@@ -43,9 +37,9 @@ export interface TabInfo {};isExecutingSQL: boolean;queryResult?: SQLResultSet;- sheetId?: SheetId;+ sheetName?: string;adviceList?: Advice[];}-export type CoreTabInfo = Pick<TabInfo, "connection" | "sheetId" | "mode">;+export type CoreTabInfo = Pick<TabInfo, "connection" | "sheetName" | "mode">;export type AnyTabInfo = Partial<TabInfo>;diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.tsindex 49bd179cf3..367d268b1b 100644--- a/frontend/src/utils/index.ts+++ b/frontend/src/utils/index.ts@@ -18,7 +18,6 @@ export * from "./tab";export * from "./task";export * from "./policy";export * from "./sheet";-export * from "./sheetV1";export * from "./pev2";export * from "./web-storage";export * from "./dom";diff --git a/frontend/src/utils/sheet.ts b/frontend/src/utils/sheet.tsindex 2e1890f0ce..a100e009d6 100644--- a/frontend/src/utils/sheet.ts+++ b/frontend/src/utils/sheet.ts@@ -1,6 +1,6 @@import { isUndefined, uniq } from "lodash-es";-import { useCurrentUserV1, useProjectV1Store, useSheetStore } from "@/store";+import { useSheetStore } from "@/store";import {Issue,Sheet,@@ -15,96 +15,8 @@ import {TaskDatabaseSchemaUpdatePayload,TaskDatabaseSchemaUpdateSDLPayload,} from "@/types";-import {- extractUserUID,- hasPermissionInProjectV1,- hasWorkspacePermissionV1,- isMemberOfProjectV1,-} from "../utils";import { flattenTaskList } from "@/components/Issue/logic";-export const isSheetReadable = (sheet: Sheet) => {- const currentUserV1 = useCurrentUserV1();-- // readable to- // PRIVATE: the creator only- // PROJECT: the creator and members in the project, workspace Owner and DBA- // PUBLIC: everyone-- if (String(sheet.creator.id) === extractUserUID(currentUserV1.value.name)) {- // Always readable to the creator- return true;- }- const { visibility } = sheet;- if (visibility === "PRIVATE") {- return false;- }- if (visibility === "PROJECT") {- if (- hasWorkspacePermissionV1(- "bb.permission.workspace.manage-project",- currentUserV1.value.userRole- )- ) {- return true;- }-- const projectV1 = useProjectV1Store().getProjectByUID(- String(sheet.project.id)- );- return isMemberOfProjectV1(projectV1.iamPolicy, currentUserV1.value);- }- // visibility === "PUBLIC"- return true;-};--export const isSheetWritable = (sheet: Sheet) => {- // If the sheet is linked to an issue, it's NOT writable- if (getSheetIssueBacktracePayload(sheet)) {- return false;- }-- const currentUserV1 = useCurrentUserV1();-- // writable to- // PRIVATE: the creator only- // PROJECT: the creator or project role can manage sheet, workspace Owner and DBA- // PUBLIC: the creator only-- if (String(sheet.creator.id) === extractUserUID(currentUserV1.value.name)) {- // Always writable to the creator- return true;- }- const { visibility } = sheet;- if (visibility === "PRIVATE") {- return false;- }- if (visibility === "PROJECT") {- if (- hasWorkspacePermissionV1(- "bb.permission.workspace.manage-project",- currentUserV1.value.userRole- )- ) {- return true;- }-- const projectV1 = useProjectV1Store().getProjectByUID(- String(sheet.project.id)- );- const isCurrentUserProjectOwner = () => {- return hasPermissionInProjectV1(- projectV1.iamPolicy,- currentUserV1.value,- "bb.permission.project.manage-sheet"- );- };- return isCurrentUserProjectOwner();- }- // visibility === "PUBLIC"- return false;-};-// getDefaultSheetPayloadWithSource gets the default payload with sheet source.export const getDefaultSheetPayloadWithSource = (sheetSource: SheetSourcediff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.tsindex 45b9be44d4..5753866673 100644--- a/frontend/src/utils/slug.ts+++ b/frontend/src/utils/slug.ts@@ -9,18 +9,28 @@ import {Project,VCS,SQLReviewPolicy,- Sheet,UNKNOWN_ID,} from "../types";import { IdType } from "../types/id";import { Sheet as SheetV1 } from "@/types/proto/v1/sheet_service";-import { getProjectAndSheetId } from "@/store/modules/v1/common";+import {+ getProjectAndSheetId,+ projectNamePrefix,+ sheetNamePrefix,+} from "@/store/modules/v1/common";export function idFromSlug(slug: string): IdType {const parts = slug.split("-");return parseInt(parts[parts.length - 1]);}+export function sheetNameFromSlug(slug: string): string {+ const parts = slug.split("-");+ return `${projectNamePrefix}${parts+ .slice(0, -1)+ .join("-")}/${sheetNamePrefix}${parts[parts.length - 1]}`;+}+export function migrationHistoryIdFromSlug(slug: string): MigrationHistoryId {const parts = slug.split("-");return parts[parts.length - 1];@@ -98,11 +108,7 @@ export function connectionSlug(return parts.join("_");}-export function sheetSlug(sheet: Sheet): string {- return [slug(sheet.name), sheet.id].join("-");-}-export function sheetSlugV1(sheet: SheetV1): string {- const [_, uid] = getProjectAndSheetId(sheet.name);- return [slug(sheet.title), uid].join("-");+ const [projectName, uid] = getProjectAndSheetId(sheet.name);+ return [projectName, uid].join("-");}diff --git a/frontend/src/utils/tab.ts b/frontend/src/utils/tab.tsindex 2cd2db723e..723e398409 100644--- a/frontend/src/utils/tab.ts+++ b/frontend/src/utils/tab.ts@@ -33,7 +33,7 @@ export const getDefaultTab = (): TabInfo => {export const INITIAL_TAB = getDefaultTab();export const isTempTab = (tab: TabInfo): boolean => {- if (tab.sheetId) return false;+ if (tab.sheetName) return false;if (!tab.isSaved) return false;if (tab.statement) return false;return true;@@ -46,7 +46,7 @@ export const isSameConnection = (a: Connection, b: Connection): boolean => {export const isSimilarTab = (a: CoreTabInfo, b: CoreTabInfo): boolean => {return (isSameConnection(a.connection, b.connection) &&- a.sheetId === b.sheetId &&+ a.sheetName === b.sheetName &&a.mode === b.mode);};diff --git a/frontend/src/utils/v1/index.ts b/frontend/src/utils/v1/index.tsindex 10a51a5577..bb3ed37498 100644--- a/frontend/src/utils/v1/index.ts+++ b/frontend/src/utils/v1/index.ts@@ -5,3 +5,4 @@ export * from "./deploymentConfig";export * from "./label";export * from "./role";export * from "./user";+export * from "./sheet";diff --git a/frontend/src/utils/sheetV1.ts b/frontend/src/utils/v1/sheet.tssimilarity index 69%rename from frontend/src/utils/sheetV1.tsrename to frontend/src/utils/v1/sheet.tsindex 38522269c5..ac9a433976 100644--- a/frontend/src/utils/sheetV1.ts+++ b/frontend/src/utils/v1/sheet.ts@@ -1,16 +1,26 @@import { isUndefined } from "lodash-es";import { useCurrentUserV1, useProjectV1Store } from "@/store";-import { SheetIssueBacktracePayload } from "@/types";+import {+ Task,+ SheetIssueBacktracePayload,+ TaskDatabaseCreatePayload,+ TaskDatabaseDataUpdatePayload,+ TaskDatabaseSchemaUpdateGhostSyncPayload,+ TaskDatabaseSchemaUpdatePayload,+ TaskDatabaseSchemaUpdateSDLPayload,+ SheetId,+} from "@/types";import {hasPermissionInProjectV1,hasWorkspacePermissionV1,isMemberOfProjectV1,-} from "../utils";+} from "../../utils";import { Sheet, Sheet_Visibility } from "@/types/proto/v1/sheet_service";import {getUserEmailFromIdentifier,getProjectAndSheetId,+ getSheetPathByLegacyProject,} from "@/store/modules/v1/common";export const isSheetReadableV1 = (sheet: Sheet) => {@@ -108,3 +118,41 @@ export const getSheetIssueBacktracePayloadV1 = (sheet: Sheet) => {return undefined;};++export const sheetNameOfTask = (task: Task) => {+ const project = task.database?.project;+ if (!project) {+ return "";+ }++ let sheetId: SheetId;++ switch (task.type) {+ case "bb.task.database.create":+ sheetId = (task.payload as TaskDatabaseCreatePayload).sheetId || "";+ break;+ case "bb.task.database.schema.update":+ sheetId = (task.payload as TaskDatabaseSchemaUpdatePayload).sheetId || "";+ break;+ case "bb.task.database.schema.update-sdl":+ sheetId =+ (task.payload as TaskDatabaseSchemaUpdateSDLPayload).sheetId || "";+ break;+ case "bb.task.database.data.update":+ sheetId = (task.payload as TaskDatabaseDataUpdatePayload).sheetId || "";+ break;+ case "bb.task.database.schema.update.ghost.sync":+ sheetId =+ (task.payload as TaskDatabaseSchemaUpdateGhostSyncPayload).sheetId ||+ "";+ break;+ default:+ return "";+ }++ if (!sheetId) {+ return "";+ }++ return getSheetPathByLegacyProject(project, sheetId);+};diff --git a/frontend/src/views/SheetDashboard.vue b/frontend/src/views/SheetDashboard.vueindex ee89c541a6..0b2b4449d3 100644--- a/frontend/src/views/SheetDashboard.vue+++ b/frontend/src/views/SheetDashboard.vue@@ -92,13 +92,13 @@ import { last } from "lodash-es";import { useDialog } from "naive-ui";import { t } from "@/plugins/i18n";-import { Sheet as SheetV1 } from "@/types/proto/v1/sheet_service";+import { Sheet } from "@/types/proto/v1/sheet_service";import {hasFeature,useUserStore,+ useSheetV1Store,useProjectV1ListByCurrentUser,} from "@/store";-import { useSheetV1Store } from "@/store/modules/v1/sheet";import { getSheetIssueBacktracePayloadV1 } from "@/utils";import {type SheetViewMode,@@ -109,7 +109,7 @@ import { Workflow } from "@/types/proto/v1/project_service";interface LocalState {isLoading: boolean;- sheetList: SheetV1[];+ sheetList: Sheet[];showFeatureModal: boolean;}@@ -156,10 +156,7 @@ const shownSheetList = computed(() => {list = list.filter((sheet) => {return (sheet.name.toLowerCase().includes(keyword) ||- new TextDecoder()- .decode(sheet.content.buffer)- .toLowerCase()- .includes(keyword)+ new TextDecoder().decode(sheet.content).toLowerCase().includes(keyword));});}@@ -215,7 +212,7 @@ const currentSheetViewMode = computed((): SheetViewMode => {const fetchSheetData = async () => {await useUserStore().fetchUserList();- let sheetList: SheetV1[] = [];+ let sheetList: Sheet[] = [];if (currentSheetViewMode.value === "my") {sheetList = await sheetV1Store.fetchMySheetList();} else if (currentSheetViewMode.value === "starred") {diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vueindex deddd0bb03..3212180027 100644--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue@@ -60,7 +60,6 @@ import type {CoreTabInfo,DatabaseId,InstanceId,- SheetId,} from "@/types";import { ConnectionTreeState, TabMode, UNKNOWN_ID } from "@/types";import {@@ -189,8 +188,8 @@ const treeData = computed(() => connectionTreeStore.tree.data);const setConnection = (option: ConnectionAtom,- extra: { sheetId?: SheetId; mode: TabMode } = {- sheetId: undefined,+ extra: { sheetName?: string; mode: TabMode } = {+ sheetName: undefined,mode: TabMode.ReadOnly,}) => {diff --git a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vueindex 7f79619b8b..6fc0aa88af 100644--- a/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue+++ b/frontend/src/views/sql-editor/EditorCommon/SaveSheetModal.vue@@ -14,6 +14,10 @@ import { computed, reactive } from "vue";import type { SheetUpsert } from "@/types";import { UNKNOWN_ID } from "@/types";import { useDatabaseStore, useSheetStore, useTabStore } from "@/store";+import {+ getProjectAndSheetId,+ getSheetPathByLegacyProject,+} from "@/store/modules/v1/common";import { defaultTabName, getDefaultTabNameFromConnection } from "@/utils";import SaveSheetForm from "./SaveSheetForm.vue";@@ -45,9 +49,11 @@ const allowSave = computed((): boolean => {return true;});-const doSaveSheet = async (sheetName?: string) => {- const { name, statement, sheetId } = tabStore.currentTab;- sheetName = sheetName || name;+const doSaveSheet = async (sheetTitle?: string) => {+ const { name, statement, sheetName } = tabStore.currentTab;+ sheetTitle = sheetTitle || name;++ const sheetId = getProjectAndSheetId(sheetName ?? "")[1];const conn = tabStore.currentTab.connection;const database = await databaseStore.getOrFetchDatabaseById(conn.databaseId);@@ -55,21 +61,21 @@ const doSaveSheet = async (sheetName?: string) => {id: sheetId,projectId: database.project.id,databaseId: conn.databaseId,- name: sheetName,+ name: sheetTitle,statement: statement,};const sheet = await sheetStore.upsertSheet(sheetUpsert);tabStore.updateCurrentTab({- sheetId: sheet.id,+ sheetName: getSheetPathByLegacyProject(sheet.project, sheet.id),isSaved: true,- name: sheetName,+ name: sheetTitle,});};const needSheetName = (sheetName: string | undefined) => {const tab = tabStore.currentTab;- if (tab.sheetId) {+ if (tab.sheetName) {// If the sheet is saved, we don't need to show the name popup.return false;}diff --git a/frontend/src/views/sql-editor/EditorCommon/SharePopover.vue b/frontend/src/views/sql-editor/EditorCommon/SharePopover.vueindex 3b4e9b3e12..884656f91d 100644--- a/frontend/src/views/sql-editor/EditorCommon/SharePopover.vue+++ b/frontend/src/views/sql-editor/EditorCommon/SharePopover.vue@@ -85,44 +85,45 @@import { ref, computed, onMounted } from "vue";import { useClipboard } from "@vueuse/core";import { useI18n } from "vue-i18n";-import { pushNotification, useTabStore, useSheetStore } from "@/store";+import { pushNotification, useTabStore, useSheetV1Store } from "@/store";import { AccessOption } from "@/types";-import { sheetSlug } from "@/utils";+import { sheetSlugV1 } from "@/utils";+import { Sheet_Visibility } from "@/types/proto/v1/sheet_service";const { t } = useI18n();const tabStore = useTabStore();-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const accessOptions = computed<AccessOption[]>(() => {return [{label: t("sql-editor.private"),- value: "PRIVATE",+ value: Sheet_Visibility.VISIBILITY_PRIVATE,description: t("sql-editor.private-desc"),},{label: t("common.project"),- value: "PROJECT",+ value: Sheet_Visibility.VISIBILITY_PROJECT,description: t("sql-editor.project-desc"),},{label: t("sql-editor.public"),- value: "PUBLIC",+ value: Sheet_Visibility.VISIBILITY_PUBLIC,description: t("sql-editor.public-desc"),},];});-const sheet = computed(() => sheetStore.currentSheet);-const isCreator = computed(() => sheetStore.isCreator);+const sheet = computed(() => sheetV1Store.currentSheet);+const isCreator = computed(() => sheetV1Store.isCreator);const currentAccess = ref<AccessOption>(accessOptions.value[0]);const isShowAccessPopover = ref(false);const updateSheet = () => {- if (tabStore.currentTab.sheetId) {- sheetStore.patchSheetById({- id: tabStore.currentTab.sheetId,+ if (sheet.value) {+ sheetV1Store.patchSheet({+ name: sheet.value.name,visibility: currentAccess.value.value,});}@@ -137,9 +138,14 @@ const handleChangeAccess = (option: AccessOption) => {isShowAccessPopover.value = false;};-const sharedTabLink = computed(- () => `${window.location.origin}/sql-editor/sheet/${sheetSlug(sheet.value)}`-);+const sharedTabLink = computed(() => {+ if (!sheet.value) {+ return "";+ }+ return `${window.location.origin}/sql-editor/sheet/${sheetSlugV1(+ sheet.value+ )}`;+});const { copy, copied } = useClipboard({source: sharedTabLink.value,diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vueindex 28cefd5775..30c6780db3 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue@@ -33,7 +33,7 @@ import type { Connection, ExecuteConfig, ExecuteOption } from "@/types";import {useCurrentTab,useInstanceStore,- useSheetStore,+ useSheetV1Store,useTabStore,} from "@/store";import SQLEditor from "./SQLEditor.vue";@@ -47,18 +47,19 @@ import {import SheetForIssueTipsBar from "./SheetForIssueTipsBar.vue";import { useExecuteSQL } from "@/composables/useExecuteSQL";import { AIChatToSQL } from "@/plugins/ai";-import { getSheetIssueBacktracePayload } from "@/utils";+import { getSheetIssueBacktracePayloadV1 } from "@/utils";const tabStore = useTabStore();-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const saveSheetModal = ref<InstanceType<typeof SaveSheetModal>>();const tab = useCurrentTab();const sheetBacktracePayload = computed(() => {- const sheetId = tabStore.currentTab.sheetId;- if (!sheetId) return undefined;- const sheet = sheetStore.getSheetById(sheetId);- return getSheetIssueBacktracePayload(sheet);+ const sheetName = tabStore.currentTab.sheetName;+ if (!sheetName) return undefined;+ const sheet = sheetV1Store.getSheetByName(sheetName);+ if (!sheet) return undefined;+ return getSheetIssueBacktracePayloadV1(sheet);});const { execute } = useExecuteSQL();diff --git a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vueindex ab580fa124..2f10b13bd5 100644--- a/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SQLEditor.vue@@ -25,7 +25,7 @@ import {useTabStore,useSQLEditorStore,useDatabaseStore,- useSheetStore,+ useSheetV1Store,useInstanceById,useDBSchemaStore,useUIStateStore,@@ -57,7 +57,7 @@ const tabStore = useTabStore();const databaseStore = useDatabaseStore();const dbSchemaStore = useDBSchemaStore();const sqlEditorStore = useSQLEditorStore();-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const uiStateStore = useUIStateStore();const editorRef = ref<InstanceType<typeof MonacoEditor>>();@@ -79,7 +79,7 @@ const selectedDialect = computed((): SQLDialect => {const engine = selectedInstance.value.engine;return dialectOfEngine(engine);});-const readonly = computed(() => sheetStore.isReadOnly);+const readonly = computed(() => sheetV1Store.isReadOnly);const currentTabId = computed(() => tabStore.currentTabId);const isSwitchingTab = ref(false);diff --git a/frontend/src/views/sql-editor/EditorPanel/SheetForIssueTipsBar.vue b/frontend/src/views/sql-editor/EditorPanel/SheetForIssueTipsBar.vueindex 6029d8b95e..7aba7bf3c4 100644--- a/frontend/src/views/sql-editor/EditorPanel/SheetForIssueTipsBar.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SheetForIssueTipsBar.vue@@ -33,29 +33,29 @@</template><script lang="ts" setup>-import { useIssueStore, useSheetStore, useTabStore } from "@/store";+import { useIssueStore, useSheetV1Store, useTabStore } from "@/store";import { Issue } from "@/types";-import { getSheetIssueBacktracePayload } from "@/utils";+import { getSheetIssueBacktracePayloadV1 } from "@/utils";import { NTooltip } from "naive-ui";import { shallowRef } from "vue";import { computed, ref, watch } from "vue";const tabStore = useTabStore();-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const issueStore = useIssueStore();const tab = computed(() => tabStore.currentTab);const loading = ref(true);const issue = shallowRef<Issue>();const sheet = computed(() => {- const { sheetId } = tab.value;- if (!sheetId) return undefined;- return sheetStore.getSheetById(sheetId);+ const { sheetName } = tab.value;+ if (!sheetName) return undefined;+ return sheetV1Store.getSheetByName(sheetName);});const payload = computed(() => {if (!sheet.value) return undefined;- return getSheetIssueBacktracePayload(sheet.value);+ return getSheetIssueBacktracePayloadV1(sheet.value);});watch(diff --git a/frontend/src/views/sql-editor/Sheet/SheetTable/Dropdown.vue b/frontend/src/views/sql-editor/Sheet/SheetTable/Dropdown.vueindex a544c4c3bd..b27fd3e5f0 100644--- a/frontend/src/views/sql-editor/Sheet/SheetTable/Dropdown.vue+++ b/frontend/src/views/sql-editor/Sheet/SheetTable/Dropdown.vue@@ -20,9 +20,11 @@ import { Sheet } from "@/types/proto/v1/sheet_service";import type { SheetCreate, SheetOrganizerUpsert } from "@/types";import type { SheetViewMode } from "../types";import { getDefaultSheetPayloadWithSource, isSheetWritableV1 } from "@/utils";-import { useSheetStore, useProjectV1Store } from "@/store";-import { getProjectAndSheetId, getDatabaseId } from "@/store/modules/v1/common";-import { useSheetV1Store } from "@/store/modules/v1/sheet";+import { useSheetStore, useSheetV1Store, useProjectV1Store } from "@/store";+import {+ getProjectAndSheetId,+ getInstanceAndDatabaseId,+} from "@/store/modules/v1/common";const props = defineProps<{view: SheetViewMode;@@ -90,6 +92,7 @@ const handleAction = async (key: string) => {closeOnEsc: false,async onPositiveClick() {await useSheetV1Store().deleteSheetByName(sheet.name);+ emit("refresh");dialogInstance.destroy();},onNegativeClick() {@@ -128,15 +131,16 @@ const handleAction = async (key: string) => {const sheetCreate: SheetCreate = {projectId: projectV1.uid,name: sheet.title,- statement: new TextDecoder().decode(sheet.content.buffer),+ statement: new TextDecoder().decode(sheet.content),visibility: "PRIVATE",payload: getDefaultSheetPayloadWithSource("BYTEBASE"),source: "BYTEBASE",};if (sheet.database) {- sheetCreate.databaseId = getDatabaseId(sheet.database);+ sheetCreate.databaseId = getInstanceAndDatabaseId(sheet.database)[1];}await sheetStore.createSheet(sheetCreate);+ emit("refresh");dialogInstance.destroy();},onNegativeClick() {diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue b/frontend/src/views/sql-editor/TabList/TabItem/Label.vueindex 56c14f3589..24d3ad314e 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/Label.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/Label.vue@@ -24,8 +24,7 @@import { computed, nextTick, PropType, reactive, ref, watch } from "vue";import type { TabInfo } from "@/types";-import { UNKNOWN_ID } from "@/types";-import { useSheetStore, useTabStore } from "@/store";+import { useSheetV1Store, useTabStore } from "@/store";type LocalState = {editing: boolean;@@ -49,7 +48,7 @@ const state = reactive<LocalState>({});const tabStore = useTabStore();-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const inputRef = ref<HTMLInputElement>();const isCurrentTab = computed(() => props.tab.id === tabStore.currentTabId);@@ -71,11 +70,10 @@ const confirmEdit = () => {}tab.name = name;-- if (tab.sheetId && tab.sheetId !== UNKNOWN_ID) {- sheetStore.patchSheetById({- id: tab.sheetId,- name,+ if (tab.sheetName) {+ sheetV1Store.patchSheet({+ name: tab.sheetName,+ title: name,});}diff --git a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vueindex 6aa511cbe5..a44bfbab2a 100644--- a/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue+++ b/frontend/src/views/sql-editor/TabList/TabItem/Prefix.vue@@ -1,11 +1,11 @@<template>- <template v-if="sheet.id !== UNKNOWN_ID">+ <template v-if="sheet"><heroicons-outline:user-group- v-if="sheet.visibility === 'PROJECT'"+ v-if="sheet.visibility === Sheet_Visibility.VISIBILITY_PROJECT"class="w-4 h-4"/><heroicons-outline:globe- v-if="sheet.visibility === 'PUBLIC'"+ v-if="sheet.visibility === Sheet_Visibility.VISIBILITY_PUBLIC"class="w-4 h-4"/></template>@@ -18,8 +18,9 @@import { computed, PropType } from "vue";import type { TabInfo } from "@/types";-import { TabMode, unknown, UNKNOWN_ID } from "@/types";-import { useSheetStore } from "@/store";+import { TabMode } from "@/types";+import { useSheetV1Store } from "@/store";+import { Sheet_Visibility } from "@/types/proto/v1/sheet_service";const props = defineProps({tab: {@@ -32,16 +33,16 @@ const props = defineProps({},});-const sheetStore = useSheetStore();+const sheetV1Store = useSheetV1Store();const sheet = computed(() => {- const { sheetId } = props.tab;- if (sheetId) {- const sheet = sheetStore.sheetById.get(sheetId);+ const { sheetName } = props.tab;+ if (sheetName) {+ const sheet = sheetV1Store.getSheetByName(sheetName);if (sheet) {return sheet;}}- return unknown("SHEET");+ return null;});</script>