fix(objects): guard system source edits
This commit is contained in:
1 parent
57dea3cb6d
commit
17bc2e66d4
13 files changed
+291
-27
No files matched your search
@@ -217,6 +217,26 @@ function openAiPanel() {
|
||||
}
|
||||
}
|
||||
|
||||
function isActiveObjectSourceReadOnly() {
|
||||
return !!activeTab.value?.objectSource?.readOnlyReason;
|
||||
}
|
||||
|
||||
function guardWritableObjectSource() {
|
||||
if (!isActiveObjectSourceReadOnly()) return true;
|
||||
toast(t("objects.sourceReadOnlySystemObject"), 5000);
|
||||
return false;
|
||||
}
|
||||
|
||||
function tryExecuteActiveTab() {
|
||||
if (!guardWritableObjectSource()) return;
|
||||
tryExecute();
|
||||
}
|
||||
|
||||
function tryExplainActiveTab() {
|
||||
if (!guardWritableObjectSource()) return;
|
||||
tryExplain();
|
||||
}
|
||||
|
||||
function analyzeHistoryWithAi(entry: HistoryEntry) {
|
||||
const connectionId = entry.connection_id || activeTab.value?.connectionId;
|
||||
if (!connectionId) {
|
||||
@@ -253,6 +273,7 @@ async function openSaveSqlDialog() {
|
||||
const tab = activeTab.value;
|
||||
if (!tab || !tab.sql.trim()) return;
|
||||
if (tab.objectSource) {
|
||||
if (!guardWritableObjectSource()) return;
|
||||
await saveActiveObjectSource(tab);
|
||||
return;
|
||||
}
|
||||
@@ -282,6 +303,10 @@ async function saveActiveObjectSource(tab: NonNullable<typeof activeTab.value>)
|
||||
const connection = connectionStore.getConfig(tab.connectionId);
|
||||
const source = tab.objectSource;
|
||||
if (!connection || !source) return;
|
||||
if (source.readOnlyReason) {
|
||||
toast(t("objects.sourceReadOnlySystemObject"), 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const statements = buildExecutableObjectSourceStatements({
|
||||
@@ -563,7 +588,7 @@ function handleKeydown(e: KeyboardEvent) {
|
||||
) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
tryExecute();
|
||||
tryExecuteActiveTab();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,9 +782,9 @@ onUnmounted(() => {
|
||||
:active-tab="activeTab"
|
||||
:active-connection="activeConnection"
|
||||
:executable-sql="executableSql"
|
||||
@execute="tryExecute()"
|
||||
@execute="tryExecuteActiveTab"
|
||||
@cancel="cancelActiveExecution()"
|
||||
@explain="tryExplain()"
|
||||
@explain="tryExplainActiveTab"
|
||||
@format-sql="formatActiveSql"
|
||||
@save-sql="void openSaveSqlDialog()"
|
||||
@open-sql="openSqlFile"
|
||||
@@ -780,9 +805,9 @@ onUnmounted(() => {
|
||||
:cursor-pos="cursorPos"
|
||||
@update:active-output-view="activeOutputView = $event"
|
||||
@fix-with-ai="fixWithAi"
|
||||
@execute="tryExecute()"
|
||||
@execute="tryExecuteActiveTab"
|
||||
@cancel="cancelActiveExecution()"
|
||||
@explain="tryExplain()"
|
||||
@explain="tryExplainActiveTab"
|
||||
@editor-update="
|
||||
(v: string) => {
|
||||
if (queryStore.activeTabId) queryStore.updateSql(queryStore.activeTabId, v);
|
||||
|
||||
Reference in new issue
Block a user