Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: open history in new tab with connection info if possible (#3292)
Liu Ji7059962cefeb
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.tsindex 283a7998ce..ef50e28999 100644--- a/frontend/src/store/modules/sqlEditor.ts+++ b/frontend/src/store/modules/sqlEditor.ts@@ -17,6 +17,7 @@ import { useInstanceStore } from "./instance";import { useTableStore } from "./table";import { useSQLStore } from "./sql";import { useTabStore } from "./tab";+import { emptyConnection } from "@/utils";// set the limit to 10000 temporarily to avoid the query timeout and page crashexport const RESULT_ROWS_LIMIT = 10000;@@ -141,3 +142,42 @@ export const useSQLEditorStore = defineStore("sqlEditor", {},},});++export const searchConnectionByName = (+ instanceName: string,+ databaseName: string+): Connection => {+ const connection = emptyConnection();+ const store = useSQLEditorStore();++ const rootNodes = store.connectionTree.data;+ for (let i = 0; i < rootNodes.length; i++) {+ const maybeInstanceNode = rootNodes[i];+ if (maybeInstanceNode.type !== "instance") {+ // Skip if we met dirty data.+ continue;+ }+ if (maybeInstanceNode.label === instanceName) {+ connection.instanceId = maybeInstanceNode.id;+ if (databaseName) {+ const { children = [] } = maybeInstanceNode;+ for (let j = 0; j < children.length; j++) {+ const maybeDatabaseNode = children[j];+ if (maybeDatabaseNode.type !== "database") {+ // Skip if we met dirty data.+ continue;+ }+ if (maybeDatabaseNode.label === databaseName) {+ connection.databaseId = maybeDatabaseNode.id;+ // Don't go further since we've found the databaseId+ break;+ }+ }+ }+ // Don't go further since we've found the instanceId+ break;+ }+ }++ return connection;+};diff --git a/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue b/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vueindex 6ea026d564..714d952f80 100644--- a/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue+++ b/frontend/src/views/sql-editor/AsidePanel/QueryHistoryContainer.vue@@ -60,7 +60,12 @@ import { computed, reactive } from "vue";import { useI18n } from "vue-i18n";import { useClipboard } from "@vueuse/core";-import { pushNotification, useTabStore, useSQLEditorStore } from "@/store";+import {+ pushNotification,+ useTabStore,+ useSQLEditorStore,+ searchConnectionByName,+} from "@/store";import { QueryHistory } from "@/types";import { getHighlightHTMLByKeyWords } from "@/utils";@@ -134,10 +139,18 @@ const handleCopy = (history: QueryHistory) => {};const handleQueryHistoryClick = async (queryHistory: QueryHistory) => {- // Changing SQL statement is quite harmless, so we just update the current tab.+ // It's awkward that we stored instanceName and databaseName rather than IDs+ // in the history activity entity.+ // We may try our best to find the correct database and instance by searching+ // their names.+ const { instanceName, databaseName, statement } = queryHistory;+ const connection = searchConnectionByName(instanceName, databaseName);++ // Open a new tab with the connection and statement.+ tabStore.selectOrAddTempTab();tabStore.updateCurrentTab({- statement: queryHistory.statement,- selectedStatement: "",+ connection,+ statement,});};</script>