Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat: disable saving if connected to an instance (#2727)

Liu Ji0a40c0b64104
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
index a6a82bd8c2..bc3861d1d0 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorAction.vue
@@ -98,7 +98,7 @@
secondary
strong
type="primary"
- :disabled="isEmptyStatement || tabStore.currentTab.isSaved"
+ :disabled="!allowSave"
@click="() => emit('save-sheet')"
>
<carbon:save class="h-5 w-5" /> &nbsp; {{ $t("common.save") }} (⌘+S)
@@ -178,6 +178,21 @@ const hasReadonlyDataSource = computed(() => {
return false;
});
+const allowSave = computed(() => {
+ if (isEmptyStatement.value) {
+ return false;
+ }
+ if (tabStore.currentTab.isSaved) {
+ return false;
+ }
+ // Temporarily disable saving and sharing if we are connected to an instance
+ // but not a database.
+ if (tabStore.currentTab.connection.databaseId === UNKNOWN_ID) {
+ return false;
+ }
+ return true;
+});
+
const { execute } = useExecuteSQL();
const handleRunQuery = async () => {
diff --git a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
index a1220cd0d2..ce7f7f2f11 100644
--- a/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
+++ b/frontend/src/views/sql-editor/EditorPanel/EditorPanel.vue
@@ -48,6 +48,7 @@ import SQLEditor from "./SQLEditor.vue";
import ExecuteHint from "./ExecuteHint.vue";
import ConnectionHolder from "./ConnectionHolder.vue";
import SaveSheetModal from "./SaveSheetModal.vue";
+import { UNKNOWN_ID } from "@/types";
const tabStore = useTabStore();
const sqlEditorStore = useSQLEditorStore();
@@ -62,6 +63,22 @@ const isProtectedEnvironment = computed(() => {
return instance.environment.tier === "PROTECTED";
});
+const allowSave = computed((): boolean => {
+ const tab = tabStore.currentTab;
+ if (tab.statement === "") {
+ return false;
+ }
+ if (tab.isSaved) {
+ return false;
+ }
+ // Temporarily disable saving and sharing if we are connected to an instance
+ // but not a database.
+ if (tab.connection.databaseId === UNKNOWN_ID) {
+ return false;
+ }
+ return true;
+});
+
const handleClose = () => {
sqlEditorStore.setSQLEditorState({
isShowExecutingHint: false,
@@ -69,6 +86,10 @@ const handleClose = () => {
};
const handleSaveSheet = async (sheetName?: string) => {
+ if (!allowSave.value) {
+ return;
+ }
+
if (tabStore.currentTab.name === defaultTabName.value && !sheetName) {
isShowSaveSheetModal.value = true;
return;