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: cosmos db select table (#14929)
ecmadao22388ff9f595
diff --git a/frontend/src/composables/useExecuteSQL.ts b/frontend/src/composables/useExecuteSQL.tsindex 96a9418a3d..a36eed69c3 100644--- a/frontend/src/composables/useExecuteSQL.ts+++ b/frontend/src/composables/useExecuteSQL.ts@@ -337,6 +337,7 @@ const useExecuteSQL = () => {limit: sqlEditorStore.resultRowsLimit,explain: params.explain,schema: params.connection.schema,+ container: params.connection.table,timeout: undefined, // TODO: make this param configurablequeryOption: {redisRunCommandsOn: sqlEditorStore.redisCommandOption,diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 59cc55aef5..429961f5be 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1936,6 +1936,10 @@"select": "Select schema","unspecified": "Unspecified"},+ "table": {+ "select": "Select table",+ "select-tip": "Please select a table to start."+ },"show-missing-databases": "Show missing databases","n-selected-m-in-total": "({selected} selected, {total} in total)","doesnt-match-database-name-template": "Doesn't match tenant database name template",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 6fb951c0e7..d89cac4e53 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1936,6 +1936,10 @@"select": "Seleccionar esquema","unspecified": "No especificado"},+ "table": {+ "select": "Seleccionar tabla",+ "select-tip": "Seleccione una mesa para comenzar."+ },"show-missing-databases": "Mostrar bases de datos faltantes","n-selected-m-in-total": "({selected} seleccionados, {total} en total)","doesnt-match-database-name-template": "No coincide con la plantilla de nombre de base de datos de inquilino",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex dc0c4574d8..f82bea6be2 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1936,6 +1936,10 @@"select": "スキーマの選択","unspecified": "不特定"},+ "table": {+ "select": "テーブルを選択",+ "select-tip": "開始するにはテーブルを選択してください。"+ },"show-missing-databases": "データベースが見つからないことを表示","n-selected-m-in-total": "({selected} 個が選択され、合計 {total} 個)","doesnt-match-database-name-template": "テナントデータベース名のテンプレートに準拠していません",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 3ccb4cb06b..776de47fd4 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1936,6 +1936,10 @@"select": "选择 schema","unspecified": "未指定"},+ "table": {+ "select": "选择表",+ "select-tip": "请选择一个表来开始查询。"+ },"show-missing-databases": "显示未找到的数据库","n-selected-m-in-total": "(已选择 {selected},共计 {total})","doesnt-match-database-name-template": "不符合租户数据库名称模板",diff --git a/frontend/src/views/sql-editor/EditorCommon/ConnectChooser.vue b/frontend/src/views/sql-editor/EditorCommon/ConnectChooser.vuenew file mode 100644index 0000000000..a6c58c0272--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/ConnectChooser.vue@@ -0,0 +1,127 @@+<template>+ <NPopselect+ :value="value"+ :options="options"+ :show-checkmark="true"+ :virtual-scroll="true"+ :style="overridePopoverPaneStyle"+ placement="bottom-end"+ trigger="click"+ class="schema-chooser-pane"+ @update:show="handleToggleShow"+ @update:value="handleSelect"+ >+ <template #header>+ <div class="font-medium">+ {{ placeholder }}+ </div>+ </template>+ <NButton+ ref="buttonRef"+ size="small"+ ghost+ type="primary"+ style="+ display: inline-flex;+ justify-content: end;+ overflow: hidden;+ --n-padding: 0 7px 0 5px;+ --n-icon-margin: 6px 2px 6px 0;+ --n-color-hover: rgb(var(--color-accent) / 0.05);+ --n-color-pressed: rgb(var(--color-accent) / 0.05);+ --n-color-focus: rgb(var(--color-accent) / 0.05);+ "+ :style="{+ maxWidth: isChosen ? '12rem' : 'unset',+ }"+ >+ <template #icon>+ <SchemaIcon+ class="w-4 h-4"+ :class="isChosen ? 'text-main' : 'text-control-placeholder'"+ />+ </template>+ <span v-if="isChosen" class="truncate text-main">+ {{ value || $t("db.schema.default") }}+ </span>+ <span v-else class="text-control-placeholder whitespace-nowrap">+ {{ placeholder }}+ </span>+ </NButton>+ </NPopselect>+</template>++<script setup lang="tsx">+import { useElementBounding } from "@vueuse/core";+import { NButton, NPopselect, type SelectOption } from "naive-ui";+import { computed, nextTick, ref, watch } from "vue";+import { SchemaIcon } from "@/components/Icon";++defineProps<{+ value: string;+ isChosen: boolean;+ placeholder: string;+ options: SelectOption[];+}>();++const emit = defineEmits<{+ (event: "update:value", value: string): void;+}>();++const popoverPaneRef = ref<HTMLDivElement>();+const popoverPaneBounding = useElementBounding(popoverPaneRef);+const popoverPaneDimensions = ref({+ minWidth: 0,+ maxHeight: 0,+});++const overridePopoverPaneStyle = computed(() => {+ const style: Record<string, any> = {};+ const { maxHeight, minWidth } = popoverPaneDimensions.value;+ if (maxHeight > 0) {+ style["--n-height"] = `${maxHeight}px`;+ }+ if (minWidth > 0) {+ style["min-width"] = `${minWidth}px`;+ }+ style["maxWidth"] = "20rem";+ return style;+});++const handleSelect = async (value: string) => {+ emit("update:value", value);+};++const handleToggleShow = async (show: boolean) => {+ if (!show) return;+ await nextTick();++ const pane = document.querySelector(".schema-chooser-pane") as HTMLDivElement;+ popoverPaneRef.value = pane;+};++// Calculate the max-height of the pane+// to prevent it to be too long to overflow the bottom of the screen+watch(popoverPaneBounding.top, (top) => {+ if (!top) {+ // Cannot calculate max-height+ popoverPaneDimensions.value.maxHeight = 0;+ return;+ }+ const safeZone = 20;+ const MAX_HEIGHT = 320;+ popoverPaneDimensions.value.maxHeight = Math.min(+ window.innerHeight - top - safeZone,+ MAX_HEIGHT+ );+});++// Calculate the width of the pane+// to prevent its height varies when scrolling+watch(popoverPaneBounding.width, (width) => {+ if (!width) return;+ if (width > popoverPaneDimensions.value.minWidth) {+ popoverPaneDimensions.value.minWidth = width;+ }+});+</script>diff --git a/frontend/src/views/sql-editor/EditorCommon/ContainerChooser.vue b/frontend/src/views/sql-editor/EditorCommon/ContainerChooser.vuenew file mode 100644index 0000000000..9f7ef181ba--- /dev/null+++ b/frontend/src/views/sql-editor/EditorCommon/ContainerChooser.vue@@ -0,0 +1,83 @@+<template>+ <ConnectChooser+ v-if="show"+ v-model:value="chosenContainer"+ :options="options"+ :is-chosen="isChosen"+ :placeholder="$t('database.table.select')"+ />+</template>++<script lang="tsx" setup>+import { type SelectOption } from "naive-ui";+import { storeToRefs } from "pinia";+import { computed, watchEffect } from "vue";+import { useI18n } from "vue-i18n";+import { useRoute } from "vue-router";+import {+ useConnectionOfCurrentSQLEditorTab,+ useDBSchemaV1Store,+ useSQLEditorTabStore,+} from "@/store";+import { Engine } from "@/types/proto/v1/common";+import { DatabaseMetadataView } from "@/types/proto/v1/database_service";+import ConnectChooser from "./ConnectChooser.vue";++const OptionValueUnspecified = "-1";++const { t } = useI18n();+const route = useRoute();+const { currentTab: tab } = storeToRefs(useSQLEditorTabStore());+const { database, instance } = useConnectionOfCurrentSQLEditorTab();+const show = computed(() => {+ return instance.value.engine === Engine.COSMOSDB;+});++const databaseMetadata = computed(() => {+ return useDBSchemaV1Store().getDatabaseMetadata(+ database.value.name,+ DatabaseMetadataView.DATABASE_METADATA_VIEW_FULL+ );+});+const options = computed(() => {+ const selectOptions: SelectOption[] = [+ {+ value: OptionValueUnspecified,+ label: t("database.schema.unspecified"),+ },+ ];++ for (const schema of databaseMetadata.value.schemas) {+ for (const table of schema.tables) {+ selectOptions.push({+ value: table.name,+ label: table.name,+ });+ }+ }+ return selectOptions;+});++const chosenContainer = computed<string>({+ get() {+ const table = tab.value?.connection.table;+ if (table === undefined) return OptionValueUnspecified;+ return table;+ },+ set(value) {+ if (!tab.value) return;+ tab.value.connection.table =+ value === OptionValueUnspecified ? undefined : value;+ },+});++watchEffect(() => {+ if (route.query.table) {+ chosenContainer.value = route.query.table as string;+ }+});++const isChosen = computed(() => {+ return chosenContainer.value !== OptionValueUnspecified;+});+</script>diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vueindex 900c2bac16..9af5cf210a 100644--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue@@ -21,24 +21,31 @@</NButton><NButtonGroup v-if="currentTab?.mode !== 'ADMIN'">- <NButton- :disabled="!allowQuery"- type="primary"- size="small"- style="--n-padding: 0 5px"- @click="handleRunQuery"- >- <template #icon>- <PlayIcon class="w-4 h-4 !fill-current" />- </template>- <template #default>- <div class="inline-flex items-center">- <span>(</span>- <span>limit {{ resultRowsLimit }}</span>- <span>)</span>- </div>+ <NTooltip :disabled="!queryTip">+ <template #trigger>+ <NButton+ :disabled="!allowQuery"+ type="primary"+ size="small"+ style="--n-padding: 0 5px"+ @click="handleRunQuery"+ >+ <template #icon>+ <PlayIcon class="w-4 h-4 !fill-current" />+ </template>+ <template #default>+ <div class="inline-flex items-center">+ <span>(</span>+ <span>limit {{ resultRowsLimit }}</span>+ <span>)</span>+ </div>+ </template>+ </NButton></template>- </NButton>+ <span class="text-sm">+ {{ queryTip }}+ </span>+ </NTooltip><QueryContextSettingPopover:disabled="!showQueryContextSettingPopover || !allowQuery"/>@@ -122,6 +129,7 @@<NButtonGroup><DatabaseChooser /><SchemaChooser />+ <ContainerChooser /></NButtonGroup><OpenAIButton@@ -145,9 +153,10 @@ import {SaveIcon,Share2Icon,} from "lucide-vue-next";-import { NButtonGroup, NButton, NPopover } from "naive-ui";+import { NButtonGroup, NButton, NPopover, NTooltip } from "naive-ui";import { storeToRefs } from "pinia";import { computed, reactive } from "vue";+import { useI18n } from "vue-i18n";import { FeatureBadge, FeatureModal } from "@/components/FeatureGuard";import {useUIStateStore,@@ -163,10 +172,12 @@ import {type FeatureType,type SQLEditorQueryParams,} from "@/types";+import { Engine } from "@/types/proto/v1/common";import { keyboardShortcutStr, isWorksheetWritableV1 } from "@/utils";import { useSQLEditorContext } from "../context";import AdminModeButton from "./AdminModeButton.vue";import BatchQueryDatabasesSelector from "./BatchQueryDatabasesSelector.vue";+import ContainerChooser from "./ContainerChooser.vue";import DatabaseChooser from "./DatabaseChooser.vue";import OpenAIButton from "./OpenAIButton";import QueryContextSettingPopover from "./QueryContextSettingPopover.vue";@@ -209,16 +220,31 @@ const isExecutingSQL = computed(() => currentTab.value?.queryContext?.status === "EXECUTING");const { instance } = useConnectionOfCurrentSQLEditorTab();+const { t } = useI18n();const showSheetsFeature = computed(() => {const mode = currentTab.value?.mode;return mode === "WORKSHEET";});+const queryTip = computed(() => {+ if (+ instance.value.engine === Engine.COSMOSDB &&+ !currentTab.value?.connection.table+ ) {+ return t("database.table.select-tip");+ }+ return "";+});+const allowQuery = computed(() => {if (isDisconnected.value) return false;if (isEmptyStatement.value) return false;if (isExecutingSQL.value) return false;++ if (instance.value.engine === Engine.COSMOSDB) {+ return !!currentTab.value?.connection.table;+ }return true;});diff --git a/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue b/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vueindex a558141255..1e50c85ff3 100644--- a/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue+++ b/frontend/src/views/sql-editor/EditorCommon/SchemaChooser.vue@@ -1,64 +1,19 @@<template>- <NPopselect+ <ConnectChooserv-if="show"- :value="chosenSchema"+ v-model:value="chosenSchema":options="options"- :show-checkmark="true"- :virtual-scroll="true"- :style="overridePopoverPaneStyle"- placement="bottom-end"- trigger="click"- class="schema-chooser-pane"- @update:show="handleToggleShow"- @update:value="handleSelect"- >- <template #header>- <div class="font-medium">- {{ $t("database.schema.select") }}- </div>- </template>- <NButton- ref="buttonRef"- size="small"- ghost- type="primary"- style="- display: inline-flex;- justify-content: end;- overflow: hidden;- --n-padding: 0 7px 0 5px;- --n-icon-margin: 6px 2px 6px 0;- --n-color-hover: rgb(var(--color-accent) / 0.05);- --n-color-pressed: rgb(var(--color-accent) / 0.05);- --n-color-focus: rgb(var(--color-accent) / 0.05);- "- :style="{- maxWidth: isChosen ? '12rem' : 'unset',- }"- >- <template #icon>- <SchemaIcon- class="w-4 h-4"- :class="isChosen ? 'text-main' : 'text-control-placeholder'"- />- </template>- <span v-if="isChosen" class="truncate text-main">- {{ chosenSchema || $t("db.schema.default") }}- </span>- <span v-else class="text-control-placeholder whitespace-nowrap">- {{ $t("database.schema.select") }}- </span>- </NButton>- </NPopselect>+ :is-chosen="isChosen"+ :placeholder="$t('database.schema.select')"+ /></template><script setup lang="ts">-import { useElementBounding } from "@vueuse/core";-import { NButton, NPopselect, type SelectOption } from "naive-ui";+import { type SelectOption } from "naive-ui";import { storeToRefs } from "pinia";-import { computed, nextTick, ref, watch } from "vue";+import { computed, watchEffect } from "vue";import { useI18n } from "vue-i18n";-import { SchemaIcon } from "@/components/Icon";+import { useRoute } from "vue-router";import {useConnectionOfCurrentSQLEditorTab,useDBSchemaV1Store,@@ -66,36 +21,18 @@ import {} from "@/store";import { DatabaseMetadataView } from "@/types/proto/v1/database_service";import { instanceAllowsSchemaScopedQuery } from "@/utils";+import ConnectChooser from "./ConnectChooser.vue";const SchemaOptionValueUnspecified = "-1";const { t } = useI18n();+const route = useRoute();const { currentTab: tab } = storeToRefs(useSQLEditorTabStore());const { database, instance } = useConnectionOfCurrentSQLEditorTab();const show = computed(() => {return instanceAllowsSchemaScopedQuery(instance.value.engine);});-const popoverPaneRef = ref<HTMLDivElement>();-const popoverPaneBounding = useElementBounding(popoverPaneRef);-const popoverPaneDimensions = ref({- minWidth: 0,- maxHeight: 0,-});--const overridePopoverPaneStyle = computed(() => {- const style: Record<string, any> = {};- const { maxHeight, minWidth } = popoverPaneDimensions.value;- if (maxHeight > 0) {- style["--n-height"] = `${maxHeight}px`;- }- if (minWidth > 0) {- style["min-width"] = `${minWidth}px`;- }- style["maxWidth"] = "20rem";- return style;-});-const databaseMetadata = computed(() => {return useDBSchemaV1Store().getDatabaseMetadata(database.value.name,@@ -129,44 +66,13 @@ const chosenSchema = computed<string>({},});-const isChosen = computed(() => {- return chosenSchema.value !== SchemaOptionValueUnspecified;-});--const handleSelect = async (value: string) => {- chosenSchema.value = value;-};--const handleToggleShow = async (show: boolean) => {- if (!show) return;- await nextTick();-- const pane = document.querySelector(".schema-chooser-pane") as HTMLDivElement;- popoverPaneRef.value = pane;-};--// Calculate the max-height of the pane-// to prevent it to be too long to overflow the bottom of the screen-watch(popoverPaneBounding.top, (top) => {- if (!top) {- // Cannot calculate max-height- popoverPaneDimensions.value.maxHeight = 0;- return;+watchEffect(() => {+ if (route.query.schema) {+ chosenSchema.value = route.query.schema as string;}- const safeZone = 20;- const MAX_HEIGHT = 320;- popoverPaneDimensions.value.maxHeight = Math.min(- window.innerHeight - top - safeZone,- MAX_HEIGHT- );});-// Calculate the width of the pane-// to prevent its height varies when scrolling-watch(popoverPaneBounding.width, (width) => {- if (!width) return;- if (width > popoverPaneDimensions.value.minWidth) {- popoverPaneDimensions.value.minWidth = width;- }+const isChosen = computed(() => {+ return chosenSchema.value !== SchemaOptionValueUnspecified;});</script>