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: auto-complete for sql editor section (#7698)
Liu Jidaaceb7a3aaf
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vueindex 17dc8c077a..0765a22c69 100644--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue@@ -159,7 +159,7 @@<script setup lang="ts">import { cloneDeep } from "lodash-es";import { NButton, NTooltip, useDialog } from "naive-ui";-import { computed, h, reactive, watch } from "vue";+import { computed, h, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";import { useRoute } from "vue-router";import { ErrorList } from "@/components/IssueV1/components/common";@@ -175,6 +175,7 @@ import {notifyNotEditableLegacyIssue,patchLegacyIssueTasksStatement,} from "@/components/IssueV1/logic";+import MonacoEditor from "@/components/MonacoEditor";import DownloadSheetButton from "@/components/Sheet/DownloadSheetButton.vue";import UploadProgressButton from "@/components/misc/UploadProgressButton.vue";import { rolloutServiceClient } from "@/grpcweb";@@ -202,6 +203,7 @@ import {import { useSQLAdviceMarkers } from "../useSQLAdviceMarkers";import FormatOnSaveCheckbox from "./FormatOnSaveCheckbox.vue";import { useAutoEditorHeight } from "./useAutoEditorHeight";+import { useEditorAutoCompletion } from "./useEditorAutoCompletion";import { EditState, useTempEditState } from "./useTempEditState";import { readFileAsync } from "./utils";@@ -225,7 +227,10 @@ const state = reactive<LocalState>({isUploadingFile: false,});-const { editorRef, updateEditorHeight } = useAutoEditorHeight();+const editorRef = ref<InstanceType<typeof MonacoEditor>>();+const { updateEditorHeight } = useAutoEditorHeight(editorRef);+const { updateEditorAutoCompletionContext } =+ useEditorAutoCompletion(editorRef);const selectedDatabase = computed(() => {return databaseForTask(issue.value, selectedTask.value);@@ -622,11 +627,12 @@ const handleStatementChange = (value: string) => {if (!sheet.value) return;setSheetStatement(sheet.value, value);}++ updateEditorHeight();};const handleMonacoEditorReady = () => {- // TODO- // handleUpdateEditorAutoCompletionContext();+ updateEditorAutoCompletionContext();updateEditorHeight();};diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/useAutoEditorHeight.ts b/frontend/src/components/IssueV1/components/StatementSection/EditorView/useAutoEditorHeight.tsindex b42626fc2f..5e8c33ff9b 100644--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/useAutoEditorHeight.ts+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/useAutoEditorHeight.ts@@ -1,10 +1,11 @@-import { ref } from "vue";+import { Ref } from "vue";import MonacoEditor from "@/components/MonacoEditor";const EDITOR_MIN_HEIGHT = 120; // ~= 6 lines, a reasonable size to start writing SQL-export const useAutoEditorHeight = () => {- const editorRef = ref<InstanceType<typeof MonacoEditor>>();+export const useAutoEditorHeight = (+ editorRef: Ref<InstanceType<typeof MonacoEditor> | undefined>+) => {const updateEditorHeight = () => {requestAnimationFrame(() => {const contentHeight =@@ -18,7 +19,6 @@ export const useAutoEditorHeight = () => {};return {- editorRef,updateEditorHeight,};};diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/useEditorAutoCompletion.ts b/frontend/src/components/IssueV1/components/StatementSection/EditorView/useEditorAutoCompletion.tsnew file mode 100644index 0000000000..d9f263c30e--- /dev/null+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/useEditorAutoCompletion.ts@@ -0,0 +1,53 @@+import { computed, Ref, watch } from "vue";+import { databaseForTask, useIssueContext } from "@/components/IssueV1/logic";+import MonacoEditor from "@/components/MonacoEditor";+import { useDBSchemaV1Store } from "@/store";+import { ComposedDatabase, UNKNOWN_ID } from "@/types";+import { TableMetadata } from "@/types/proto/v1/database_service";++export const useEditorAutoCompletion = (+ editorRef: Ref<InstanceType<typeof MonacoEditor> | undefined>+) => {+ const { issue, selectedTask } = useIssueContext();+ const dbSchemaStore = useDBSchemaV1Store();+ const databaseList = computed(() => {+ const db = databaseForTask(issue.value, selectedTask.value);+ if (db.uid === String(UNKNOWN_ID)) {+ return [];+ }+ return [db];+ });++ watch(+ databaseList,+ (list) => {+ list.forEach((db) => {+ if (db.uid !== String(UNKNOWN_ID)) {+ dbSchemaStore.getOrFetchDatabaseMetadata(db.name);+ }+ });+ },+ { immediate: true }+ );++ const tableList = computed(() => {+ return databaseList.value+ .map((item) => dbSchemaStore.getTableList(item.name))+ .flat();+ });++ const updateEditorAutoCompletionContext = async () => {+ const databaseMap: Map<ComposedDatabase, TableMetadata[]> = new Map();+ for (const database of databaseList.value) {+ const tableList = await dbSchemaStore.getOrFetchTableList(database.name);+ databaseMap.set(database, tableList);+ }+ editorRef.value?.setEditorAutoCompletionContextV1(databaseMap);+ };++ watch([databaseList, tableList], () => {+ updateEditorAutoCompletionContext();+ });++ return { updateEditorAutoCompletionContext };+};