19 files changed
+903
-4
No files matched your search
@@ -67,6 +67,7 @@ import { Tabs, TabsContent } from "@/components/ui/tabs";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import ErrorBanner from "@/components/ui/ErrorBanner.vue";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
import DataGridValueTransform from "@/components/grid/DataGridValueTransform.vue";
|
||||
import DataGridCellDetailPanel from "@/components/grid/DataGridCellDetailPanel.vue";
|
||||
import DataGridPagination from "@/components/grid/DataGridPagination.vue";
|
||||
import DataGridSearchBar from "@/components/grid/DataGridSearchBar.vue";
|
||||
@@ -5782,6 +5783,10 @@ const showCompactDetailJson = computed(() => {
|
||||
|
||||
// CodeMirror-based cell detail editors
|
||||
const valueEditorContainer = ref<HTMLElement>();
|
||||
const detailTransformOpen = ref(false);
|
||||
watch([showCellDetail, activeCellDetailTab, () => activeCellDetail.value?.rowId, () => activeCellDetail.value?.colIndex], () => {
|
||||
detailTransformOpen.value = false;
|
||||
});
|
||||
let valueDetailEditor: UseCellDetailEditorReturn | null = null;
|
||||
|
||||
const editorThemeAccessor = () => settingsStore.editorSettings.theme;
|
||||
@@ -5812,7 +5817,7 @@ watch(valueEditorContainer, async (el) => {
|
||||
},
|
||||
onEscape: () => restoreDetailOriginalValue(),
|
||||
onBlur: () => {
|
||||
if (!detailValueDiffOpen.value) commitValueEditorEdit();
|
||||
if (!detailValueDiffOpen.value && !detailTransformOpen.value) commitValueEditorEdit();
|
||||
},
|
||||
editorTheme: editorThemeAccessor,
|
||||
appAppearance: editorAppAppearance,
|
||||
@@ -13204,6 +13209,14 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val
|
||||
<div v-else ref="valueEditorContainer" data-cell-detail-editor-root class="min-h-0 min-w-0 flex-1 w-full rounded border overflow-auto" />
|
||||
</div>
|
||||
<div class="min-w-0 flex flex-wrap gap-1 mt-2 shrink-0">
|
||||
<DataGridValueTransform
|
||||
v-if="activeCellDetail && !isBinaryCellColumnType(activeCellDetail.type)"
|
||||
v-model:open="detailTransformOpen"
|
||||
:source="isEditingDetail && !((activeCellDetail.isNull ?? activeCellDetail.value === null) && detailEditValue === detailEditOriginalValue) ? detailEditValue : null"
|
||||
:identity="`${activeCellDetail.rowId}:${activeCellDetail.colIndex}:${activeCellDetailTab}`"
|
||||
:incomplete="activeCellDetail.isSourceTruncated"
|
||||
:unsafe-number="typeof activeCellDetail.value === 'number' && Number.isInteger(activeCellDetail.value) && !Number.isSafeInteger(activeCellDetail.value) && detailEditValue === activeCellDetail.rawValue"
|
||||
/>
|
||||
<DropdownMenu v-if="activeCellDetail?.isEditable">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="outline" size="sm" class="h-6 gap-1 text-xs" @mousedown.prevent>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import DataGridValueTransform from "@/components/grid/DataGridValueTransform.vue";
|
||||
import { computed, nextTick, ref, watch } from "vue";
|
||||
import { Code2, Copy, Download, Eye, FileUp, Info, Pencil } from "@lucide/vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
@@ -9,7 +10,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
|
||||
import { useCellDetailEditor, type UseCellDetailEditorReturn } from "@/composables/useCellDetailEditor";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { BINARY_CELL_DOWNLOAD_MODES, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
|
||||
import { BINARY_CELL_DOWNLOAD_MODES, isBinaryCellColumnType, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
|
||||
import { isGeometryColumnType } from "@/lib/dataGrid/cellDetailPresentation";
|
||||
import { isHexGeometry, renderWktOnCanvas } from "@/lib/dataGrid/geometryPreview";
|
||||
import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
|
||||
@@ -149,6 +150,13 @@ watch(
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div class="text-muted-foreground">{{ t("grid.cellValue") }}</div>
|
||||
<div class="flex items-center gap-1">
|
||||
<DataGridValueTransform
|
||||
v-if="open && !isBinaryCellColumnType(detail.type)"
|
||||
:source="(detail.isNull ?? detail.value === null) ? null : detail.rawValue"
|
||||
:identity="`${detail.rowId}:${detail.colIndex}`"
|
||||
:incomplete="detail.isSourceTruncated"
|
||||
:unsafe-number="typeof detail.value === 'number' && Number.isInteger(detail.value) && !Number.isSafeInteger(detail.value)"
|
||||
/>
|
||||
<Button v-if="detail.formattedJson" :variant="jsonView ? 'secondary' : 'ghost'" size="sm" class="h-6 gap-1 px-2 text-xs" :title="t('grid.formattedJson')" @click="toggleJsonFormatted">
|
||||
<Code2 class="h-3 w-3" />
|
||||
{{ t("grid.formattedJson") }}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import DataGridValueTransform from "@/components/grid/DataGridValueTransform.vue";
|
||||
import { computed, toRef } from "vue";
|
||||
import { Code2, Copy, Download, Eye, FileDiff, FileUp, Pencil, X } from "@lucide/vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
@@ -8,7 +9,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover
|
||||
import { TabsContent } from "@/components/ui/tabs";
|
||||
import TemporalCellEditor from "@/components/grid/TemporalCellEditor.vue";
|
||||
import { useDataGridCellDetail } from "@/composables/useDataGridCellDetail";
|
||||
import { BINARY_CELL_DOWNLOAD_MODES, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
|
||||
import { BINARY_CELL_DOWNLOAD_MODES, isBinaryCellColumnType, binaryCellUtf8Text, isBlobCellColumnType, type BinaryCellDownloadMode } from "@/lib/dataGrid/binaryCellDownload";
|
||||
import { isGeometryColumnType } from "@/lib/dataGrid/cellDetailPresentation";
|
||||
import { isHexGeometry } from "@/lib/dataGrid/geometryPreview";
|
||||
import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
|
||||
@@ -141,6 +142,13 @@ defineExpose({ openSearch });
|
||||
<div class="flex min-h-5 min-w-0 flex-wrap items-center justify-between gap-2">
|
||||
<div class="shrink-0 text-muted-foreground">{{ t("grid.cellValue") }}</div>
|
||||
<div class="min-w-0 flex flex-1 flex-wrap items-center justify-end gap-1">
|
||||
<DataGridValueTransform
|
||||
v-if="!isBinaryCellColumnType(detail.type)"
|
||||
:source="(detail.isNull ?? detail.value === null) && (!editing || !detailEditValue || detailEditValue === detail.rawValue) ? null : editing ? detailEditValue : detail.rawValue"
|
||||
:identity="`${detail.rowId}:${detail.colIndex}:${editing}`"
|
||||
:incomplete="detail.isSourceTruncated"
|
||||
:unsafe-number="typeof detail.value === 'number' && Number.isInteger(detail.value) && !Number.isSafeInteger(detail.value) && (!editing || detailEditValue === detail.rawValue)"
|
||||
/>
|
||||
<Button v-if="editing && showCompareJson" variant="ghost" size="sm" class="h-5 gap-1 px-1.5 text-xs" :disabled="!canCompareJson" :title="t('grid.compareJson')" @mousedown.prevent @click="emit('compareJson')"><FileDiff class="h-3 w-3" />{{ t("grid.compareJson") }}</Button>
|
||||
<Button v-if="showCompactJson" variant="ghost" size="sm" class="h-5 gap-1 px-1.5 text-xs" :disabled="!canCompactJson" :title="t('grid.compactJson')" @click="emit('compactJson')"><Code2 class="h-3 w-3" />{{ t("grid.compactJson") }}</Button>
|
||||
<Button v-if="!editing && detail.formattedJson" :variant="sideJsonView ? 'secondary' : 'ghost'" size="sm" class="h-5 gap-1 px-1.5 text-xs" :title="t('grid.formattedJson')" @click="emit('toggleFormatted')"><Code2 class="h-3 w-3" />{{ t("grid.formattedJson") }}</Button>
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, useId, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { copyToClipboard } from "@/lib/common/clipboard";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
||||
import { CELL_TRANSFORM_KINDS, CELL_TRANSFORM_MAX_INPUT, CELL_TRANSFORM_MAX_OUTPUT, CELL_TRANSFORM_MAX_RADIX_DIGITS, transformCellValue, type CellTransformKind, type CellTransformResult } from "@/lib/dataGrid/cellValueTransform";
|
||||
import { DataGridDateTimePatterns, getSupportedTimeZoneOptions } from "@/lib/dataGrid/columnFormatter";
|
||||
|
||||
const props = defineProps<{
|
||||
source: string | null;
|
||||
identity: string;
|
||||
incomplete?: boolean;
|
||||
unsafeNumber?: boolean;
|
||||
}>();
|
||||
const { t } = useI18n();
|
||||
const { toast } = useToast();
|
||||
const id = useId();
|
||||
const open = defineModel<boolean>("open", { default: false });
|
||||
const kind = ref<CellTransformKind>("timestamp");
|
||||
const unit = ref<"auto" | "seconds" | "milliseconds">("auto");
|
||||
const timezone = ref(Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC");
|
||||
const zones = [...new Set(["UTC", timezone.value, ...getSupportedTimeZoneOptions(Intl as unknown as { supportedValuesOf?: (key: "timeZone") => string[] }, timezone.value)])];
|
||||
const pattern = ref("YYYY-MM-DD HH:mm:ss");
|
||||
const fromBase = ref(10);
|
||||
const toBase = ref(16);
|
||||
const result = ref<CellTransformResult | null>(null);
|
||||
let previousEditorFocus: HTMLElement | null = null;
|
||||
let previousEditorIdentity = "";
|
||||
|
||||
function rememberEditorFocus() {
|
||||
const active = document.activeElement;
|
||||
previousEditorFocus = active instanceof HTMLElement && active.closest("[data-cell-detail-editor-root]") ? active : null;
|
||||
previousEditorIdentity = props.identity;
|
||||
}
|
||||
|
||||
function restoreEditorFocus(event: Event) {
|
||||
const target = previousEditorFocus;
|
||||
previousEditorFocus = null;
|
||||
if (!target?.isConnected || previousEditorIdentity !== props.identity) return;
|
||||
// Opening the preview skips the editor's blur commit. Restore its focus so
|
||||
// the next deliberate departure still commits the untouched editing draft.
|
||||
event.preventDefault();
|
||||
target.focus({ preventScroll: true });
|
||||
}
|
||||
|
||||
const blockedReason = computed(() => {
|
||||
if (props.source === null) return "nullSource";
|
||||
if (props.incomplete) return "incomplete";
|
||||
if (props.unsafeNumber) return "unsafeNumber";
|
||||
if (props.source.length > CELL_TRANSFORM_MAX_INPUT) return "tooLarge";
|
||||
return "";
|
||||
});
|
||||
|
||||
// Locale messages only interpolate the grouped limit digits, so translations keep their wording.
|
||||
const errorLimits = {
|
||||
maxInput: new Intl.NumberFormat("en-US").format(CELL_TRANSFORM_MAX_INPUT),
|
||||
maxOutput: new Intl.NumberFormat("en-US").format(CELL_TRANSFORM_MAX_OUTPUT),
|
||||
maxRadixDigits: new Intl.NumberFormat("en-US").format(CELL_TRANSFORM_MAX_RADIX_DIGITS),
|
||||
};
|
||||
|
||||
// Keep only options between cells. Results must always belong to the current source.
|
||||
watch(
|
||||
() => props.identity,
|
||||
() => {
|
||||
open.value = false;
|
||||
result.value = null;
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
[() => props.source, () => props.incomplete, () => props.unsafeNumber, kind, unit, timezone, pattern, fromBase, toBase, open],
|
||||
() => {
|
||||
result.value = null;
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
|
||||
function convert() {
|
||||
if (blockedReason.value || props.source === null) return;
|
||||
result.value = transformCellValue(props.source, { kind: kind.value, unit: unit.value, timezone: timezone.value, pattern: pattern.value, fromBase: fromBase.value, toBase: toBase.value });
|
||||
}
|
||||
async function copyResult() {
|
||||
if (!result.value?.ok) return;
|
||||
try {
|
||||
await copyToClipboard(result.value.text);
|
||||
toast(t("grid.cellValueCopied"), 2000);
|
||||
} catch (error) {
|
||||
toast(error instanceof Error ? error.message : String(error), 5000);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogTrigger as-child>
|
||||
<Button variant="outline" size="sm" class="h-6 px-2 text-xs" @mousedown.prevent>{{ t("cellTransform.title") }}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent class="flex max-h-[85vh] flex-col overflow-y-auto sm:max-w-2xl" data-native-clipboard @open-auto-focus="rememberEditorFocus" @close-auto-focus="restoreEditorFocus">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ t("cellTransform.title") }}</DialogTitle>
|
||||
<DialogDescription>{{ t("cellTransform.description") }}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div class="flex flex-wrap items-end gap-3 text-xs">
|
||||
<label class="flex flex-col gap-1">
|
||||
{{ t("cellTransform.format") }}
|
||||
<select v-model="kind" class="h-8 rounded border bg-background px-2">
|
||||
<option v-for="item in CELL_TRANSFORM_KINDS" :key="item" :value="item">{{ t(`cellTransform.kinds.${item}`) }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<template v-if="kind === 'timestamp'">
|
||||
<label class="flex flex-col gap-1">
|
||||
{{ t("cellTransform.unit") }}
|
||||
<select v-model="unit" class="h-8 rounded border bg-background px-2">
|
||||
<option v-for="item in ['auto', 'seconds', 'milliseconds']" :key="item" :value="item">{{ t(`cellTransform.units.${item}`) }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1">
|
||||
{{ t("cellTransform.timezone") }}
|
||||
<input v-model="timezone" :list="`${id}-zones`" class="h-8 rounded border bg-background px-2" />
|
||||
<datalist :id="`${id}-zones`"><option v-for="zone in zones" :key="zone" :value="zone" /></datalist>
|
||||
</label>
|
||||
<label class="flex min-w-0 flex-col gap-1">
|
||||
{{ t("cellTransform.pattern") }}
|
||||
<select v-model="pattern" class="h-8 max-w-full rounded border bg-background px-2">
|
||||
<option v-for="item in DataGridDateTimePatterns" :key="item" :value="item">{{ item }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
<template v-if="kind === 'radix'">
|
||||
<label class="flex flex-col gap-1">
|
||||
{{ t("cellTransform.fromBase") }}
|
||||
<select v-model="fromBase" class="h-8 rounded border bg-background px-2">
|
||||
<option v-for="base in [2, 8, 10, 16]" :key="base" :value="base">{{ base }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1">
|
||||
{{ t("cellTransform.toBase") }}
|
||||
<select v-model="toBase" class="h-8 rounded border bg-background px-2">
|
||||
<option v-for="base in [2, 8, 10, 16]" :key="base" :value="base">{{ base }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
<Button size="sm" class="h-8" :disabled="!!blockedReason" @click="convert">{{ t("cellTransform.convert") }}</Button>
|
||||
</div>
|
||||
<p v-if="kind === 'radix'" class="text-xs text-muted-foreground">{{ t("cellTransform.radixHint") }}</p>
|
||||
<p v-if="kind === 'urlEncode' || kind === 'urlDecode'" class="text-xs text-muted-foreground">{{ t("cellTransform.urlHint") }}</p>
|
||||
<p v-if="blockedReason" role="status" class="text-xs text-muted-foreground">{{ t(`cellTransform.errors.${blockedReason}`, errorLimits) }}</p>
|
||||
<p v-else-if="result && !result.ok" role="alert" class="text-xs text-destructive">{{ t(`cellTransform.errors.${result.error}`, errorLimits) }}</p>
|
||||
<template v-if="result?.ok">
|
||||
<div class="flex items-center justify-between gap-2 text-xs">
|
||||
<span
|
||||
>{{ t("cellTransform.result") }}<template v-if="result.unit"> · {{ t(`cellTransform.units.${result.unit}`) }}</template></span
|
||||
>
|
||||
<Button variant="outline" size="sm" class="h-6 text-xs" @click="copyResult">{{ t("cellTransform.copy") }}</Button>
|
||||
</div>
|
||||
<textarea :value="result.text" :aria-label="t('cellTransform.result')" readonly class="dbx-data-grid-value-font h-64 min-h-24 w-full resize-y rounded border bg-muted/20 p-3 text-xs" spellcheck="false" />
|
||||
</template>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -76,6 +76,7 @@ vi.mock("@/components/ui/label", async () => ({ Label: (await import("./vueHostH
|
||||
vi.mock("@/components/ui/LightDropdown.vue", async () => ({ default: (await import("./vueHostHarness")).createPassthroughStub("LightDropdown") }));
|
||||
vi.mock("@/components/ui/LightTooltip.vue", async () => ({ default: (await import("./vueHostHarness")).createPassthroughStub("LightTooltip") }));
|
||||
vi.mock("@/components/grid/TemporalCellEditor.vue", async () => ({ default: (await import("./vueHostHarness")).createPassthroughStub("TemporalCellEditor") }));
|
||||
vi.mock("@/components/grid/DataGridValueTransform.vue", async () => ({ default: (await import("./vueHostHarness")).createPassthroughStub("DataGridValueTransform") }));
|
||||
vi.mock("@/composables/useCellDetailEditor", () => ({ useCellDetailEditor: () => mocks.editor }));
|
||||
vi.mock("@/composables/useTheme", () => ({ useTheme: () => ({ isDark: { value: false }, themePalette: { value: {} } }) }));
|
||||
vi.mock("@/stores/settingsStore", () => ({ useSettingsStore: () => ({ editorSettings: { cellDetailJsonFormatted: true, theme: "default", fontSize: 13, fontFamily: "monospace" }, updateEditorSettings: mocks.updateSettings }) }));
|
||||
@@ -1686,7 +1687,7 @@ describe("cell detail surfaces", () => {
|
||||
it("snapshots comparison values before opening and suppresses modal-induced blur commits", () => {
|
||||
expect(dataGridCellDetailEditSource).toContain("detailValueDiffSnapshot.value = snapshot;");
|
||||
expect(dataGridCellDetailEditSource).toContain("detailValueDiffOpen.value = true;");
|
||||
expect(dataGridSource).toContain("if (!detailValueDiffOpen.value) commitValueEditorEdit();");
|
||||
expect(dataGridSource).toContain("if (!detailValueDiffOpen.value && !detailTransformOpen.value) commitValueEditorEdit();");
|
||||
expect(dataGridSource).toContain(':disabled="!canCompareDetailJson" @mousedown.prevent @click="openDetailJsonCompare"');
|
||||
expect(dataGridSource).toContain('v-model:open="detailValueDiffOpen" :snapshot="detailValueDiffSnapshot"');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user