fix(grid): clarify pending save actions
This commit is contained in:
@@ -103,6 +103,7 @@ import {
|
||||
} from "@/lib/columnFormatter";
|
||||
import { isCancelSearchShortcut, isFocusSearchShortcut } from "@/lib/keyboardShortcuts";
|
||||
import { dataGridHeaderContentWidth, scrollbarGutterWidth } from "@/lib/dataGridScrollGutter";
|
||||
import { dataGridSaveActionMode } from "@/lib/dataGridSaveUi";
|
||||
import {
|
||||
filterColumnVisibilityOptions,
|
||||
nextHiddenColumnIndexes,
|
||||
@@ -1282,6 +1283,13 @@ const {
|
||||
cleanupFrames,
|
||||
} = editor;
|
||||
|
||||
const saveActionMode = computed(() =>
|
||||
dataGridSaveActionMode({
|
||||
pendingChangeCount: pendingChangeCount.value,
|
||||
useTransaction: !!useTransaction.value,
|
||||
}),
|
||||
);
|
||||
|
||||
function canEditRowItem(item: RowItem | undefined): boolean {
|
||||
return !!props.editable && !!item && !item.isDeleted && (item.isNew || canEditExistingRows.value);
|
||||
}
|
||||
@@ -2657,29 +2665,36 @@ defineExpose({
|
||||
<span class="h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse" />
|
||||
{{ t("grid.transactionActive") }}
|
||||
</span>
|
||||
<Button
|
||||
v-if="useTransaction"
|
||||
:variant="transactionActive ? 'default' : 'secondary'"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5"
|
||||
:disabled="!transactionActive || isSaving"
|
||||
@click="onToolbarCommit"
|
||||
>
|
||||
<Loader2 v-if="isSaving" class="w-3 h-3 mr-1 animate-spin" />
|
||||
<Save v-else class="w-3 h-3 mr-1" />
|
||||
{{ t("grid.commit") }}
|
||||
</Button>
|
||||
<Button
|
||||
v-if="useTransaction"
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5"
|
||||
:disabled="!transactionActive"
|
||||
@click="onToolbarRollback"
|
||||
>
|
||||
<RotateCcw class="w-3 h-3 mr-1" />
|
||||
{{ t("grid.rollback") }}
|
||||
</Button>
|
||||
<template v-if="editable && (tableMeta || customSave) && hasPendingChanges">
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="default"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5 shrink-0"
|
||||
:disabled="isSaving"
|
||||
@click="onToolbarCommit"
|
||||
>
|
||||
<Loader2 v-if="isSaving" class="w-3 h-3 mr-1 animate-spin" />
|
||||
<Save v-else class="w-3 h-3 mr-1" />
|
||||
{{ t(saveActionMode.labelKey, { count: pendingChangeCount }) }}
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" class="max-w-sm">
|
||||
{{ t(saveActionMode.tooltipKey, { count: pendingChangeCount }) }}
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="h-5 text-xs px-1.5 shrink-0"
|
||||
:disabled="isSaving"
|
||||
@click="useTransaction ? onToolbarRollback() : discardChanges()"
|
||||
>
|
||||
<RotateCcw class="w-3 h-3 mr-1" />
|
||||
{{ t(saveActionMode.secondaryActionKey) }}
|
||||
</Button>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Truncation warning banner -->
|
||||
@@ -3852,16 +3867,10 @@ defineExpose({
|
||||
<span>{{ result.execution_time_ms }}ms</span>
|
||||
<span v-if="selectedRowCount > 0 || hasCellSelection" class="text-foreground">{{ selectionSummary }}</span>
|
||||
|
||||
<template v-if="editable && (tableMeta || customSave) && !useTransaction">
|
||||
<template v-if="editable && (tableMeta || customSave)">
|
||||
<span v-if="hasPendingChanges" class="ml-2 text-foreground">
|
||||
{{ t("grid.pendingChanges", { count: pendingChangeCount }) }}
|
||||
</span>
|
||||
<Button v-if="hasPendingChanges" variant="default" size="sm" class="h-5 text-xs ml-2" @click="saveChanges">
|
||||
<Save class="w-3 h-3 mr-1" /> {{ t("grid.save") }}
|
||||
</Button>
|
||||
<Button v-if="hasPendingChanges" variant="ghost" size="sm" class="h-5 text-xs" @click="discardChanges">
|
||||
{{ t("grid.discard") }}
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<span class="ml-auto flex items-center gap-1">
|
||||
|
||||
@@ -376,10 +376,13 @@ export default {
|
||||
refresh: "Refresh",
|
||||
commit: "Commit",
|
||||
rollback: "Rollback",
|
||||
transactionSaveHint: "Commit {count} pending change(s) in a transaction.",
|
||||
nonTransactionalSaveHint:
|
||||
"Save {count} pending change(s) one by one. If one fails, earlier successful changes will not be rolled back.",
|
||||
transactionActive: "Editing",
|
||||
queryEditReady: "Editable",
|
||||
queryEditReadyHint:
|
||||
"This single-table result comes from “{table}”. You can edit, delete, or add rows, then commit to save.",
|
||||
"This single-table result comes from “{table}”. You can edit, delete, or add rows, then use the pending-changes action to save.",
|
||||
queryEditReadOnly: "Read-only result",
|
||||
queryEditUnsupported: {
|
||||
"not-select": "Only SELECT query results can be edited directly.",
|
||||
|
||||
@@ -344,6 +344,9 @@ export default {
|
||||
refresh: "Actualizar",
|
||||
commit: "Confirmar",
|
||||
rollback: "Revertir",
|
||||
transactionSaveHint: "Confirma {count} cambio(s) pendiente(s) en una transacción.",
|
||||
nonTransactionalSaveHint:
|
||||
"Guarda {count} cambio(s) pendiente(s) uno por uno. Si uno falla, los cambios anteriores correctos no se revierten.",
|
||||
transactionActive: "Editando",
|
||||
sortUnsupported: "Este SQL no admite ordenamiento del resultado completo. Intenta con una consulta SELECT simple.",
|
||||
truncatedHint: "Los resultados están limitados a 10.000 filas. Usa LIMIT/OFFSET en tu consulta para paginar.",
|
||||
|
||||
@@ -372,9 +372,11 @@ export default {
|
||||
refresh: "刷新",
|
||||
commit: "提交",
|
||||
rollback: "回滚",
|
||||
transactionSaveHint: "在事务中提交 {count} 项待保存更改。",
|
||||
nonTransactionalSaveHint: "逐条保存 {count} 项更改;如果中途失败,前面已成功的更改不会回滚。",
|
||||
transactionActive: "编辑中",
|
||||
queryEditReady: "可编辑",
|
||||
queryEditReadyHint: "这是来自“{table}”的单表结果,可直接修改、删除或新增行,最后点击提交保存。",
|
||||
queryEditReadyHint: "这是来自“{table}”的单表结果,可直接修改、删除或新增行,最后点击待保存按钮保存。",
|
||||
queryEditReadOnly: "只读结果",
|
||||
queryEditUnsupported: {
|
||||
"not-select": "只有 SELECT 查询结果可以直接编辑。",
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
export interface DataGridSaveActionMode {
|
||||
labelKey: "grid.pendingChanges";
|
||||
tooltipKey: "grid.transactionSaveHint" | "grid.nonTransactionalSaveHint";
|
||||
secondaryActionKey: "grid.rollback" | "grid.discard";
|
||||
}
|
||||
|
||||
export function dataGridSaveActionMode(options: {
|
||||
pendingChangeCount: number;
|
||||
useTransaction: boolean;
|
||||
}): DataGridSaveActionMode {
|
||||
return {
|
||||
labelKey: "grid.pendingChanges",
|
||||
tooltipKey: options.useTransaction ? "grid.transactionSaveHint" : "grid.nonTransactionalSaveHint",
|
||||
secondaryActionKey: options.useTransaction ? "grid.rollback" : "grid.discard",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { strict as assert } from "node:assert";
|
||||
import test from "node:test";
|
||||
import { dataGridSaveActionMode } from "../../apps/desktop/src/lib/dataGridSaveUi.ts";
|
||||
|
||||
test("uses pending-change count as the primary grid save action label", () => {
|
||||
assert.deepEqual(dataGridSaveActionMode({ pendingChangeCount: 3, useTransaction: true }), {
|
||||
labelKey: "grid.pendingChanges",
|
||||
tooltipKey: "grid.transactionSaveHint",
|
||||
secondaryActionKey: "grid.rollback",
|
||||
});
|
||||
|
||||
assert.deepEqual(dataGridSaveActionMode({ pendingChangeCount: 3, useTransaction: false }), {
|
||||
labelKey: "grid.pendingChanges",
|
||||
tooltipKey: "grid.nonTransactionalSaveHint",
|
||||
secondaryActionKey: "grid.discard",
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user