Skip to content

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

chore: optimize request query in sql editor (#12305)

ecmadao9cc26a21eeb2
diff --git a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue
index d45bfa09d0..2a01ef5be4 100644
--- a/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue
+++ b/frontend/src/components/Issue/panel/RequestQueryPanel/index.vue
@@ -2,6 +2,7 @@
<Drawer
:show="true"
width="auto"
+ :placement="placement"
@update:show="(show: boolean) => !show && $emit('close')"
>
<DrawerContent
@@ -115,10 +116,18 @@ defineOptions({
name: "RequestQueryPanel",
});
-const props = defineProps<{
- projectId?: string;
- database?: ComposedDatabase;
-}>();
+const props = withDefaults(
+ defineProps<{
+ projectId?: string;
+ database?: ComposedDatabase;
+ placement: "left" | "right";
+ }>(),
+ {
+ projectId: undefined,
+ database: undefined,
+ placement: "right",
+ }
+);
defineEmits<{
(event: "close"): void;
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 2120c786a2..d3558942f2 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -179,7 +179,6 @@ const prepareDatabases = async () => {
const databaseList = (
await databaseStore.searchDatabases({
filter: filters.join(" && "),
- permission: "bb.databases.query",
})
).filter((db) => db.syncState === State.ACTIVE);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index de672df4ec..922a2e0911 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2295,6 +2295,7 @@
"description": "Batch query {count} additional databases under {project}."
},
"executing-query": "Executing query",
+ "request-query": "Request query",
"grouping": "Grouping",
"previous-row": "Previous row",
"next-row": "Next row",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 0c73a90cca..819e01b973 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2295,6 +2295,7 @@
"description": "Consulta por lotes {count} bases de datos adicionales en {project}."
},
"executing-query": "Ejecutando consulta",
+ "request-query": "Solicitar consulta",
"grouping": "Agrupamiento",
"previous-row": "Fila anterior",
"next-row": "siguiente fila",
@@ -3532,4 +3533,4 @@
"self": "Última actualización"
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index b88b433967..cc10e4eff4 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2295,6 +2295,7 @@
"description": "{project} の下にある {count} データベースをバッチクエリします。"
},
"executing-query": "クエリの実行",
+ "request-query": "リクエストクエリ",
"grouping": "グループ",
"previous-row": "前の行",
"next-row": "次の行",
@@ -3532,4 +3533,4 @@
"self": "最後の更新"
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 5c41e94703..4d8821ba7e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2295,6 +2295,7 @@
"description": "批量查询 {project} 下的 {count} 个数据库。"
},
"executing-query": "执行查询",
+ "request-query": "请求查询",
"grouping": "分组",
"previous-row": "上一行",
"next-row": "下一行",
@@ -3532,4 +3533,4 @@
"self": "最后更新"
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
index 4b51ddf1dd..987da4622b 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/ConnectionPane.vue
@@ -58,6 +58,7 @@ import { onMounted } from "vue";
import MaskSpinner from "@/components/misc/MaskSpinner.vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import {
+ useCurrentUserV1,
useDatabaseV1Store,
useInstanceV1Store,
useIsLoggedIn,
@@ -78,7 +79,7 @@ import {
ExpandableTreeNodeTypes,
UNKNOWN_ID,
} from "@/types";
-import { findAncestor, isDescendantOf } from "@/utils";
+import { findAncestor, isDescendantOf, isDatabaseV1Queryable } from "@/utils";
import { useSQLEditorContext } from "../../context";
import {
DatabaseHoverPanel,
@@ -95,6 +96,8 @@ const tabStore = useSQLEditorTabStore();
const databaseStore = useDatabaseV1Store();
const instanceStore = useInstanceV1Store();
const isLoggedIn = useIsLoggedIn();
+const me = useCurrentUserV1();
+
const { events: editorEvents, showConnectionPanel } = useSQLEditorContext();
const searchHistory = useSearchHistory();
const {
@@ -190,6 +193,10 @@ const expandNodesByType = <T extends SQLEditorTreeNodeType>(
return nodes;
};
+const canQueryDatabase = (database: ComposedDatabase): boolean => {
+ return isDatabaseV1Queryable(database, me.value);
+};
+
// dynamic render the highlight keywords
const renderLabel = ({ option }: { option: TreeOption }) => {
const node = option as any as SQLEditorTreeNode;
@@ -211,11 +218,13 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
// Check if clicked on the content part.
// And ignore the fold/unfold arrow.
if (type === "database") {
- setConnection(node, {
- worksheet: tabStore.currentTab?.worksheet ?? "",
- mode: DEFAULT_SQL_EDITOR_TAB_MODE,
- });
- showConnectionPanel.value = false;
+ if (canQueryDatabase(node.meta.target as ComposedDatabase)) {
+ setConnection(node, {
+ worksheet: tabStore.currentTab?.worksheet ?? "",
+ mode: DEFAULT_SQL_EDITOR_TAB_MODE,
+ });
+ showConnectionPanel.value = false;
+ }
}
// If the search pattern is not empty, append the selected database name to
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
index 2735df1db9..16b8b9f9ca 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/TreeNode/DatabaseNode.vue
@@ -24,9 +24,16 @@
<span class="flex-1 truncate">
<HighlightLabelText :text="database.databaseName" :keyword="keyword" />
<span v-if="!hasInstanceContext" class="text-control-light">
- ({{ database.instanceEntity.title }})</span
- >
+ ({{ database.instanceEntity.title }})
+ </span>
</span>
+ <HideInStandaloneMode>
+ <RequestQueryButton
+ v-if="!canQuery"
+ :database="database"
+ :panel-placement="'left'"
+ />
+ </HideInStandaloneMode>
</div>
</template>
@@ -34,10 +41,13 @@
import { computed } from "vue";
import DatabaseIcon from "~icons/heroicons-outline/circle-stack";
import { EnvironmentV1Name, InstanceV1EngineIcon } from "@/components/v2";
+import { useCurrentUserV1 } from "@/store";
import type {
SQLEditorTreeNode as TreeNode,
SQLEditorTreeFactor as Factor,
} from "@/types";
+import { isDatabaseV1Queryable } from "@/utils";
+import RequestQueryButton from "../../../EditorCommon/ResultView/RequestQueryButton.vue";
import HighlightLabelText from "./HighlightLabelText.vue";
const props = defineProps<{
@@ -46,10 +56,16 @@ const props = defineProps<{
keyword: string;
}>();
+const me = useCurrentUserV1();
+
const database = computed(
() => (props.node as TreeNode<"database">).meta.target
);
+const canQuery = computed(() =>
+ isDatabaseV1Queryable(database.value, me.value)
+);
+
const hasInstanceContext = computed(() => {
return props.factors.includes("instance");
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue
index bd30ecdbe5..344d09de26 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/RequestQueryButton.vue
@@ -1,13 +1,14 @@
<template>
<div v-if="available">
- <NButton text type="primary" @click="showPanel = true">
- {{ $t("custom-approval.risk-rule.risk.namespace.request_query") }}
+ <NButton text type="primary" @click="onClick">
+ {{ $t("sql-editor.request-query") }}
</NButton>
<RequestQueryPanel
:show="showPanel"
:project-id="database?.projectEntity.uid"
:database="database"
+ :placement="panelPlacement"
@close="showPanel = false"
/>
</div>
@@ -16,19 +17,34 @@
<script setup lang="ts">
import { computed, ref } from "vue";
import RequestQueryPanel from "@/components/Issue/panel/RequestQueryPanel/index.vue";
-import { useConnectionOfCurrentSQLEditorTab, useCurrentUserV1 } from "@/store";
-import { UNKNOWN_ID } from "@/types";
+import { useCurrentUserV1 } from "@/store";
+import { UNKNOWN_ID, type ComposedDatabase } from "@/types";
import { hasPermissionToCreateRequestGrantIssue } from "@/utils";
+const props = withDefaults(
+ defineProps<{
+ database: ComposedDatabase;
+ panelPlacement: "left" | "right";
+ }>(),
+ {
+ panelPlacement: "right",
+ }
+);
+
const me = useCurrentUserV1();
const showPanel = ref(false);
-const { database } = useConnectionOfCurrentSQLEditorTab();
const available = computed(() => {
- if (database.value.uid === String(UNKNOWN_ID)) {
+ if (props.database.uid === String(UNKNOWN_ID)) {
return false;
}
- return hasPermissionToCreateRequestGrantIssue(database.value, me.value);
+ return hasPermissionToCreateRequestGrantIssue(props.database, me.value);
});
+
+const onClick = (e: MouseEvent) => {
+ e.stopPropagation();
+ e.preventDefault();
+ showPanel.value = true;
+};
</script>
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
index e7414321a4..694f7bddce 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/ResultViewV1.vue
@@ -52,6 +52,7 @@
<HideInStandaloneMode>
<RequestQueryButton
v-if="resultSet.status === Status.PERMISSION_DENIED"
+ :database="database ?? connectedDb"
/>
<SyncDatabaseButton
v-else-if="resultSet.error.includes('resource not found')"
@@ -143,7 +144,8 @@ const props = defineProps({
const { t } = useI18n();
const currentUser = useCurrentUserV1();
const policyStore = usePolicyV1Store();
-const { instance } = useConnectionOfCurrentSQLEditorTab();
+const { instance, database: connectedDb } =
+ useConnectionOfCurrentSQLEditorTab();
const keyword = ref("");
const detail: SQLResultViewContext["detail"] = ref({
show: false,