fix(mongodb): preserve explicit document id types
This commit is contained in:
1 parent
cc340605b8
commit
2457fac04f
12 files changed
+103
-7
No files matched your search
@@ -169,7 +169,7 @@ import { canGoNextDataGridPage } from "@/lib/dataGrid/dataGridPagination";
|
||||
import { dataGridCountQueryOptions } from "@/lib/dataGrid/dataGridQueryOptions";
|
||||
import { dataGridBottomScrollTop, dataGridScrollPosition, isDataGridAtScrollBottom, isDataGridNearScrollBottom, restoredDataGridScrollLeft, shouldCheckInfiniteScrollAfterScroll, type DataGridScrollPosition } from "@/lib/dataGrid/dataGridInfiniteScroll";
|
||||
import { CANVAS_DATA_GRID_ROW_HEIGHT, drawCanvasDataGrid } from "@/lib/dataGrid/canvasDataGridRenderer";
|
||||
import { dataGridSaveActionMode, dataGridSaveToolbarState } from "@/lib/dataGrid/dataGridSaveUi";
|
||||
import { dataGridPreviewLabelKey, dataGridSaveActionMode, dataGridSaveToolbarState } from "@/lib/dataGrid/dataGridSaveUi";
|
||||
import type { QueryEditabilityReason } from "@/lib/sql/sqlAnalysis";
|
||||
import { EDITOR_FONT_FAMILY_CSS_VAR } from "@/lib/editor/editorThemes";
|
||||
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";
|
||||
@@ -4235,6 +4235,7 @@ const saveActionMode = computed(() =>
|
||||
useTransaction: !!useTransaction.value,
|
||||
}),
|
||||
);
|
||||
const previewLabelKey = computed(() => dataGridPreviewLabelKey(resolvedDatabaseType.value));
|
||||
const saveToolbarState = computed(() =>
|
||||
dataGridSaveToolbarState({
|
||||
editable: props.editable,
|
||||
@@ -7270,8 +7271,12 @@ function prepareTransposeCellMouseDown(rowIndex: number, actualColIdx: number) {
|
||||
if (item) prepareDataCellMouseDown(item, actualColIdx);
|
||||
}
|
||||
|
||||
function canSaveGridChangesFromShortcut() {
|
||||
return saveToolbarState.value.showActions && !saveToolbarState.value.actionsDisabled;
|
||||
}
|
||||
|
||||
async function saveGridChangesFromShortcut() {
|
||||
if (!saveToolbarState.value.showActions || saveToolbarState.value.actionsDisabled) return false;
|
||||
if (!canSaveGridChangesFromShortcut()) return false;
|
||||
await onToolbarCommit();
|
||||
return true;
|
||||
}
|
||||
@@ -7345,9 +7350,10 @@ async function onGridKeydown(event: KeyboardEvent) {
|
||||
return;
|
||||
}
|
||||
if (isSaveShortcut(event, settingsStore.editorSettings.shortcuts)) {
|
||||
if (await saveGridChangesFromShortcut()) {
|
||||
if (canSaveGridChangesFromShortcut()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
await saveGridChangesFromShortcut();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -9672,11 +9678,11 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
||||
>
|
||||
<Loader2 v-if="isPreviewLoading" class="data-grid-topbar-action-icon w-3 h-3 animate-spin" />
|
||||
<Eye v-else class="data-grid-topbar-action-icon w-3 h-3" />
|
||||
<span class="data-grid-topbar-action-label" :class="{ 'data-grid-topbar-action-label--compact': compactDataGridToolbar }">{{ t("toolbar.previewSql") }}</span>
|
||||
<span class="data-grid-topbar-action-label" :class="{ 'data-grid-topbar-action-label--compact': compactDataGridToolbar }">{{ t(previewLabelKey) }}</span>
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" class="max-w-sm">
|
||||
{{ t("toolbar.previewSql") }}
|
||||
{{ t(previewLabelKey) }}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Tooltip>
|
||||
|
||||
@@ -42,6 +42,7 @@ export default {
|
||||
rollback: "Rollback",
|
||||
txnAutoRolledBack: "Transaction auto-rolled back after 5 minutes of inactivity",
|
||||
previewSql: "Preview SQL",
|
||||
previewQuery: "Preview query",
|
||||
hidePreviewSql: "Hide SQL Preview",
|
||||
saveSql: "Save to SQL Library",
|
||||
openSql: "Open SQL file",
|
||||
|
||||
@@ -44,6 +44,7 @@ export default withEnglishFallback({
|
||||
rollback: "Revertir",
|
||||
txnAutoRolledBack: "Transacción revertida automáticamente tras 5 minutos de inactividad",
|
||||
previewSql: "Vista previa de SQL",
|
||||
previewQuery: "Vista previa de la consulta",
|
||||
hidePreviewSql: "Ocultar vista previa de SQL",
|
||||
saveSql: "Guardar en biblioteca SQL",
|
||||
openSql: "Abrir archivo SQL",
|
||||
|
||||
@@ -43,6 +43,7 @@ export default withEnglishFallback({
|
||||
rollback: "Rollback",
|
||||
txnAutoRolledBack: "Transazione annullata automaticamente dopo 5 minuti di inattività",
|
||||
previewSql: "Anteprima SQL",
|
||||
previewQuery: "Anteprima query",
|
||||
hidePreviewSql: "Nascondi anteprima SQL",
|
||||
saveSql: "Salva nella Libreria SQL",
|
||||
openSql: "Apri file SQL",
|
||||
|
||||
@@ -44,6 +44,7 @@ export default withEnglishFallback({
|
||||
rollback: "ロールバック",
|
||||
txnAutoRolledBack: "5分間操作がなかったため、トランザクションは自動的にロールバックされました",
|
||||
previewSql: "SQLをプレビュー",
|
||||
previewQuery: "クエリをプレビュー",
|
||||
hidePreviewSql: "SQLプレビューを非表示",
|
||||
saveSql: "SQLライブラリに保存",
|
||||
openSql: "SQLファイルを開く",
|
||||
|
||||
@@ -44,6 +44,7 @@ export default withEnglishFallback({
|
||||
rollback: "Reverter",
|
||||
txnAutoRolledBack: "Transação revertida automaticamente após 5 minutos de inatividade",
|
||||
previewSql: "Visualizar SQL",
|
||||
previewQuery: "Visualizar consulta",
|
||||
hidePreviewSql: "Ocultar Visualização SQL",
|
||||
saveSql: "Salvar na Biblioteca SQL",
|
||||
openSql: "Abrir arquivo SQL",
|
||||
|
||||
@@ -44,6 +44,7 @@ export default withEnglishFallback({
|
||||
rollback: "回滚",
|
||||
txnAutoRolledBack: "事务已因 5 分钟无操作而自动回滚",
|
||||
previewSql: "预览 SQL",
|
||||
previewQuery: "预览查询",
|
||||
hidePreviewSql: "隐藏 SQL 预览",
|
||||
saveSql: "保存到 SQL 库",
|
||||
openSql: "打开 SQL 文件",
|
||||
|
||||
@@ -44,6 +44,7 @@ export default withEnglishFallback({
|
||||
rollback: "回溯",
|
||||
txnAutoRolledBack: "事務已因 5 分鐘無操作而自動回溯",
|
||||
previewSql: "預覽 SQL",
|
||||
previewQuery: "預覽查詢",
|
||||
hidePreviewSql: "隱藏 SQL 預覽",
|
||||
saveSql: "儲存到 SQL 庫",
|
||||
openSql: "開啟 SQL 檔案",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { dataGridPreviewLabelKey } from "@/lib/dataGrid/dataGridSaveUi";
|
||||
|
||||
describe("dataGridPreviewLabelKey", () => {
|
||||
it("offers a query preview for document databases that never emit SQL", () => {
|
||||
expect(dataGridPreviewLabelKey("mongodb")).toBe("toolbar.previewQuery");
|
||||
expect(dataGridPreviewLabelKey("elasticsearch")).toBe("toolbar.previewQuery");
|
||||
});
|
||||
|
||||
it("keeps the SQL wording for SQL databases", () => {
|
||||
expect(dataGridPreviewLabelKey("mysql")).toBe("toolbar.previewSql");
|
||||
expect(dataGridPreviewLabelKey("postgres")).toBe("toolbar.previewSql");
|
||||
expect(dataGridPreviewLabelKey("sqlite")).toBe("toolbar.previewSql");
|
||||
});
|
||||
|
||||
it("falls back to the SQL wording when the database type is unknown", () => {
|
||||
expect(dataGridPreviewLabelKey(undefined)).toBe("toolbar.previewSql");
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,11 @@
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
|
||||
const NON_SQL_PREVIEW_DATABASE_TYPES: ReadonlySet<DatabaseType> = new Set<DatabaseType>(["mongodb", "elasticsearch"]);
|
||||
|
||||
export function dataGridPreviewLabelKey(databaseType?: DatabaseType): "toolbar.previewQuery" | "toolbar.previewSql" {
|
||||
return databaseType && NON_SQL_PREVIEW_DATABASE_TYPES.has(databaseType) ? "toolbar.previewQuery" : "toolbar.previewSql";
|
||||
}
|
||||
|
||||
export interface DataGridSaveActionMode {
|
||||
labelKey: "grid.commit" | "grid.save";
|
||||
tooltipKey: "grid.transactionSaveHint" | "grid.nonTransactionalSaveHint";
|
||||
|
||||
Reference in new issue
Block a user