diff --git a/frontend/src2/components/Code.vue b/frontend/src2/components/Code.vue index 8a4bb4f37..81abdc20b 100644 --- a/frontend/src2/components/Code.vue +++ b/frontend/src2/components/Code.vue @@ -137,5 +137,14 @@ defineExpose({ const _pos = Math.min(pos, code.value.length) codeMirror.value.view.dispatch({ selection: { anchor: _pos, head: _pos } }) }, + insertText: (text) => { + const view = codeMirror.value.view + const pos = view.state.selection.ranges[0].to + view.dispatch({ + changes: { from: pos, insert: text }, + selection: { anchor: pos + text.length, head: pos + text.length } + }) + view.focus() + }, }) diff --git a/frontend/src2/query/components/NativeQueryEditor.vue b/frontend/src2/query/components/NativeQueryEditor.vue index d33a349f7..3700f4eba 100644 --- a/frontend/src2/query/components/NativeQueryEditor.vue +++ b/frontend/src2/query/components/NativeQueryEditor.vue @@ -10,6 +10,7 @@ import { Query } from '../query' import QueryDataTable from './QueryDataTable.vue' import DataSourceSelector from './source_selector/DataSourceSelector.vue' import { createToast } from '../../helpers/toasts' +import SchemaExplorer from './SchemaExplorer.vue' const query = inject('query')! query.autoExecute = false @@ -55,6 +56,13 @@ async function format() { } } +const codeEditor = ref | null>(null) +function insertTextIntoEditor(text: string) { + if (codeEditor.value) { + codeEditor.value.insertText(text) + } +} + const dataSourceSchema = ref>({}) const dataSourceStore = useDataSourceStore() wheneverChanges( @@ -81,7 +89,7 @@ const completions = computed(() => { Object.entries(dataSourceSchema.value).forEach(([table, tableData]) => { schema[table] = tableData.columns.map((column: any) => ({ label: column.label, - detail: column.label, + detail: column.type, })) }) @@ -89,7 +97,7 @@ const completions = computed(() => { label: table, detail: tableData.label, })) - + console.log({ schema, tables }) return { schema, tables, @@ -98,7 +106,9 @@ const completions = computed(() => { diff --git a/frontend/src2/query/components/SchemaExplorer.vue b/frontend/src2/query/components/SchemaExplorer.vue new file mode 100644 index 000000000..d701505b8 --- /dev/null +++ b/frontend/src2/query/components/SchemaExplorer.vue @@ -0,0 +1,160 @@ + + +