Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(core): default Base tables to zero records (#7372)

Univer596510134678
diff --git a/packages/core/src/bases/__tests__/base-data-model.spec.ts b/packages/core/src/bases/__tests__/base-data-model.spec.ts
index 20947e8d3f..b98ee0d711 100644
--- a/packages/core/src/bases/__tests__/base-data-model.spec.ts
+++ b/packages/core/src/bases/__tests__/base-data-model.spec.ts
@@ -20,6 +20,19 @@ import { BaseDataModel } from '../base-data-model';
import { BaseFieldType } from '../typedef';
describe('BaseDataModel', () => {
+ it('creates an empty default table without persistent records', () => {
+ const model = new BaseDataModel({ id: 'base-1', name: 'Base' });
+ const snapshot = model.getSnapshot();
+ const table = snapshot.tables['table-1'];
+
+ expect(snapshot.tableOrder).toEqual(['table-1']);
+ expect(table.recordOrder).toEqual([]);
+ expect(table.records).toEqual({});
+ expect(table.rowId).toEqual({});
+ expect(table.rowIndex).toEqual({});
+ expect(table.cellData).toEqual({});
+ });
+
it('keeps complete recordOrder without sorting all records', () => {
const throwingOrderKey = {
localeCompare: () => {
diff --git a/packages/core/src/bases/empty-snapshot.ts b/packages/core/src/bases/empty-snapshot.ts
index 79acf61bf8..f92f89cfcc 100644
--- a/packages/core/src/bases/empty-snapshot.ts
+++ b/packages/core/src/bases/empty-snapshot.ts
@@ -34,7 +34,7 @@ export function createDefaultBaseTableSnapshot(options: ICreateDefaultBaseTableS
const now = options.now ?? Date.now();
const primaryFieldId = options.primaryFieldId ?? generateRandomId(6);
const gridViewId = options.gridViewId ?? generateRandomId(6);
- const recordCount = options.recordCount ?? 5;
+ const recordCount = options.recordCount ?? 0;
const primaryField: IFieldSnapshot = {
id: primaryFieldId,
name: options.primaryFieldName ?? 'Name',
@@ -114,7 +114,7 @@ export function getEmptySnapshot(
id: tableId,
name: 'Table 1',
now,
- recordCount: 5,
+ recordCount: 0,
}),
},
createdAt: now,