Skip to content

Commit dc4262d

Browse files
authored
chore: support not show the native sql (#726)
Co-authored-by: rick <[email protected]>
1 parent c0c227e commit dc4262d

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

console/atest-ui/src/views/DataManager.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { GetDataManagerPreference, SetDataManagerPreference } from './cache'
99
import { ElMessage } from 'element-plus'
1010
import { Codemirror } from 'vue-codemirror'
1111
import { sql, StandardSQL, MySQL, PostgreSQL, Cassandra } from "@codemirror/lang-sql"
12+
import type { SQLConfig } from "@codemirror/lang-sql"
1213
import HistoryInput from '../components/HistoryInput.vue'
1314
import type { Ref } from 'vue'
1415
import { Refresh, Document } from '@element-plus/icons-vue'
@@ -153,6 +154,7 @@ API.GetStores((data) => {
153154
loadingStores.value = false
154155
})
155156
157+
const showNativeSQL = ref(true)
156158
const ormDataHandler = (data: QueryData) => {
157159
const result = [] as any[]
158160
const cols = new Set<string>()
@@ -168,7 +170,7 @@ const ormDataHandler = (data: QueryData) => {
168170
169171
columns.value = [] as string[]
170172
data.meta.labels = data.meta.labels.filter((item) => {
171-
if (item.key === '_native_sql') {
173+
if (showNativeSQL.value && item.key === '_native_sql') {
172174
sqlQuery.value = item.value
173175
return false
174176
}
@@ -210,15 +212,15 @@ const keyValueDataHandler = (data: QueryData) => {
210212
})
211213
})
212214
}
213-
214215
const sqlConfig = ref({
215216
dialect: StandardSQL,
216217
defaultSchema: queryDataMeta.value.currentDatabase,
217218
upperCaseKeywords: true,
218219
schema: {}
219-
})
220+
} as SQLConfig)
220221
221222
const executeQuery = async () => {
223+
showNativeSQL.value = true
222224
if (sqlQuery.value === '') {
223225
switch (kind.value) {
224226
case ExtensionKind.ExtensionKindElasticsearch:
@@ -291,6 +293,13 @@ Magic.AdvancedKeys([{
291293
Keys: ['Ctrl+E', 'Ctrl+Enter'],
292294
Func: executeQuery,
293295
Description: 'Execute query'
296+
}, {
297+
Keys: ['Ctrl+Shift+O'],
298+
Func: () => {
299+
showNativeSQL.value = false
300+
executeWithQuery(sqlQuery.value)
301+
},
302+
Description: 'Execute query without showing native SQL'
294303
}])
295304
</script>
296305

console/atest-ui/src/views/TestCase.vue

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, watch, reactive } from 'vue'
2+
import { ref, watch } from 'vue'
33
import { ElMessage } from 'element-plus'
44
import { Edit, Delete, Search, CopyDocument, Help } from '@element-plus/icons-vue'
55
import JsonViewer from 'vue-json-viewer'
@@ -20,9 +20,7 @@ import jsonlint from 'jsonlint-mod'
2020
2121
import CodeMirror from 'codemirror'
2222
import { json, jsonLanguage } from "@codemirror/lang-json"
23-
import { LanguageSupport } from "@codemirror/language"
24-
import { CompletionContext } from "@codemirror/autocomplete"
25-
import type { Completion } from "@codemirror/autocomplete"
23+
import { NewLanguageComplete } from './languageComplete'
2624
import 'codemirror/lib/codemirror.css'
2725
import 'codemirror/addon/merge/merge.js'
2826
import 'codemirror/addon/merge/merge.css'
@@ -34,36 +32,7 @@ window.DIFF_DELETE = -1;
3432
window.DIFF_INSERT = 1;
3533
window.DIFF_EQUAL = 0;
3634
37-
const templateFuncs = ref([] as Completion[])
38-
function myCompletions(context: CompletionContext) {
39-
if (templateFuncs.value.length == 0) {
40-
API.FunctionsQuery("", "template", (e) => {
41-
if (e.data) {
42-
e.data.forEach((item: any) => {
43-
templateFuncs.value.push({
44-
label: item.key,
45-
type: "text",
46-
} as Completion)
47-
})
48-
}
49-
})
50-
}
51-
52-
let word = context.matchBefore(/\w*/) || {
53-
from: "",
54-
to: ""
55-
}
56-
if (word.from == word.to && !context.explicit)
57-
return null
58-
return {
59-
from: word.from,
60-
options: templateFuncs.value
61-
}
62-
}
63-
const jsonComplete = new LanguageSupport(jsonLanguage, jsonLanguage.data.of(
64-
{autocomplete: myCompletions}
65-
))
66-
35+
const jsonComplete = NewLanguageComplete(jsonLanguage)
6736
const { t } = useI18n()
6837
6938
const props = defineProps({
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Language, LanguageSupport } from "@codemirror/language"
2+
import { CompletionContext } from "@codemirror/autocomplete"
3+
import type { Completion } from "@codemirror/autocomplete"
4+
import { API } from './net'
5+
import { ref } from 'vue'
6+
7+
const templateFuncs = ref([] as Completion[])
8+
function tplFuncCompletions(context: CompletionContext) {
9+
if (templateFuncs.value.length == 0) {
10+
API.FunctionsQuery("", "template", (e) => {
11+
if (e.data) {
12+
e.data.forEach((item: any) => {
13+
templateFuncs.value.push({
14+
label: item.key,
15+
type: "text",
16+
} as Completion)
17+
})
18+
}
19+
})
20+
}
21+
22+
let word = context.matchBefore(/\w*/) || {
23+
from: "",
24+
to: ""
25+
}
26+
if (word.from == word.to && !context.explicit)
27+
return null
28+
return {
29+
from: word.from,
30+
options: templateFuncs.value
31+
}
32+
}
33+
34+
export const NewLanguageComplete = (lang: Language) => {
35+
return new LanguageSupport(lang, lang.data.of(
36+
{autocomplete: tplFuncCompletions}
37+
))
38+
}

0 commit comments

Comments
 (0)