feat(grid): add positioned batch row insertion
This commit is contained in:
1 parent
8e7b74d0ee
commit
5c3b045979
19 files changed
+1021
-41
No files matched your search
@@ -102,7 +102,6 @@ import {
|
||||
defaultTransposeRecordWidth,
|
||||
minTransposeFieldWidth,
|
||||
minTransposeRecordWidth,
|
||||
nextAppendedTransposeState,
|
||||
nextContextTransposeState,
|
||||
nextKeyboardTransposeState,
|
||||
nextTransposeState,
|
||||
@@ -212,7 +211,8 @@ import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { simpleDataGridOrderByMatchesSort, simpleDataGridOrderByReferencesMissingColumn, type DataGridSortDirection, type DataGridSortMode } from "@/lib/dataGrid/dataGridSort";
|
||||
import { DATA_GRID_CONDITION_TOOLBAR_MIN_WIDTH, isDataGridToolbarCompact, type DataGridReloadIntent, type DataGridToolbarActionCapability, type DataGridToolbarAutoRefreshCapability, type DataGridToolbarSaveCapability } from "@/lib/dataGrid/dataGridToolbar";
|
||||
import { buildOrderedGridRows, type GridInsertRowPosition, type GridNewRowPlacement } from "@/lib/dataGrid/gridNewRowPlacement";
|
||||
import { DATA_GRID_CONDITION_TOOLBAR_MIN_WIDTH, isDataGridToolbarCompact, type DataGridReloadIntent, type DataGridToolbarActionCapability, type DataGridToolbarAddRowCapability, type DataGridToolbarAutoRefreshCapability, type DataGridToolbarSaveCapability } from "@/lib/dataGrid/dataGridToolbar";
|
||||
import { getTableMetadataCapabilities } from "@/lib/table/tableMetadataCapabilities";
|
||||
import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";
|
||||
import { filterObjectBrowserTableColumns } from "@/lib/table/objectBrowserTableInfo";
|
||||
@@ -244,6 +244,7 @@ const DataGridMongoJsonPreview = defineAsyncComponent(() => import("@/components
|
||||
const DataGridDetailDialogs = defineAsyncComponent(() => import("@/components/grid/DataGridDetailDialogs.vue"));
|
||||
const DataGridBulkEditDialog = defineAsyncComponent(() => import("@/components/grid/DataGridBulkEditDialog.vue"));
|
||||
const DataGridCopyColumnNamesDialog = defineAsyncComponent(() => import("@/components/grid/DataGridCopyColumnNamesDialog.vue"));
|
||||
const DataGridInsertRowsDialog = defineAsyncComponent(() => import("@/components/grid/DataGridInsertRowsDialog.vue"));
|
||||
const ExportProgressDialog = defineAsyncComponent(() => import("@/components/export/ExportProgressDialog.vue"));
|
||||
const FORMATTED_JSON_EDIT_WARNING_COUNT_STORAGE_KEY = "dbx-cell-detail-formatted-json-edit-warning-count";
|
||||
const FORMATTED_JSON_EDIT_WARNING_MAX_COUNT = 3;
|
||||
@@ -594,6 +595,10 @@ const bulkEditDialogOpen = ref(false);
|
||||
const bulkEditValue = ref("");
|
||||
const copyColumnNamesDialogOpen = ref(false);
|
||||
const copyColumnNamesDialogColumns = ref<string[]>([]);
|
||||
const insertRowsDialogOpen = ref(false);
|
||||
// Configured placement for newly inserted rows; the dropdown exposes it as a
|
||||
// mutually-exclusive radio group and the main "add row" button inserts here.
|
||||
const insertPosition = ref<GridInsertRowPosition>("below");
|
||||
const generateIncrementDialogOpen = ref(false);
|
||||
const generateIncrementStartValue = ref("1");
|
||||
const generateIncrementTarget = ref<"selection" | "detail">("selection");
|
||||
@@ -616,6 +621,7 @@ const imagePreviewSrc = ref("");
|
||||
const imagePreviewTitle = ref("");
|
||||
const bulkEditDialogMounted = useDataGridAsyncSurface(bulkEditDialogOpen);
|
||||
const copyColumnNamesDialogMounted = useDataGridAsyncSurface(copyColumnNamesDialogOpen);
|
||||
const insertRowsDialogMounted = useDataGridAsyncSurface(insertRowsDialogOpen);
|
||||
const cellDetailDialogMounted = useDataGridAsyncSurface(cellDetailDialogOpen);
|
||||
const detailDialogsMounted = useDataGridAsyncSurface(computed(() => rowDetailDialogOpen.value || columnDetailDialogOpen.value));
|
||||
const imagePreviewMounted = useDataGridAsyncSurface(imagePreviewOpen);
|
||||
@@ -2922,6 +2928,7 @@ const {
|
||||
scrollerRef,
|
||||
dirtyRows,
|
||||
newRows,
|
||||
newRowMeta: editorNewRowMeta,
|
||||
deletedRows,
|
||||
quickEntryDraftRow,
|
||||
quickEntryDraftRowId,
|
||||
@@ -2943,7 +2950,7 @@ const {
|
||||
restoreCellValue,
|
||||
cancelEdit,
|
||||
onEditKeydown,
|
||||
addRow: addEditorRow,
|
||||
addRows: addEditorRows,
|
||||
appendPastedRowsToNewRow,
|
||||
cloneRow,
|
||||
showDeleteRowConfirm,
|
||||
@@ -3257,8 +3264,7 @@ function onToolbarRollback() {
|
||||
|
||||
function addRow() {
|
||||
if (!canInsertRows.value) return;
|
||||
addEditorRow();
|
||||
focusAppendedTransposeRecord();
|
||||
insertRows(1, insertPosition.value);
|
||||
}
|
||||
|
||||
const refreshToolbarCapability = computed<DataGridToolbarActionCapability>(() => ({
|
||||
@@ -3280,11 +3286,72 @@ const autoRefreshToolbarCapability = computed<DataGridToolbarAutoRefreshCapabili
|
||||
onToggle: toggleAutoRefresh,
|
||||
onSelectInterval: setAutoRefreshInterval,
|
||||
}));
|
||||
const addRowToolbarCapability = computed<DataGridToolbarActionCapability>(() => ({
|
||||
const canPlaceInsertAtSelection = computed(() => {
|
||||
if (selectedRowCount.value !== 1) return false;
|
||||
const selectedId = [...selectedRowIds.value][0];
|
||||
if (selectedId === undefined) return false;
|
||||
const item = getRowItem(selectedId);
|
||||
if (!item || item.isDraft) return false;
|
||||
return item.sourceIndex !== undefined || (item.isNew && item.newIndex !== undefined);
|
||||
});
|
||||
|
||||
function selectedRowPlacement(position: "above" | "below"): GridNewRowPlacement | null {
|
||||
if (!canPlaceInsertAtSelection.value) return null;
|
||||
const selectedId = [...selectedRowIds.value][0]!;
|
||||
const item = getRowItem(selectedId);
|
||||
if (!item) return null;
|
||||
if (item.isNew && item.newIndex !== undefined) {
|
||||
const meta = editorNewRowMeta.value[item.newIndex];
|
||||
if (meta) return { anchorId: -meta.token, position };
|
||||
}
|
||||
if (item.sourceIndex !== undefined) return { anchorId: item.sourceIndex, position };
|
||||
return null;
|
||||
}
|
||||
|
||||
function insertRows(count: number, position: "above" | "below" | "end") {
|
||||
const placement: GridNewRowPlacement | null = position === "end" ? null : selectedRowPlacement(position);
|
||||
const firstNewRowId = addEditorRows(count, placement);
|
||||
if (firstNewRowId !== undefined) {
|
||||
nextTick(() => {
|
||||
const displayIndex = displayRowIndexById(firstNewRowId);
|
||||
if (displayIndex >= 0) scrollGridRowIntoView(displayIndex);
|
||||
});
|
||||
focusInsertedTransposeRecord(firstNewRowId);
|
||||
}
|
||||
}
|
||||
|
||||
function handleAddRowMenuSelect(value: string) {
|
||||
if (value === "insert-multiple") {
|
||||
insertRowsDialogOpen.value = true;
|
||||
return;
|
||||
}
|
||||
if (value === "position-above") {
|
||||
insertPosition.value = "above";
|
||||
return;
|
||||
}
|
||||
if (value === "position-below") {
|
||||
insertPosition.value = "below";
|
||||
return;
|
||||
}
|
||||
if (value === "position-end") {
|
||||
insertPosition.value = "end";
|
||||
return;
|
||||
}
|
||||
insertRows(1, "end");
|
||||
}
|
||||
|
||||
const addRowToolbarCapability = computed<DataGridToolbarAddRowCapability>(() => ({
|
||||
label: t("grid.addRow"),
|
||||
tooltip: `${t("grid.addRow")} (${shortcutMod}+N)`,
|
||||
visible: canInsertRows.value,
|
||||
items: [
|
||||
{ value: "insert-multiple", label: t("grid.insertMultipleRows") },
|
||||
{ value: "position-above", label: t("grid.insertPositionAbove"), separatorBefore: true, selected: insertPosition.value === "above", disabled: !canPlaceInsertAtSelection.value },
|
||||
{ value: "position-below", label: t("grid.insertPositionBelow"), selected: insertPosition.value === "below", disabled: !canPlaceInsertAtSelection.value },
|
||||
{ value: "position-end", label: t("grid.insertPositionEnd"), selected: insertPosition.value === "end" },
|
||||
],
|
||||
onTrigger: addRow,
|
||||
onSelect: handleAddRowMenuSelect,
|
||||
}));
|
||||
const previewToolbarCapability = computed<DataGridToolbarActionCapability>(() => ({
|
||||
label: t(previewLabelKey.value),
|
||||
@@ -3337,28 +3404,34 @@ function dirtyColumnsForRow(dirty: Map<number, CellValue> | undefined, columnCou
|
||||
|
||||
const displayRowRefs = computed<DisplayRowRef[]>(() => {
|
||||
const refs: DisplayRowRef[] = [];
|
||||
for (const sourceIndex of sortedRows.value) {
|
||||
const dirty = dirtyRows.value.get(sourceIndex);
|
||||
const isDeleted = deletedRows.value.has(sourceIndex);
|
||||
const status: RowStatus = isDeleted ? "deleted" : dirty?.size ? "edited" : "clean";
|
||||
const isActiveEditingRow = quickEntryEnabled.value && editingCell.value?.rowId === sourceIndex;
|
||||
if (matchesRowStatusFilter(status, rowStatusFilter.value) || isActiveEditingRow) {
|
||||
refs.push({ id: sourceIndex, displayIndex: refs.length, sourceIndex, isNew: false, isDeleted, status });
|
||||
// Pending rows carry a display placement (anchor row + above/below) so they
|
||||
// can render interleaved with the loaded rows; unplaced rows stay at the end.
|
||||
for (const entry of buildOrderedGridRows(sortedRows.value, editorNewRowMeta.value, newRows.value.length)) {
|
||||
if (entry.kind === "source") {
|
||||
const sourceIndex = entry.sourceIndex;
|
||||
const dirty = dirtyRows.value.get(sourceIndex);
|
||||
const isDeleted = deletedRows.value.has(sourceIndex);
|
||||
const status: RowStatus = isDeleted ? "deleted" : dirty?.size ? "edited" : "clean";
|
||||
const isActiveEditingRow = quickEntryEnabled.value && editingCell.value?.rowId === sourceIndex;
|
||||
if (matchesRowStatusFilter(status, rowStatusFilter.value) || isActiveEditingRow) {
|
||||
refs.push({ id: sourceIndex, displayIndex: refs.length, sourceIndex, isNew: false, isDeleted, status });
|
||||
}
|
||||
} else {
|
||||
const newIndex = entry.newIndex;
|
||||
const row = newRows.value[newIndex];
|
||||
if (!row || !rowMatchesLocalColumnFilters(row)) continue;
|
||||
const status: RowStatus = "new";
|
||||
if (!matchesRowStatusFilter(status, rowStatusFilter.value)) continue;
|
||||
refs.push({
|
||||
id: -(newIndex + 1),
|
||||
displayIndex: refs.length,
|
||||
newIndex,
|
||||
isNew: true,
|
||||
isDeleted: false,
|
||||
status,
|
||||
});
|
||||
}
|
||||
}
|
||||
newRows.value.forEach((row, i) => {
|
||||
if (!rowMatchesLocalColumnFilters(row)) return;
|
||||
const status: RowStatus = "new";
|
||||
if (!matchesRowStatusFilter(status, rowStatusFilter.value)) return;
|
||||
refs.push({
|
||||
id: -(i + 1),
|
||||
displayIndex: refs.length,
|
||||
newIndex: i,
|
||||
isNew: true,
|
||||
isDeleted: false,
|
||||
status,
|
||||
});
|
||||
});
|
||||
if (showQuickEntryDraftRow.value) {
|
||||
ensureQuickEntryDraftRow();
|
||||
refs.push({
|
||||
@@ -6676,10 +6749,13 @@ function applyTransposeState(next: { showTranspose: boolean; transposeRowIndex:
|
||||
}
|
||||
}
|
||||
|
||||
function focusAppendedTransposeRecord() {
|
||||
function focusInsertedTransposeRecord(rowId: number) {
|
||||
if (!showTranspose.value) return;
|
||||
nextTick(() => {
|
||||
applyTransposeState(nextAppendedTransposeState(true, displayRowCount.value));
|
||||
const displayIndex = displayRowIndexById(rowId);
|
||||
if (displayIndex >= 0) {
|
||||
applyTransposeState(nextTransposeStateForRecordCount(true, displayIndex, displayRowCount.value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -9750,6 +9826,7 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
||||
/>
|
||||
|
||||
<DataGridBulkEditDialog v-if="bulkEditDialogMounted" v-model:open="bulkEditDialogOpen" v-model:value="bulkEditValue" :selected-cell-count="selectedCellCount" @apply="applyBulkEditValue" />
|
||||
<DataGridInsertRowsDialog v-if="insertRowsDialogMounted" v-model:open="insertRowsDialogOpen" :can-place-at-selection="canPlaceInsertAtSelection" :initial-position="insertPosition" @insert="insertRows" />
|
||||
|
||||
<DataGridExtractorDialog v-model:open="extractorConfigOpen" :extractor="selectedCopyExtractor" :options="settingsStore.editorSettings.dataGridExtractorOptions" :items="extractorMenuItems" :preview="previewWithExtractor" @save="saveExtractorConfiguration" />
|
||||
<DataGridCopyColumnNamesDialog v-if="copyColumnNamesDialogMounted" v-model:open="copyColumnNamesDialogOpen" :column-names="copyColumnNamesDialogColumns" :database-type="resolvedDatabaseType" :column-comments="columnCommentMap" @copy="copyText" />
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { DATA_GRID_MAX_BATCH_INSERT_ROWS } from "@/composables/useDataGridEditor";
|
||||
import { type GridInsertRowPosition } from "@/lib/dataGrid/gridNewRowPlacement";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
const MAX_INSERT_ROWS = DATA_GRID_MAX_BATCH_INSERT_ROWS;
|
||||
|
||||
const { t } = useI18n();
|
||||
const open = defineModel<boolean>("open", { default: false });
|
||||
const props = defineProps<{ canPlaceAtSelection?: boolean; initialPosition?: GridInsertRowPosition }>();
|
||||
const emit = defineEmits<{ insert: [count: number, position: GridInsertRowPosition] }>();
|
||||
|
||||
const canUsePosition = computed(() => props.canPlaceAtSelection !== false);
|
||||
|
||||
const rowCount = ref("1");
|
||||
const position = ref<GridInsertRowPosition>("below");
|
||||
|
||||
watch(
|
||||
open,
|
||||
(isOpen) => {
|
||||
if (isOpen) {
|
||||
rowCount.value = "1";
|
||||
position.value = canUsePosition.value ? (props.initialPosition ?? "below") : "end";
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// Without a unique selected row the above/below placements are not meaningful;
|
||||
// fall back to the end instead of silently degrading on submit.
|
||||
watch(canUsePosition, (canUse) => {
|
||||
if (!canUse) position.value = "end";
|
||||
});
|
||||
|
||||
function parseIntegerOrNull(raw: string): number | null {
|
||||
const trimmed = raw.trim();
|
||||
if (!/^\d+$/.test(trimmed)) return null;
|
||||
const value = Number(trimmed);
|
||||
return Number.isInteger(value) && value >= 1 ? value : null;
|
||||
}
|
||||
|
||||
const parsedCount = computed<number | null>(() => {
|
||||
const parsed = parseIntegerOrNull(rowCount.value);
|
||||
if (parsed === null) return null;
|
||||
return Math.min(parsed, MAX_INSERT_ROWS);
|
||||
});
|
||||
|
||||
const inputInvalid = computed(() => {
|
||||
const raw = rowCount.value.trim();
|
||||
if (raw === "") return false;
|
||||
return parseIntegerOrNull(raw) === null;
|
||||
});
|
||||
|
||||
function confirmInsert() {
|
||||
const count = parsedCount.value;
|
||||
if (count === null) return;
|
||||
emit("insert", count, position.value);
|
||||
open.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent class="sm:max-w-[420px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ t("grid.insertRowsTitle") }}</DialogTitle>
|
||||
<DialogDescription>{{ t("grid.insertRowsDescription") }}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div class="space-y-3">
|
||||
<div class="space-y-2">
|
||||
<label for="insert-rows-count" class="text-sm font-medium">{{ t("grid.insertRowCountLabel") }}</label>
|
||||
<Input id="insert-rows-count" v-model="rowCount" type="number" min="1" :max="MAX_INSERT_ROWS" :aria-invalid="inputInvalid" class="w-40" @keydown.enter.prevent="confirmInsert" />
|
||||
<p v-if="inputInvalid" class="text-sm text-destructive">{{ t("grid.insertRowCountInvalid") }}</p>
|
||||
<p class="text-xs text-muted-foreground">{{ t("grid.insertRowsMaxHint", { max: MAX_INSERT_ROWS }) }}</p>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<span class="text-sm font-medium">{{ t("grid.insertRowPositionLabel") }}</span>
|
||||
<label class="flex items-center gap-2 text-sm">
|
||||
<input v-model="position" type="radio" value="above" :disabled="!canUsePosition" class="h-3.5 w-3.5 accent-primary disabled:cursor-not-allowed" />
|
||||
{{ t("grid.insertPositionAbove") }}
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-sm">
|
||||
<input v-model="position" type="radio" value="below" :disabled="!canUsePosition" class="h-3.5 w-3.5 accent-primary disabled:cursor-not-allowed" />
|
||||
{{ t("grid.insertPositionBelow") }}
|
||||
</label>
|
||||
<label class="flex items-center gap-2 text-sm">
|
||||
<input v-model="position" type="radio" value="end" class="h-3.5 w-3.5 accent-primary" />
|
||||
{{ t("grid.insertPositionEnd") }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" @click="open = false">{{ t("dangerDialog.cancel") }}</Button>
|
||||
<Button :disabled="parsedCount === null" @click="confirmInsert">{{ t("grid.insertRowsConfirm") }}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
dataGridToolbarIntervalOptions,
|
||||
isDataGridToolbarCapabilityDisabled,
|
||||
isDataGridToolbarCapabilityVisible,
|
||||
selectDataGridToolbarAddRowItem,
|
||||
selectDataGridToolbarAutoRefreshInterval,
|
||||
selectDataGridToolbarCopyItem,
|
||||
selectDataGridToolbarExportItem,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
triggerDataGridToolbarCopy,
|
||||
triggerDataGridToolbarAction,
|
||||
type DataGridToolbarActionCapability,
|
||||
type DataGridToolbarAddRowCapability,
|
||||
type DataGridToolbarAutoRefreshCapability,
|
||||
type DataGridToolbarCopyCapability,
|
||||
type DataGridToolbarExportCapability,
|
||||
@@ -25,7 +27,7 @@ const props = defineProps<{
|
||||
compact?: boolean;
|
||||
refresh: DataGridToolbarActionCapability;
|
||||
autoRefresh?: DataGridToolbarAutoRefreshCapability;
|
||||
addRow?: DataGridToolbarActionCapability;
|
||||
addRow?: DataGridToolbarAddRowCapability;
|
||||
copyData?: DataGridToolbarCopyCapability;
|
||||
exportData?: DataGridToolbarExportCapability;
|
||||
transpose?: DataGridToolbarActionCapability;
|
||||
@@ -117,15 +119,34 @@ function actionLabelClass() {
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
<Tooltip v-if="isDataGridToolbarCapabilityVisible(addRow)">
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="sm" :class="actionButtonClass" :disabled="isDataGridToolbarCapabilityDisabled(addRow)" @click="void triggerDataGridToolbarAction(addRow)">
|
||||
<Plus class="data-grid-topbar-action-icon h-3 w-3" />
|
||||
<span class="data-grid-topbar-action-label" :class="actionLabelClass()">{{ addRow?.label }}</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">{{ addRow?.tooltip ?? addRow?.label }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<div v-if="isDataGridToolbarCapabilityVisible(addRow)" class="flex h-5 shrink-0 items-stretch overflow-hidden rounded-md border border-border">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button variant="ghost" size="sm" class="h-5 rounded-none border-0 px-1.5 text-xs" :disabled="isDataGridToolbarCapabilityDisabled(addRow)" @click="void triggerDataGridToolbarAction(addRow)">
|
||||
<Plus class="h-3 w-3" :class="compact ? '' : 'mr-1'" />
|
||||
<span v-if="!compact">{{ addRow?.label }}</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom">{{ addRow?.tooltip ?? addRow?.label }}</TooltipContent>
|
||||
</Tooltip>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="icon" class="h-5 w-5 rounded-none border-0 border-l border-border" :aria-label="addRow?.label" :disabled="isDataGridToolbarCapabilityDisabled(addRow)">
|
||||
<ChevronDown class="h-3 w-3" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" class="min-w-52">
|
||||
<template v-for="item in addRow?.items ?? []" :key="item.value">
|
||||
<DropdownMenuSeparator v-if="item.separatorBefore" />
|
||||
<DropdownMenuItem class="gap-2" :disabled="item.disabled" @select="void selectDataGridToolbarAddRowItem(addRow, item.value)">
|
||||
<Check v-if="item.selected" class="h-3.5 w-3.5 shrink-0 text-primary" />
|
||||
<span v-else class="h-3.5 w-3.5 shrink-0" />
|
||||
<span class="flex-1">{{ item.label }}</span>
|
||||
</DropdownMenuItem>
|
||||
</template>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
<DropdownMenu v-if="isDataGridToolbarCapabilityVisible(exportData)">
|
||||
<Tooltip>
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { createApp, nextTick, type App } from "vue";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import i18n from "@/i18n";
|
||||
|
||||
vi.mock("@/components/ui/dialog", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
const passthrough = defineComponent({
|
||||
setup(_props, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
});
|
||||
return {
|
||||
Dialog: passthrough,
|
||||
DialogContent: passthrough,
|
||||
DialogDescription: passthrough,
|
||||
DialogFooter: passthrough,
|
||||
DialogHeader: passthrough,
|
||||
DialogTitle: passthrough,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/button", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
return {
|
||||
Button: defineComponent({
|
||||
inheritAttrs: false,
|
||||
setup(_props, { attrs, slots }) {
|
||||
return () => h("button", attrs, slots.default?.());
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/input", async () => {
|
||||
const { defineComponent, h } = await import("vue");
|
||||
return {
|
||||
Input: defineComponent({
|
||||
inheritAttrs: false,
|
||||
props: { modelValue: String },
|
||||
emits: ["update:modelValue"],
|
||||
setup(props, { attrs, emit }) {
|
||||
return () => h("input", { ...attrs, value: props.modelValue, onInput: (event: Event) => emit("update:modelValue", (event.target as HTMLInputElement).value) });
|
||||
},
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
import DataGridInsertRowsDialog from "../DataGridInsertRowsDialog.vue";
|
||||
|
||||
const mountedApps: Array<{ app: App; host: HTMLElement }> = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const { app, host } of mountedApps.splice(0)) {
|
||||
app.unmount();
|
||||
host.remove();
|
||||
}
|
||||
});
|
||||
|
||||
describe("DataGridInsertRowsDialog", () => {
|
||||
it("uses the configured end position when first mounted open", async () => {
|
||||
const onInsert = vi.fn();
|
||||
const host = document.createElement("div");
|
||||
document.body.append(host);
|
||||
const app = createApp(DataGridInsertRowsDialog, {
|
||||
open: true,
|
||||
canPlaceAtSelection: true,
|
||||
initialPosition: "end",
|
||||
onInsert,
|
||||
});
|
||||
app.use(i18n);
|
||||
app.mount(host);
|
||||
mountedApps.push({ app, host });
|
||||
|
||||
await nextTick();
|
||||
expect((host.querySelector('input[value="end"]') as HTMLInputElement).checked).toBe(true);
|
||||
|
||||
[...host.querySelectorAll("button")].find((button) => button.textContent === "Insert")!.click();
|
||||
await nextTick();
|
||||
expect(onInsert).toHaveBeenCalledWith(1, "end");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user