Skip to content

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

feat(sql-editor): expand schema and tables in connection tree dynamically (#8067)

Liu Ji48e8eed179bd
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 152f1d9eb4..0cd6057d4a 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -97,7 +97,97 @@ const prepareAccessibleDatabaseList = async () => {
connectionTreeStore.tree.databaseList = databaseList;
};
-const prepareConnectionTree = async () => {
+const connectionTreeCache: Record<"instance" | "project", ConnectionAtom[]> = {
+ project: [],
+ instance: [],
+};
+
+const initializeConnectionTree = async () => {
+ const build = (mode: ConnectionTreeMode): ConnectionAtom[] => {
+ if (mode) {
+ const { databaseList } = connectionTreeStore.tree;
+ const instanceList = uniqBy(
+ databaseList.map((db) => db.instanceEntity),
+ (instance) => instance.uid
+ );
+ const tree = instanceList.map((instance) => {
+ const node = connectionTreeStore.mapAtom(
+ instance,
+ "instance",
+ undefined /* ROOT */
+ );
+ return node;
+ });
+
+ for (const instance of instanceList) {
+ const instanceItem = tree.find(
+ (item: ConnectionAtom) => item.id === instance.uid
+ )!;
+
+ instanceItem.children = databaseList
+ .filter((db) => db.instanceEntity.uid === instance.uid)
+ .map((db) => {
+ const node = connectionTreeStore.mapAtom(
+ db,
+ "database",
+ instanceItem
+ );
+ node.disabled = !isDatabaseV1Queryable(db, currentUserV1.value);
+ if (node.disabled) {
+ // If a database node is not accessible
+ // it's not expandable either.
+ node.isLeaf = true;
+ }
+ return node;
+ });
+ }
+ return tree;
+ } else {
+ const databaseList = connectionTreeStore.tree.databaseList.filter(
+ (db) => {
+ return db.project !== DEFAULT_PROJECT_V1_NAME;
+ }
+ );
+ const projectList = uniqBy(
+ databaseList.map((db) => db.projectEntity),
+ (project) => project.uid
+ );
+
+ const projectAtomList = projectList.map((project) => {
+ const node = connectionTreeStore.mapAtom(
+ project,
+ "project",
+ undefined /* ROOT */
+ );
+ return node;
+ });
+
+ projectAtomList.forEach((projectAtom) => {
+ projectAtom.children = databaseList
+ .filter((db) => db.projectEntity.uid === projectAtom.id)
+ .map((db) => {
+ const node = connectionTreeStore.mapAtom(
+ db,
+ "database",
+ projectAtom
+ );
+ node.disabled = !isDatabaseV1Queryable(db, currentUserV1.value);
+ if (node.disabled) {
+ // If a database node is not accessible
+ // it's not expandable either.
+ node.isLeaf = true;
+ }
+ return node;
+ });
+ });
+
+ return projectAtomList;
+ }
+ };
+
+ connectionTreeCache.instance = build(ConnectionTreeMode.INSTANCE);
+ connectionTreeCache.project = build(ConnectionTreeMode.PROJECT);
+
if (connectionTreeStore.tree.mode === ConnectionTreeMode.INSTANCE) {
if (
!hasWorkspacePermissionV1(
@@ -108,79 +198,21 @@ const prepareConnectionTree = async () => {
connectionTreeStore.tree.mode = ConnectionTreeMode.PROJECT;
return;
}
- const { databaseList } = connectionTreeStore.tree;
- const instanceList = uniqBy(
- databaseList.map((db) => db.instanceEntity),
- (instance) => instance.uid
- );
- const connectionTree = instanceList.map((instance) => {
- const node = connectionTreeStore.mapAtom(instance, "instance", "0");
- return node;
- });
-
- for (const instance of instanceList) {
- const instanceItem = connectionTree.find(
- (item: ConnectionAtom) => item.id === instance.uid
- )!;
-
- instanceItem.children = databaseList
- .filter((db) => db.instanceEntity.uid === instance.uid)
- .map((db) => {
- const node = connectionTreeStore.mapAtom(
- db,
- "database",
- instance.uid
- );
- node.disabled = !isDatabaseV1Queryable(db, currentUserV1.value);
- if (node.disabled) {
- // If a database node is not accessible
- // it's not expandable either.
- node.isLeaf = true;
- }
- return node;
- });
- }
- connectionTreeStore.tree.data = connectionTree;
- } else {
- const databaseList = connectionTreeStore.tree.databaseList.filter((db) => {
- return db.project !== DEFAULT_PROJECT_V1_NAME;
- });
- const projectList = uniqBy(
- databaseList.map((db) => db.projectEntity),
- (project) => project.uid
- );
-
- const projectAtomList = projectList.map((project) => {
- const node = connectionTreeStore.mapAtom(project, "project", "0");
- return node;
- });
-
- projectAtomList.forEach((projectAtom) => {
- projectAtom.children = databaseList
- .filter((db) => db.projectEntity.uid === projectAtom.id)
- .map((db) => {
- const node = connectionTreeStore.mapAtom(
- db,
- "database",
- projectAtom.id
- );
- node.disabled = !isDatabaseV1Queryable(db, currentUserV1.value);
- if (node.disabled) {
- // If a database node is not accessible
- // it's not expandable either.
- node.isLeaf = true;
- }
- return node;
- });
- });
-
- connectionTreeStore.tree.data = projectAtomList;
}
-
// Won't fetch tableList for every database here.
// Will fetch them asynchronously only when a database node opens.
};
+const switchConnectionTree = () => {
+ const tree = connectionTreeStore.tree;
+ const mode = tree.mode;
+ if (mode === ConnectionTreeMode.INSTANCE) {
+ tree.data = connectionTreeCache.instance;
+ } else {
+ tree.data = connectionTreeCache.project;
+ }
+};
+
const prepareSheet = async () => {
const sheetSlug = (route.params.sheetSlug as string) || "";
if (!sheetSlug) {
@@ -396,10 +428,11 @@ onMounted(async () => {
await usePolicyV1Store().getOrFetchPolicyByName("policies/WORKSPACE_IAM");
await prepareAccessControlPolicy();
await prepareAccessibleDatabaseList();
+ await initializeConnectionTree();
connectionTreeStore.tree.state = ConnectionTreeState.LOADED;
}
- watch(() => connectionTreeStore.tree.mode, prepareConnectionTree, {
+ watch(() => connectionTreeStore.tree.mode, switchConnectionTree, {
immediate: true,
});
diff --git a/frontend/src/store/modules/connectionTree.ts b/frontend/src/store/modules/connectionTree.ts
index 0bc392280f..d4b5403329 100644
--- a/frontend/src/store/modules/connectionTree.ts
+++ b/frontend/src/store/modules/connectionTree.ts
@@ -11,6 +11,10 @@ import {
} from "@/types";
import { ConnectionTreeState, UNKNOWN_ID } from "@/types";
import { Engine } from "@/types/proto/v1/common";
+import {
+ SchemaMetadata,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
import { Policy } from "@/types/proto/v1/org_policy_service";
import { Project } from "@/types/proto/v1/project_service";
import { emptyConnection } from "@/utils";
@@ -20,6 +24,9 @@ import {
useDBSchemaV1Store,
} from "./v1";
+export const ROOT_NODE_ID = "ROOT";
+export const CONNECTION_TREE_DELIMITER = "->";
+
// Normalize value, fallback to ConnectionTreeMode.PROJECT
const normalizeConnectionTreeMode = (raw: string) => {
if (raw === ConnectionTreeMode.INSTANCE) {
@@ -49,7 +56,6 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {
state: ConnectionTreeState.UNSET,
});
const expandedTreeNodeKeys = ref<string[]>([]);
- const selectedTableAtom = ref<ConnectionAtom>();
// actions
const fetchConnectionByInstanceIdAndDatabaseId = async (
@@ -89,14 +95,20 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {
};
// utilities
const mapAtom = (
- item: Project | ComposedInstance | ComposedDatabase,
+ item:
+ | Project
+ | ComposedInstance
+ | ComposedDatabase
+ | SchemaMetadata
+ | TableMetadata,
type: ConnectionAtomType,
- parentId: string
+ parent: ConnectionAtom | undefined,
+ children?: ConnectionAtom[]
) => {
- const id = item.uid;
+ const id = idForConnectionAtomItem(type, item, parent);
const key = `${type}-${id}`;
const connectionAtom: ConnectionAtom = {
- parentId,
+ parentId: parent?.id ?? ROOT_NODE_ID,
id,
key,
label:
@@ -106,9 +118,14 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {
? (item as ComposedInstance).title
: type === "database"
? (item as ComposedDatabase).databaseName
+ : type === "schema"
+ ? (item as SchemaMetadata).name
+ : type === "table"
+ ? (item as TableMetadata).name
: "",
type,
- isLeaf: type === "database",
+ isLeaf: type === "table",
+ children,
};
return connectionAtom;
};
@@ -125,7 +142,6 @@ export const useConnectionTreeStore = defineStore("connectionTree", () => {
accessControlPolicyList,
tree,
expandedTreeNodeKeys,
- selectedTableAtom,
fetchConnectionByInstanceIdAndDatabaseId,
fetchConnectionByInstanceId,
mapAtom,
@@ -199,3 +215,34 @@ export const isConnectableAtom = (atom: ConnectionAtom): boolean => {
}
return false;
};
+
+export const idForConnectionAtomItem = (
+ type: ConnectionAtomType,
+ item:
+ | Project
+ | ComposedInstance
+ | ComposedDatabase
+ | SchemaMetadata
+ | TableMetadata,
+ parent: ConnectionAtom | undefined
+) => {
+ if (type === "project" || type === "instance" || type === "database") {
+ const target = item as Project | ComposedInstance | ComposedDatabase;
+ return target.uid;
+ }
+ if (type === "schema") {
+ const target = item as SchemaMetadata;
+ return [parent?.id ?? ROOT_NODE_ID, target.name].join(
+ CONNECTION_TREE_DELIMITER
+ );
+ }
+ if (type === "table") {
+ const target = item as TableMetadata;
+ return [parent?.id ?? ROOT_NODE_ID, target.name].join(
+ CONNECTION_TREE_DELIMITER
+ );
+ }
+
+ console.error("should never reach this line", type, item);
+ return "";
+};
diff --git a/frontend/src/types/connectionTree.ts b/frontend/src/types/connectionTree.ts
index 0feaad9275..86e71c9fbd 100644
--- a/frontend/src/types/connectionTree.ts
+++ b/frontend/src/types/connectionTree.ts
@@ -1,4 +1,9 @@
-export type ConnectionAtomType = "project" | "instance" | "database";
+export type ConnectionAtomType =
+ | "project"
+ | "instance"
+ | "database"
+ | "schema"
+ | "table";
export enum ConnectionTreeState {
UNSET,
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index 528d5b9470..708b34a55b 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -31,6 +31,7 @@
:render-prefix="renderPrefix"
:node-props="nodeProps"
:virtual-scroll="true"
+ @load="handleLoadSubTree"
@update:expanded-keys="updateExpandedKeys"
/>
</div>
@@ -65,6 +66,8 @@ import {
useSQLEditorStore,
useIsLoggedIn,
useTabStore,
+ CONNECTION_TREE_DELIMITER,
+ useDBSchemaV1Store,
} from "@/store";
import type { ConnectionAtom, CoreTabInfo, DatabaseId } from "@/types";
import {
@@ -73,6 +76,7 @@ import {
TabMode,
UNKNOWN_ID,
} from "@/types";
+import { SchemaMetadata } from "@/types/proto/v1/database_service";
import {
emptyConnection,
getSuggestedTabNameFromConnection,
@@ -84,7 +88,9 @@ import {
isSimilarTab,
instanceV1AllowsCrossDatabaseQuery,
} from "@/utils";
+import { useSQLEditorContext } from "../context";
import { Prefix, Label } from "./TreeNode";
+import { fetchDatabaseSubTree } from "./common";
type Position = {
x: number;
@@ -116,6 +122,7 @@ const tabStore = useTabStore();
const isLoggedIn = useIsLoggedIn();
const currentUserV1 = useCurrentUserV1();
const sqlEditorStore = useSQLEditorStore();
+const { selectedDatabaseSchema } = useSQLEditorContext();
const mounted = useMounted();
const treeRef = ref<InstanceType<typeof NTree>>();
@@ -194,6 +201,26 @@ const allowAdmin = computed(() =>
const treeData = computed(() => connectionTreeStore.tree.data);
+const connect = (target: CoreTabInfo) => {
+ if (isSimilarTab(target, tabStore.currentTab)) {
+ // Don't go further if the connection doesn't change.
+ return;
+ }
+ if (tabStore.currentTab.isFreshNew) {
+ // If the current tab is "fresh new", update its connection directly.
+ tabStore.updateCurrentTab(target);
+ } else {
+ // Otherwise select or add a new tab and set its connection
+ const name = getSuggestedTabNameFromConnection(target.connection);
+ tabStore.selectOrAddSimilarTab(
+ target,
+ /* beside */ false,
+ /* defaultTabName */ name
+ );
+ tabStore.updateCurrentTab(target);
+ }
+};
+
const setConnection = (
option: ConnectionAtom,
extra: { sheetName?: string; mode: TabMode } = {
@@ -202,6 +229,11 @@ const setConnection = (
}
) => {
if (option) {
+ if (option.type === "schema" || option.type === "table") {
+ // Should be handled in maybeSelectTable
+ return;
+ }
+
if (option.type === "project") {
// Not connectable to a project
return;
@@ -220,26 +252,6 @@ const setConnection = (
};
const conn = target.connection;
- const connect = () => {
- if (isSimilarTab(target, tabStore.currentTab)) {
- // Don't go further if the connection doesn't change.
- return;
- }
- if (tabStore.currentTab.isFreshNew) {
- // If the current tab is "fresh new", update its connection directly.
- tabStore.updateCurrentTab(target);
- } else {
- // Otherwise select or add a new tab and set its connection
- const name = getSuggestedTabNameFromConnection(target.connection);
- tabStore.selectOrAddSimilarTab(
- target,
- /* beside */ false,
- /* defaultTabName */ name
- );
- tabStore.updateCurrentTab(target);
- }
- };
-
// If selected item is instance node
if (option.type === "instance") {
conn.instanceId = option.id;
@@ -250,7 +262,7 @@ const setConnection = (
conn.databaseId = database.uid;
}
- connect();
+ connect(target);
}
};
@@ -310,6 +322,52 @@ const maybeExpandKey = (key: string) => {
}
};
+const maybeSelectTable = async (atom: ConnectionAtom) => {
+ const parts = atom.id.split(CONNECTION_TREE_DELIMITER);
+ if (parts.length < 2 || parts.length > 3) {
+ return;
+ }
+ const database = databaseStore.getDatabaseByUID(parts[0]);
+ if (database.uid !== tabStore.currentTab.connection.databaseId) {
+ const target: CoreTabInfo = {
+ connection: {
+ instanceId: database.instanceEntity.uid,
+ databaseId: database.uid,
+ },
+ mode: TabMode.ReadOnly,
+ };
+ target.connection.instanceId = database.instanceEntity.uid;
+ target.connection.databaseId = database.uid;
+
+ connect(target);
+ await nextTick();
+ }
+ const databaseMetadata =
+ await useDBSchemaV1Store().getOrFetchDatabaseMetadata(database.name);
+ let schemaMetadata: SchemaMetadata | undefined = undefined;
+ if (parts.length === 2) {
+ // database -> table
+ schemaMetadata = databaseMetadata.schemas.find((s) => s.name === "");
+ }
+ if (parts.length === 3) {
+ // database -> schema -> table
+ const schema = parts[1];
+ schemaMetadata = databaseMetadata.schemas.find((s) => s.name === schema);
+ }
+ if (!schemaMetadata) {
+ return;
+ }
+ const table = parts[parts.length - 1];
+ const tableMetadata = schemaMetadata.tables.find((t) => t.name === table);
+ if (!tableMetadata) {
+ return;
+ }
+ selectedDatabaseSchema.value = {
+ schema: schemaMetadata,
+ table: tableMetadata,
+ };
+};
+
const nodeProps = ({ option }: { option: TreeOption }) => {
const atom = option as any as ConnectionAtom;
return {
@@ -322,6 +380,9 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
if (atom.type === "instance" || atom.type === "database") {
setConnection(atom);
}
+ if (atom.type === "table") {
+ maybeSelectTable(atom);
+ }
}
},
onContextmenu(e: MouseEvent) {
@@ -341,10 +402,17 @@ const nodeProps = ({ option }: { option: TreeOption }) => {
};
};
+const handleLoadSubTree = (node: TreeOption) => {
+ const atom = node as any as ConnectionAtom;
+ const type = atom.type;
+ if (type === "database") {
+ return fetchDatabaseSubTree(atom);
+ }
+ return Promise.resolve();
+};
+
const updateExpandedKeys = (keys: string[]) => {
- connectionTreeStore.expandedTreeNodeKeys = keys.filter(
- (key) => !key.startsWith("database-")
- );
+ connectionTreeStore.expandedTreeNodeKeys = keys;
};
// When switching tabs, scroll the matched node into view if needed.
diff --git a/frontend/src/views/sql-editor/AsidePanel/TreeNode/Prefix.vue b/frontend/src/views/sql-editor/AsidePanel/TreeNode/Prefix.vue
index 61634103e9..f524765cd3 100644
--- a/frontend/src/views/sql-editor/AsidePanel/TreeNode/Prefix.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/TreeNode/Prefix.vue
@@ -23,6 +23,12 @@
<heroicons-outline:database class="w-4 h-4" />
</span>
</template>
+ <template v-else-if="atom.type === 'schema'">
+ <carbon:data-structured class="w-4 h-4" />
+ </template>
+ <template v-else-if="atom.type === 'table'">
+ <heroicons-outline:table class="h-4 w-4" />
+ </template>
</template>
<script lang="ts" setup>
diff --git a/frontend/src/views/sql-editor/AsidePanel/common.ts b/frontend/src/views/sql-editor/AsidePanel/common.ts
new file mode 100644
index 0000000000..3570041c43
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/common.ts
@@ -0,0 +1,42 @@
+import {
+ useConnectionTreeStore,
+ useDatabaseV1Store,
+ useDBSchemaV1Store,
+} from "@/store";
+import { ConnectionAtom } from "@/types";
+
+export const fetchDatabaseSubTree = async (atom: ConnectionAtom) => {
+ const uid = atom.id;
+ const db = useDatabaseV1Store().getDatabaseByUID(uid);
+ const databaseMetadata =
+ await useDBSchemaV1Store().getOrFetchDatabaseMetadata(db.name);
+ const { schemas } = databaseMetadata;
+ if (schemas.length === 0) {
+ // Empty database
+ atom.children = [];
+ return;
+ }
+
+ if (schemas.length === 1 && schemas[0].name === "") {
+ // A single schema database, should render tables directly as a database
+ // node's children
+ atom.children = schemas[0].tables.map((table) =>
+ useConnectionTreeStore().mapAtom(table, "table", atom)
+ );
+ return;
+ } else {
+ // Multiple schema database
+ atom.children = schemas.map((schema) => {
+ const schemaNode = useConnectionTreeStore().mapAtom(
+ schema,
+ "schema",
+ atom
+ );
+ schemaNode.children = schema.tables.map((table) =>
+ useConnectionTreeStore().mapAtom(table, "table", schemaNode)
+ );
+ return schemaNode;
+ });
+ return;
+ }
+};
diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vue
index b57db8caa4..67c3364b4b 100644
--- a/frontend/src/views/sql-editor/SQLEditorPage.vue
+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue
@@ -1,56 +1,56 @@
<template>
<div class="sqleditor--wrapper">
- <div class="flex-1 flex flex-row h-full">
- <Splitpanes
- class="default-theme flex flex-col flex-1 overflow-hidden"
- :dbl-click-splitter="false"
- >
- <Pane v-if="windowWidth >= 800" size="20">
- <AsidePanel @alter-schema="handleAlterSchema" />
- </Pane>
- <template v-else>
- <teleport to="body">
- <div
- id="fff"
- class="fixed rounded-full border border-control-border shadow-lg w-10 h-10 bottom-[4rem] flex items-center justify-center bg-white hover:bg-control-bg cursor-pointer z-[99999999] transition-all"
- :class="[
- state.sidebarExpanded
- ? 'left-[80%] -translate-x-5'
- : 'left-[1rem]',
- ]"
- style="
- transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
- transition-duration: 300ms;
- "
- @click="state.sidebarExpanded = !state.sidebarExpanded"
- >
- <heroicons-outline:chevron-left
- class="w-6 h-6 transition-transform"
- :class="[state.sidebarExpanded ? '' : '-scale-100']"
- />
- </div>
- <NDrawer
- v-model:show="state.sidebarExpanded"
- width="80vw"
- placement="left"
- >
- <AsidePanel @alter-schema="handleAlterSchema" />
- </NDrawer>
- </teleport>
- </template>
- <Pane class="relative flex flex-col">
- <TabList />
+ <Splitpanes
+ class="default-theme flex flex-col flex-1 overflow-hidden"
+ :dbl-click-splitter="false"
+ >
+ <Pane v-if="windowWidth >= 800" size="20">
+ <AsidePanel @alter-schema="handleAlterSchema" />
+ </Pane>
+ <template v-else>
+ <teleport to="body">
+ <div
+ id="fff"
+ class="fixed rounded-full border border-control-border shadow-lg w-10 h-10 bottom-[4rem] flex items-center justify-center bg-white hover:bg-control-bg cursor-pointer z-[99999999] transition-all"
+ :class="[
+ state.sidebarExpanded
+ ? 'left-[80%] -translate-x-5'
+ : 'left-[1rem]',
+ ]"
+ style="
+ transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
+ transition-duration: 300ms;
+ "
+ @click="state.sidebarExpanded = !state.sidebarExpanded"
+ >
+ <heroicons-outline:chevron-left
+ class="w-6 h-6 transition-transform"
+ :class="[state.sidebarExpanded ? '' : '-scale-100']"
+ />
+ </div>
+ <NDrawer
+ v-model:show="state.sidebarExpanded"
+ width="80vw"
+ placement="left"
+ >
+ <AsidePanel @alter-schema="handleAlterSchema" />
+ </NDrawer>
+ </teleport>
+ </template>
+ <Pane class="relative flex flex-col">
+ <TabList />
- <div class="w-full flex-1 overflow-hidden">
- <template v-if="allowAccess">
- <template v-if="tabStore.currentTab.mode === TabMode.ReadOnly">
- <Splitpanes
- v-if="allowReadOnlyMode"
- horizontal
- class="default-theme"
- :dbl-click-splitter="false"
- >
- <Pane>
+ <div class="w-full flex-1 overflow-hidden">
+ <template v-if="allowAccess">
+ <template v-if="tabStore.currentTab.mode === TabMode.ReadOnly">
+ <Splitpanes
+ v-if="allowReadOnlyMode"
+ horizontal
+ class="default-theme"
+ :dbl-click-splitter="false"
+ >
+ <Pane class="flex flex-row overflow-hidden">
+ <div class="h-full flex-1 overflow-hidden">
<Splitpanes
vertical
class="default-theme"
@@ -66,64 +66,65 @@
<SecondarySidebar @alter-schema="handleAlterSchema" />
</Pane>
</Splitpanes>
- </Pane>
- <Pane v-if="!isDisconnected" :size="40">
- <ResultPanel />
- </Pane>
- </Splitpanes>
+ </div>
- <div
- v-else
- class="w-full h-full flex flex-col items-center justify-center gap-y-2"
- >
- <img
- src="../../assets/illustration/403.webp"
- class="max-h-[40%]"
- />
- <i18n-t
- class="textinfolabel flex items-center"
- keypath="sql-editor.allow-admin-mode-only"
- tag="div"
+ <div
+ v-if="windowWidth >= 1024"
+ class="h-full border-l shrink-0"
>
- <template #instance>
- <InstanceV1Name :instance="instance" :link="false" />
- </template>
- </i18n-t>
- <AdminModeButton />
- </div>
- </template>
+ <SecondaryGutterBar />
+ </div>
+ </Pane>
+ <Pane v-if="!isDisconnected" :size="40">
+ <ResultPanel />
+ </Pane>
+ </Splitpanes>
- <TerminalPanelV1
- v-if="tabStore.currentTab.mode === TabMode.Admin"
- />
- </template>
- <div
- v-else
- class="w-full h-full flex flex-col items-center justify-center"
- >
- <img
- src="../../assets/illustration/403.webp"
- class="max-h-[40%]"
- />
- <div class="textinfolabel">
- {{ $t("database.access-denied") }}
+ <div
+ v-else
+ class="w-full h-full flex flex-col items-center justify-center gap-y-2"
+ >
+ <img
+ src="../../assets/illustration/403.webp"
+ class="max-h-[40%]"
+ />
+ <i18n-t
+ class="textinfolabel flex items-center"
+ keypath="sql-editor.allow-admin-mode-only"
+ tag="div"
+ >
+ <template #instance>
+ <InstanceV1Name :instance="instance" :link="false" />
+ </template>
+ </i18n-t>
+ <AdminModeButton />
</div>
- </div>
- </div>
+ </template>
+ <TerminalPanelV1
+ v-if="tabStore.currentTab.mode === TabMode.Admin"
+ />
+ </template>
<div
- v-if="isFetchingSheet"
- class="flex items-center justify-center absolute inset-0 bg-white/50 z-20"
+ v-else
+ class="w-full h-full flex flex-col items-center justify-center"
>
- <BBSpin />
+ <img src="../../assets/illustration/403.webp" class="max-h-[40%]" />
+ <div class="textinfolabel">
+ {{ $t("database.access-denied") }}
+ </div>
</div>
- </Pane>
- </Splitpanes>
+ </div>
+
+ <div
+ v-if="isFetchingSheet"
+ class="flex items-center justify-center absolute inset-0 bg-white/50 z-20"
+ >
+ <BBSpin />
+ </div>
+ </Pane>
+ </Splitpanes>
- <div v-if="windowWidth >= 1024" class="h-full border-l shrink-0">
- <SecondaryGutterBar />
- </div>
- </div>
<Quickstart />
<Drawer v-model:show="showSheetPanel">
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
index 0cc430ec2f..9bda0135ac 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/InfoTabPane/SchemaPanel/SchemaPanel.vue
@@ -18,20 +18,20 @@
<DatabaseSchema
:database="database"
:database-metadata="databaseMetadata"
- :header-clickable="state.selected !== undefined"
- @click-header="state.selected = undefined"
+ :header-clickable="selected !== undefined"
+ @click-header="selected = undefined"
@select-table="handleSelectTable"
@alter-schema="emit('alter-schema', $event)"
/>
<Transition name="slide-up" appear>
<TableSchema
- v-if="state.selected"
+ v-if="selected"
class="absolute bottom-0 w-full h-[calc(100%-33px)] bg-white"
:database="database"
:database-metadata="databaseMetadata"
- :schema="state.selected.schema"
- :table="state.selected.table"
- @close="state.selected = undefined"
+ :schema="selected.schema"
+ :table="selected.table"
+ @close="selected = undefined"
@alter-schema="emit('alter-schema', $event)"
/>
</Transition>
@@ -49,21 +49,18 @@
<script lang="ts" setup>
import { storeToRefs } from "pinia";
-import { computed, reactive, ref, watch } from "vue";
+import { computed, ref, watch } from "vue";
import { useDatabaseV1ByUID, useDBSchemaV1Store, useTabStore } from "@/store";
import {
DatabaseMetadata,
SchemaMetadata,
TableMetadata,
} from "@/types/proto/v1/database_service";
+import { useSQLEditorContext } from "@/views/sql-editor/context";
import DatabaseSchema from "./DatabaseSchema.vue";
import TableSchema from "./TableSchema.vue";
import { provideSchemaPanelContext } from "./context";
-type LocalState = {
- selected?: { schema: SchemaMetadata; table: TableMetadata };
-};
-
const emit = defineEmits<{
(
event: "alter-schema",
@@ -71,9 +68,7 @@ const emit = defineEmits<{
): void;
}>();
-const state = reactive<LocalState>({
- selected: undefined,
-});
+const { selectedDatabaseSchema: selected } = useSQLEditorContext();
const dbSchemaStore = useDBSchemaV1Store();
const { currentTab } = storeToRefs(useTabStore());
@@ -84,13 +79,13 @@ const { database } = useDatabaseV1ByUID(computed(() => conn.value.databaseId));
const databaseMetadata = ref<DatabaseMetadata>();
const handleSelectTable = (schema: SchemaMetadata, table: TableMetadata) => {
- state.selected = { schema, table };
+ selected.value = { schema, table };
};
watch(
() => database.value.name,
async (name) => {
- state.selected = undefined;
+ selected.value = undefined;
databaseMetadata.value = await dbSchemaStore.getOrFetchDatabaseMetadata(
name,
/* !skipCache */ false
diff --git a/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue
index 537f2f246c..fd58ec4558 100644
--- a/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue
+++ b/frontend/src/views/sql-editor/SecondarySidebar/SecondaryGutterBar/SecondaryGutterBar.vue
@@ -1,5 +1,5 @@
<template>
- <div class="flex flex-col items-stretch justify-start text-sm space-y-2">
+ <div class="h-full flex flex-col items-stretch justify-between text-sm pb-1">
<div class="divide-y border-b">
<div
v-if="showInfoPane"
diff --git a/frontend/src/views/sql-editor/context.ts b/frontend/src/views/sql-editor/context.ts
index b45d9b1a43..3d20a7086c 100644
--- a/frontend/src/views/sql-editor/context.ts
+++ b/frontend/src/views/sql-editor/context.ts
@@ -1,5 +1,9 @@
import Emittery from "emittery";
import { InjectionKey, inject, provide, Ref, ref } from "vue";
+import {
+ SchemaMetadata,
+ TableMetadata,
+} from "@/types/proto/v1/database_service";
type SQLEditorEvents = Emittery<{
// nothing by now
@@ -7,6 +11,9 @@ type SQLEditorEvents = Emittery<{
export type SQLEditorContext = {
showAIChatBox: Ref<boolean>;
+ selectedDatabaseSchema: Ref<
+ { schema: SchemaMetadata; table: TableMetadata } | undefined
+ >;
events: SQLEditorEvents;
};
@@ -22,6 +29,7 @@ export const useSQLEditorContext = () => {
export const provideSQLEditorContext = () => {
const context: SQLEditorContext = {
showAIChatBox: ref(false),
+ selectedDatabaseSchema: ref(),
events: new Emittery(),
};