Skip to content

Commit e3cb8c0

Browse files
ZonaHexCopilot
andauthored
feat: timestamp input assistance (#555)
* feat: time assistance input * style: ui * style: ui * Update src/views/dashboard/query/time-assistance.vue Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: delete * refactor: message * refactor: remove insert message --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent dec4423 commit e3cb8c0

File tree

11 files changed

+443
-63
lines changed

11 files changed

+443
-63
lines changed

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@
1717
"VITE"
1818
],
1919
"vue-i18n.i18nPaths": "src/locale,src/views/dashboard/locale",
20-
"i18n-ally.localesPaths": ["src/locale", "src/views/dashboard/locale"]
20+
"i18n-ally.localesPaths": [
21+
"src/locale",
22+
"src/views/dashboard/locale"
23+
],
24+
"editor.formatOnSave": true
2125
}

src/assets/icons.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/style/button.less

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,10 @@
109109
.arco-btn-size-medium:not(.arco-btn-only-icon) .arco-btn-icon {
110110
margin-right: 10px;
111111
}
112+
113+
.arco-radio-group-button {
114+
background-color: var(--grey-bg-color);
115+
.arco-radio-button.arco-radio-checked {
116+
color: var(--brand-color);
117+
}
118+
}

src/assets/style/form.less

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,10 @@
121121
width: 180px !important;
122122
}
123123

124-
.arco-picker {
125-
background: var(--grey-bg-color);
126-
127-
.arco-picker-prefix {
128-
display: flex;
129-
}
130-
}
131-
132124
.arco-picker input {
133125
width: 150px;
134126
}
135127

136-
.arco-picker-focused {
137-
background-color: inherit;
138-
border-color: var(--hover-brand-color);
139-
140-
.arco-picker-input-active input {
141-
background: inherit;
142-
}
143-
}
144-
145128
.arco-picker-has-prefix {
146129
padding-right: 8px;
147130
padding-left: 8px;
@@ -198,19 +181,6 @@
198181
background: var(--grey-bg-color);
199182
}
200183

201-
.arco-picker-cell-in-range .arco-picker-date {
202-
background-color: var(--light-brand-color);
203-
}
204-
205-
.arco-picker-cell-range-start .arco-picker-date-value,
206-
.arco-picker-cell-range-end .arco-picker-date-value {
207-
background-color: var(--brand-color);
208-
}
209-
210-
.arco-picker-cell-today::after {
211-
background-color: var(--brand-color);
212-
}
213-
214184
.arco-panel-date-with-view-tabs .arco-panel-date-timepicker .arco-timepicker-cell-inner {
215185
border-radius: 4px;
216186
}
@@ -225,3 +195,32 @@
225195
font-size: 13px;
226196
color: var(--small-font-color);
227197
}
198+
199+
.arco-picker {
200+
border-radius: 4px;
201+
background: var(--grey-bg-color);
202+
.arco-picker-prefix {
203+
display: flex;
204+
}
205+
}
206+
207+
.arco-picker-focused,
208+
.arco-picker-focused:hover {
209+
background-color: inherit;
210+
border-color: var(--hover-brand-color);
211+
212+
.arco-picker-input-active input {
213+
background: inherit;
214+
}
215+
}
216+
217+
.arco-picker-cell-in-range .arco-picker-date {
218+
background-color: var(--light-brand-color);
219+
}
220+
221+
.arco-picker-cell-range-start .arco-picker-date-value,
222+
.arco-picker-cell-range-end .arco-picker-date-value,
223+
.arco-picker-cell-selected .arco-picker-date-value,
224+
.arco-picker-cell-today::after {
225+
background-color: var(--brand-color);
226+
}

