Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: save sheet (#1162)
STEVENd4b4d25f01ae
diff --git a/frontend/src/store/modules/sheet.ts b/frontend/src/store/modules/sheet.tsindex 99a3217d64..eaf4abdcee 100644--- a/frontend/src/store/modules/sheet.ts+++ b/frontend/src/store/modules/sheet.ts@@ -8,7 +8,6 @@ import {SheetPatch,Principal,ResourceObject,- TabInfo,Database,Project,ProjectMember,@@ -18,6 +17,7 @@ import {SheetCreate,SheetOrganizerUpsert,ProjectId,+ SheetUpsert,} from "@/types";import { getPrincipalFromIncludedList } from "./principal";import { useAuthStore } from "./auth";@@ -149,49 +149,19 @@ export const useSheetStore = defineStore("sheet", {}this.sheetById.set(sheetId, sheet);},- upsertSheet(payload: {- sheet: Pick<Sheet, "id" | "name" | "statement">;- currentTab: TabInfo;- }): Promise<Sheet> {- const { sheet, currentTab } = payload;- const hasSheet = this.sheetById.has(sheet.id);-- if (hasSheet) {- return this.patchSheetById(sheet);+ upsertSheet(sheetUpsert: SheetUpsert): Promise<Sheet> {+ if (sheetUpsert.id) {+ return this.patchSheetById({+ id: sheetUpsert.id,+ name: sheetUpsert.name,+ statement: sheetUpsert.statement,+ });}- return this.createSheetByTab(currentTab);- },- async createSheetByTab(currentTab: TabInfo): Promise<Sheet> {- const sqlEditorStore = useSQLEditorStore();- const ctx = sqlEditorStore.connectionContext;-- const result = (- await axios.post(`/api/sheet`, {- data: {- type: "createSheet",- attributes: {- projectId: ctx.projectId,- databaseId: ctx.databaseId,- name: currentTab.name,- statement: currentTab.statement,- visibility: "PRIVATE",- },- },- })- ).data;- const sheet = convertSheet(result.data, result.included);-- this.setSheetList(- this.sheetList.concat(sheet).sort((a, b) => b.createdTs - a.createdTs)- );-- this.setSheetById({- sheetId: sheet.id,- sheet: sheet,+ return this.createSheet({+ ...sheetUpsert,+ visibility: "PRIVATE",});-- return sheet;},async createSheet(sheetCreate: SheetCreate): Promise<Sheet> {const resData = (diff --git a/frontend/src/types/sheet.ts b/frontend/src/types/sheet.tsindex 8b714bb548..c68ad07ce0 100644--- a/frontend/src/types/sheet.ts+++ b/frontend/src/types/sheet.ts@@ -42,6 +42,15 @@ export interface Sheet {pinned: boolean;}+export interface SheetUpsert {+ id?: SheetId;+ projectId: ProjectId;+ databaseId?: DatabaseId;+ name: string;+ statement: string;+ visibility?: SheetVisibility;+}+export interface SheetCreate {projectId: ProjectId;databaseId?: DatabaseId;diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vueindex cb228326ef..89c17eb392 100644--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue@@ -57,20 +57,23 @@ const handleSaveSheet = async (sheetName?: string) => {isShowSaveSheetModal.value = false;const { name, statement, sheetId } = tabStore.currentTab;+ sheetName = sheetName ? sheetName : name;- const sheet = await sheetStore.upsertSheet({- sheet: {- id: sheetId as number,- name: sheetName ? sheetName : name,- statement,- },- currentTab: tabStore.currentTab,- });+ const ctx = sqlEditorStore.connectionContext;+ const sheetUpsert = {+ id: sheetId,+ projectId: ctx.projectId,+ databaseId: ctx.databaseId,+ name: sheetName,+ statement: statement,+ };++ const sheet = await sheetStore.upsertSheet(sheetUpsert);tabStore.updateCurrentTab({sheetId: sheet.id,isSaved: true,- name: sheetName ? sheetName : name,+ name: sheetName,});};diff --git a/frontend/src/views/sql-editor/EditorPanel/SaveSheetModal.vue b/frontend/src/views/sql-editor/EditorPanel/SaveSheetModal.vueindex 116931ab36..dd2bbe6af4 100644--- a/frontend/src/views/sql-editor/EditorPanel/SaveSheetModal.vue+++ b/frontend/src/views/sql-editor/EditorPanel/SaveSheetModal.vue@@ -1,19 +1,17 @@<template><div class="save-sheet-modal w-80">- <NInput+ <n-inputref="sheetNameInputRef"v-model:value="sheetName":placeholder="$t('sql-editor.save-sheet-input-placeholder')"- @keyup.enter="(e: Event) => emit('save-sheet', sheetName)"+ @keyup.enter="handleSaveSheet"/></div><div class="mt-4 flex justify-end space-x-2">- <NButton @click="(e: Event) => emit('close')">{{- $t("common.close")- }}</NButton>- <NButton type="primary" @click="emit('save-sheet', sheetName)">+ <n-button @click="emit('close')">{{ $t("common.close") }}</n-button>+ <n-button type="primary" @click="handleSaveSheet">{{ $t("common.save") }}- </NButton>+ </n-button></div></template>@@ -32,6 +30,10 @@ const tabStore = useTabStore();const sheetName = ref(tabStore.currentTab.name);const sheetNameInputRef = ref();+const handleSaveSheet = () => {+ emit("save-sheet", sheetName.value);+};+nextTick(() => {sheetNameInputRef.value?.focus();});