Skip to content

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

chore(sql-editor): label selector improvements (#12616)

Liu Ji5132dbe6dcd3
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/GroupingBar/AddFactorButton.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/GroupingBar/AddFactorButton.vue
index fff699ea21..ff379f7008 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/GroupingBar/AddFactorButton.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/GroupingBar/AddFactorButton.vue
@@ -2,9 +2,13 @@
<NPopselect
v-if="visible"
:options="options"
+ :virtual-scroll="true"
trigger="click"
placement="right-start"
+ class="add-factor-pane"
+ :style="overridePopoverPaneStyle"
@update:value="handleSelect"
+ @update:show="handleToggleShow"
>
<NButton size="small" style="--n-padding: 4px">
<template #icon>
@@ -15,10 +19,11 @@
</template>
<script setup lang="ts">
+import { useElementBounding } from "@vueuse/core";
import { PlusIcon } from "lucide-vue-next";
import { NButton, type SelectOption } from "naive-ui";
import { storeToRefs } from "pinia";
-import { computed, h, nextTick } from "vue";
+import { computed, h, nextTick, ref, watch } from "vue";
import { useSQLEditorTreeStore } from "@/store";
import { readableSQLEditorTreeFactor } from "@/types";
import { useSQLEditorContext } from "@/views/sql-editor/context";
@@ -26,6 +31,25 @@ import { useSQLEditorContext } from "@/views/sql-editor/context";
const { events } = useSQLEditorContext();
const treeStore = useSQLEditorTreeStore();
const { factorList, availableFactorList } = storeToRefs(treeStore);
+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 restFactorList = computed(() => {
const factors = new Set(factorList.value.map((f) => f.factor));
@@ -56,6 +80,9 @@ const options = computed(() => {
if (label.length === 0) {
return preset;
}
+ if (preset.length === 0) {
+ return label;
+ }
return [
{
type: "group",
@@ -85,4 +112,33 @@ const handleSelect = async (factor: string) => {
await nextTick();
events.emit("tree-ready");
};
+
+const handleToggleShow = async (show: boolean) => {
+ if (!show) return;
+ await nextTick();
+
+ const pane = document.querySelector(".add-factor-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;
+ popoverPaneDimensions.value.maxHeight = window.innerHeight - top - safeZone;
+});
+
+// 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>