src/assets/style/global.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ samp {
471471
.arco-icon {
472472
stroke-linecap: round;
473473
stroke-linejoin: round;
474-
stroke-width: 3px;
474+
stroke-width: 3.5;
475475
}
476476

477477
#app {

src/assets/style/select.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
.arco-select-view-clear-btn svg,
8686
.arco-select-view-icon svg {
8787
font-size: 9px;
88-
stroke-width: 6px;
8988
stroke-linecap: round;
9089
stroke-linejoin: round;
9190
}

src/locale/en-US/dashboard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ export default {
8181
'dashboard.hideSidebar': 'Hide sidebar',
8282
'dashboard.rerunQuery': 'Rerun Query',
8383
'dashboard.clearResults': 'Clear results?',
84+
'dashboard.timeAssistance': 'Time Input Assistance',
8485
}

src/locale/zh-CN/dashboard.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ export default {
8181
'dashboard.hideSidebar': '隐藏侧边栏',
8282
'dashboard.rerunQuery': '重新执行查询',
8383
'dashboard.clearResults': '清除结果?',
84+
'dashboard.timeAssistance': 'Time Assistance',
8485
}

src/views/dashboard/modules/query-modal/index.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ a-modal.query-modal(
102102
justify-content: center;
103103
border-radius: 4px;
104104
margin-left: 3px;
105-
svg {
106-
stroke-width: 3px;
107-
}
108105
}
109106
.arco-modal-close-btn:hover {
110107
background: var(--th-bg-color);

src/views/dashboard/query/editor.vue

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ a-card.editor-card(:bordered="false")
88
:disabled="isButtonDisabled || explainQueryRunning"
99
@click="runPartQuery()"
1010
)
11-
a-popover(position="bl" content-class="code-tooltip" :content="currentStatement")
12-
a-space(:size="4")
13-
icon-loading(v-if="secondaryCodeRunning" spin)
14-
icon-play-arrow(v-else)
15-
div {{ $t('dashboard.runQuery') + (queryType === 'sql' && currentQueryNumber ? ' #' + currentQueryNumber : '') }}
16-
icon-close-circle-fill.icon-16(v-if="secondaryCodeRunning")
11+
a-tooltip(position="left" content="Ctrl + Enter")
12+
a-popover(position="bl" content-class="code-tooltip" :content="currentStatement")
13+
a-space(:size="4")
14+
icon-loading(v-if="secondaryCodeRunning" spin)
15+
icon-play-arrow(v-else)
16+
div {{ $t('dashboard.runQuery') + (queryType === 'sql' && currentQueryNumber ? ' #' + currentQueryNumber : '') }}
17+
icon-close-circle-fill.icon-16(v-if="secondaryCodeRunning")
1718
template(#icon)
1819
icon-down
1920
template(#content)
@@ -47,17 +48,24 @@ a-card.editor-card(:bordered="false")
4748
template(#icon)
4849
icon-import
4950
| {{ $t('dashboard.importExplain') }}
50-
a-button(
51+
a-tooltip(
5152
v-if="queryType === 'sql'"
52-
type="outline"
53-
:disabled="isButtonDisabled"
54-
@click="runQueryAll()"
53+
position="br"
54+
content="Alt + Enter"
55+
mini
5556
)
56-
a-space(:size="4")
57-
icon-loading(v-if="primaryCodeRunning" spin)
58-
icon-play-arrow(v-else)
59-
| {{ $t('dashboard.runAll') }}
60-
icon-close-circle-fill.icon-16(v-if="primaryCodeRunning")
57+
a-button(type="outline" :disabled="isButtonDisabled" @click="runQueryAll()")
58+
a-space(:size="4")
59+
icon-loading(v-if="primaryCodeRunning" spin)
60+
icon-play-arrow(v-else)
61+
| {{ $t('dashboard.runAll') }}
62+
icon-close-circle-fill.icon-16(v-if="primaryCodeRunning")
63+
a-tooltip(mini position="right" :content="$t('dashboard.timeAssistance')")
64+
a-button(type="secondary" @click="openTimeAssistance")
65+
template(#icon)
66+
svg.icon-18
67+
use(href="#time-index")
68+
TimeAssistance(ref="tsRef" :cm="currentView")
6169
.query-select
6270
a-space(size="medium")
6371
a-tooltip(v-if="queryType === 'sql'" mini :content="$t('dashboard.format')")
@@ -154,7 +162,7 @@ a-card.editor-card(:bordered="false")
154162
import { acceptCompletion } from '@codemirror/autocomplete'
155163
import type { PromForm } from '@/store/modules/code-run/types'
156164
import { useStorage } from '@vueuse/core'
157-
import { sqlFormatter, parseSqlStatements, findStatementAtPosition, debounce } from '@/utils/sql'
165+
import { sqlFormatter, parseSqlStatements, findStatementAtPosition } from '@/utils/sql'
158166
import { Message } from '@arco-design/web-vue'
159167
import fileDownload from 'js-file-download'
160168
@@ -173,6 +181,8 @@ a-card.editor-card(:bordered="false")
173181
tabSize: 2,
174182
})
175183
184+
const tsRef = ref<InstanceType<typeof import('./time-assistance.vue').default> | null>(null)
185+
176186
const {
177187
codes,
178188
queryType,
@@ -185,9 +195,12 @@ a-card.editor-card(:bordered="false")
185195
clearCode,
186196
} = useQueryCode()
187197
198+
// Get current active CodeMirror view based on query type
199+
const currentView = computed(() => {
200+
return queryType.value === 'sql' ? sqlView.value : promqlView.value
201+
})
202+
188203
const currentSqlPreview = ref('')
189-
const triggerVisible = ref(false)
190-
const rangePickerVisible = ref(false)
191204
const promForm = reactive<PromForm>({
192205
time: 5,
193206
step: '30s',
@@ -206,6 +219,11 @@ a-card.editor-card(:bordered="false")
206219
207220
const emit = defineEmits(['selectExplainTab'])
208221
222+
const openTimeAssistance = () => {
223+
if (tsRef.value) {
224+
tsRef.value?.open()
225+
}
226+
}
209227
// Show the import explain modal
210228
const showImportExplainModal = () => {
211229
importExplainModalVisible.value = true
@@ -417,28 +435,36 @@ a-card.editor-card(:bordered="false")
417435
label: `Last ${value} minutes`,
418436
}))
419437
420-
// TODO: fix this
421-
const defaultKeymap = [
438+
const myKeymap = keymap.of([
422439
{
423-
key: 'alt-Enter',
440+
key: `Ctrl-Enter`,
441+
run: () => {
442+
runPartQuery()
443+
return true
444+
},
445+
},
446+
{
447+
key: 'Alt-Enter', // Run All
424448
run: () => {
425449
runQueryAll()
450+
return true
426451
},
427452
},
428453
{
429-
key: 'ctrl-Enter',
454+
key: 'Ctrl-Shift-;', // Time Assistant(Cmd/Ctrl+Shift+;)
430455
run: () => {
431-
runPartQuery()
456+
openTimeAssistance()
457+
return true
432458
},
433459
},
434460
{
435461
key: 'Tab',
436462
run: acceptCompletion,
437463
},
438-
]
464+
])
439465
440-
const extensionsForSql = [...extensions.value.sql, keymap.of(defaultKeymap as any)]
441-
const extensionsForPromql = [...extensions.value.promql, keymap.of(defaultKeymap as any)]
466+
const extensionsForSql = [myKeymap, ...extensions.value.sql]
467+
const extensionsForPromql = [myKeymap, ...extensions.value.promql]
442468
const placeholder = `Paste response from explain analyze format json here. Example format:
443469
{
444470
"output": [

0 commit comments

Comments
 (0)