Skip to content

Commit c3b444a

Browse files
committed
fix(ui): align result columns and add create script action
1 parent 3d7dc80 commit c3b444a

5 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎src/components/grid/DataGrid.vue‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import type { ColumnFilter, DataGridEmits } from '@/types/grid'
33
import { useVirtualizer } from '@tanstack/vue-virtual'
4+
import { useResizeObserver } from '@vueuse/core'
45
import { computed, ref, watch } from 'vue'
56
import { useI18n } from 'vue-i18n'
67
import {
@@ -119,6 +120,11 @@ function handleClearSort() {
119120
// ── Virtual Scroller ──
120121
const scrollContainer = ref<HTMLDivElement | null>(null)
121122
const headerViewport = ref<HTMLDivElement | null>(null)
123+
const viewportWidth = ref(0)
124+
125+
useResizeObserver(scrollContainer, () => {
126+
viewportWidth.value = scrollContainer.value?.clientWidth ?? 0
127+
})
122128
123129
// The header lives outside the rows scroll container, so mirror the rows'
124130
// scrollLeft onto the header viewport. The overflow-hidden viewport is still a
@@ -148,6 +154,16 @@ function getColumnWidth(col: string): number {
148154
return columnWidths.value.get(col) ?? defaultColumnWidth
149155
}
150156
157+
// Absolute virtual rows must not size themselves from their cell contents.
158+
// Share one explicit width with the header, including scrollbar-free viewport space.
159+
const gridWidth = computed(() => Math.max(
160+
viewportWidth.value,
161+
40 + props.columns.reduce((width, col) => width + getColumnWidth(col), 0)
162+
+ (props.connectionId ? 80 : 0),
163+
))
164+
165+
watch([gridWidth, viewportWidth], syncHeaderScroll, { flush: 'post' })
166+
151167
let resizeStartX = 0
152168
let resizeStartWidth = 0
153169
let resizeColumn = ''
@@ -590,9 +606,11 @@ watch(sortableColumns, (columns) => {
590606
<div
591607
ref="headerViewport"
592608
class="border-b bg-muted flex flex-shrink-0 overflow-hidden"
609+
:style="{ width: `${viewportWidth}px` }"
593610
>
594611
<div
595-
class="flex flex-shrink-0 min-w-full"
612+
class="flex flex-shrink-0"
613+
:style="{ width: `${gridWidth}px` }"
596614
>
597615
<!-- Select-All Checkbox -->
598616
<div class="flex flex-shrink-0 h-8 w-10 items-center justify-center">
@@ -690,20 +708,21 @@ watch(sortableColumns, (columns) => {
690708
@scroll="syncHeaderScroll"
691709
>
692710
<div
693-
:style="{ height: `${rowVirtualizer.getTotalSize()}px` }"
711+
:style="{ width: `${gridWidth}px`, height: `${rowVirtualizer.getTotalSize()}px` }"
694712
class="relative"
695713
>
696714
<!-- Virtual Rows -->
697715
<div
698716
v-for="virtualRow in rowVirtualizer.getVirtualItems()"
699717
:key="`r-${virtualRow.index}`"
700718
:data-index="virtualRow.index"
701-
class="group border-b border-border/30 flex min-w-full transition-colors duration-75 left-0 top-0 absolute hover:bg-muted/[0.08]"
719+
class="group border-b border-border/30 flex transition-colors duration-75 left-0 top-0 absolute hover:bg-muted/[0.08]"
702720
:class="[
703721
virtualRow.index % 2 === 0 ? 'bg-muted/[0.03]' : '',
704722
selection.isSelected(virtualRow.index) ? 'bg-primary/[0.08]' : '',
705723
]"
706724
:style="{
725+
width: `${gridWidth}px`,
707726
height: `${virtualRow.size}px`,
708727
transform: `translateY(${virtualRow.start}px)`,
709728
}"
@@ -787,7 +806,7 @@ watch(sortableColumns, (columns) => {
787806
<!-- Row Actions -->
788807
<div
789808
v-if="connectionId"
790-
class="bg-background/80 flex flex-shrink-0 w-20 items-center right-0 justify-center sticky z-10"
809+
class="bg-background flex flex-shrink-0 w-20 items-center right-0 justify-center sticky z-10"
791810
@click.stop
792811
>
793812
<DropdownMenu>

‎src/components/sidebar/DatabaseSelectorRow.vue‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type Props = {
2222
}
2323
2424
type ActionKind
25-
= | 'newDatabase'
25+
= | 'createScript'
26+
| 'newDatabase'
2627
| 'newSchema'
2728
| 'newTable'
2829
| 'newView'
@@ -157,14 +158,15 @@ watch(() => props.connectionId, async (connId) => {
157158
class="shrink-0 h-7 w-7"
158159
:disabled="props.loading"
159160
:title="t('sidebar.database.refreshTooltip')"
161+
:aria-label="t('sidebar.database.refreshTooltip')"
160162
@click="emit('refresh')"
161163
>
162164
<span class="i-carbon-renew h-3.5 w-3.5" :class="{ 'animate-spin': isSpinning }" />
163165
</Button>
164166

165167
<DropdownMenu>
166168
<DropdownMenuTrigger as-child>
167-
<Button variant="ghost" size="icon" class="shrink-0 h-7 w-7" :title="t('sidebar.actionMenu.label')">
169+
<Button variant="ghost" size="icon" class="shrink-0 h-7 w-7" :title="t('sidebar.actionMenu.label')" :aria-label="t('sidebar.actionMenu.label')">
168170
<span class="i-carbon-overflow-menu-horizontal h-3.5 w-3.5" />
169171
</Button>
170172
</DropdownMenuTrigger>
@@ -173,6 +175,10 @@ watch(() => props.connectionId, async (connId) => {
173175
{{ t('sidebar.actionMenu.label') }}
174176
</div>
175177
<DropdownMenuSeparator />
178+
<DropdownMenuItem :disabled="!props.modelValue" @click="handleAction('createScript')">
179+
<span class="i-lucide-file-plus-2 mr-2 h-3.5 w-3.5" aria-hidden="true" /> {{ t('sidebar.actionMenu.createScript') }}
180+
</DropdownMenuItem>
181+
<DropdownMenuSeparator />
176182
<DropdownMenuItem v-if="capabilities.newDatabase" @click="handleAction('newDatabase')">
177183
<span class="i-carbon-data-base mr-2 h-3.5 w-3.5" /> {{ t('sidebar.actionMenu.newDatabase') }}
178184
</DropdownMenuItem>

‎src/lang/enUS.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ export const enUS = {
19271927
},
19281928
actionMenu: {
19291929
label: 'Database actions',
1930+
createScript: 'Create Script',
19301931
newDatabase: 'New Database',
19311932
newSchema: 'New Schema',
19321933
newTable: 'New Table',

‎src/lang/zhCN.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,7 @@ export const zhCN = {
19271927
},
19281928
actionMenu: {
19291929
label: '数据库操作',
1930+
createScript: '新建脚本',
19301931
newDatabase: '新建数据库',
19311932
newSchema: '新建模式',
19321933
newTable: '新建表',

‎src/pages/QueriesPage.vue‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ function handleDatabaseRefresh() {
861861
862862
function handleDatabaseAction(kind: string) {
863863
switch (kind) {
864+
case 'createScript':
865+
if (selectedDatabase.value)
866+
handleOpenQueryTab(selectedDatabase.value)
867+
break
864868
case 'newDatabase':
865869
createDatabaseDialogOpen.value = true
866870
break

0 commit comments

Comments
 (0)