Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(data-grid): placeholder for pending rows in original row number

xianghu908a6696f07ed82
diff --git a/apps/desktop/src/lib/dataGrid/__tests__/dataGridRowNumber.spec.ts b/apps/desktop/src/lib/dataGrid/__tests__/dataGridRowNumber.spec.ts
index 3111d12c2e..a6a8319e94 100644
--- a/apps/desktop/src/lib/dataGrid/__tests__/dataGridRowNumber.spec.ts
+++ b/apps/desktop/src/lib/dataGrid/__tests__/dataGridRowNumber.spec.ts
@@ -19,9 +19,19 @@ describe("data grid row number labels", () => {
expect(resolveDataGridRowNumberLabel({ displayIndex: 2, sourceIndex: 36, sourceRowNumbers: true, pageOffset: 100 })).toBe("137");
});
- it("falls back to the view position for rows without a source index", () => {
- // 新增行还没有落库位置,sourceIndex 为 undefined
- expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: true, pageOffset: 0 })).toBe("8");
+ it("uses a placeholder for rows without an original position", () => {
+ // 新增行还没有落库位置(sourceIndex 为 undefined):原始行号模式下用 "+" 占位。
+ // 不能回退到视图序号,否则会与紧随其后的那一行撞号。
+ expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: true, pageOffset: 0 })).toBe("+");
+ expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: true, pageOffset: 100 })).toBe("+");
+ // 视图序号模式不受影响,新增行照常显示它在列表中的位置
+ expect(resolveDataGridRowNumberLabel({ displayIndex: 7, sourceRowNumbers: false, pageOffset: 0 })).toBe("8");
+ });
+
+ it("keeps an inserted row from colliding with the row below it", () => {
+ // 新增行占住显示位置 3(displayIndex 2),紧随其后的原始第 3 行 sourceIndex 为 2
+ expect(resolveDataGridRowNumberLabel({ displayIndex: 2, sourceRowNumbers: true, pageOffset: 0 })).toBe("+");
+ expect(resolveDataGridRowNumberLabel({ displayIndex: 3, sourceIndex: 2, sourceRowNumbers: true, pageOffset: 0 })).toBe("3");
});
it("keeps the draft placeholder regardless of the mode", () => {
diff --git a/apps/desktop/src/lib/dataGrid/dataGridRowNumber.ts b/apps/desktop/src/lib/dataGrid/dataGridRowNumber.ts
index b54127be02..b136851850 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridRowNumber.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridRowNumber.ts
@@ -5,7 +5,8 @@
* 行状态筛选),被隐藏的行后面的行号会整体前移,无法再对应回完整结果里的位置。
* `sourceIndex` 是筛选前的原始下标,一直保留在行数据里,因此 `source` 模式直接用它,
* 让筛选前后同一个行号始终指向同一条数据。分页模式下原始下标是页内下标,
- * 仍需叠加页偏移才能得到完整结果中的位置。
+ * 仍需叠加页偏移才能得到完整结果中的位置。未落库的新增行没有原始位置,
+ * 用 "+" 占位(原因见下方函数内注释);草稿行沿用 "*"。
*/
export interface DataGridRowNumberInput {
displayIndex: number;
@@ -20,6 +21,9 @@ export interface DataGridRowNumberInput {
export function resolveDataGridRowNumberLabel(input: DataGridRowNumberInput): string {
// 待保存的草稿行没有落库位置,保持原有的 "*" 占位
if (input.isDraft) return "*";
+ // 原始行号模式下,未落库的新增行没有「原始位置」可言。这里用占位符而不是回退到
+ // 视图序号:回退会让它与紧随其后的那一行撞号(插入点之后正好错位 1,两行同号)。
+ if (input.sourceRowNumbers && input.sourceIndex === undefined) return "+";
const index = input.sourceRowNumbers && input.sourceIndex !== undefined ? input.sourceIndex : input.displayIndex;
return String(index + 1 + input.pageOffset);
}