mirror of
https://github.com/dream-num/univer.git
synced 2026-09-21 05:44:04 +08:00
revert: "fix(formula): fix where the formula calculation could not be recalculated after it was interrupted in certain situations (#6454)" (#6464)
This commit is contained in:
@@ -166,7 +166,6 @@ export class FFormula extends FBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `onCalculationEnd` instead.
|
||||
* Wait for computing in the Univer instance to complete. Please note that this does not only include formula calculation,
|
||||
* but also other computing tasks, e.g. pivot table calculation.
|
||||
* @param {number} [timeout] The maximum time to wait for the computing to complete, in milliseconds. The default
|
||||
@@ -193,7 +192,7 @@ export class FFormula extends FBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for the formula calculation to complete.
|
||||
* @deprecated Use `whenComputingCompleteAsync` instead.
|
||||
* @returns {Promise<void>} This method returns a promise that resolves when the calculation is complete.
|
||||
*/
|
||||
onCalculationEnd(): Promise<void> {
|
||||
|
||||
+86
-55
@@ -639,19 +639,19 @@ describe('Test update formula ', () => {
|
||||
expect(values).toStrictEqual([
|
||||
[null],
|
||||
[null],
|
||||
[{ f: '=A1' }],
|
||||
[{ f: '=A2' }],
|
||||
[{ f: '=A3' }],
|
||||
[{ f: '=A4' }],
|
||||
[{ f: '=A1', t: 2, v: 1 }],
|
||||
[{ f: '=A2', t: 2, v: 2 }],
|
||||
[{ f: '=A3', t: 2, v: 3 }],
|
||||
[{ f: '=A4', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
|
||||
const valuesUndo = getValues(0, 1, 5, 1, sheetId);
|
||||
expect(valuesUndo).toStrictEqual([
|
||||
[{ f: '=A1' }],
|
||||
[{ f: '=A2', si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ f: '=A1', t: 2, v: 1 }],
|
||||
[{ f: '=A2', si: 'W8Hdfc', t: 2, v: 2 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 3 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 4 }],
|
||||
[null],
|
||||
[null],
|
||||
]);
|
||||
@@ -661,10 +661,10 @@ describe('Test update formula ', () => {
|
||||
expect(valuesRedo).toStrictEqual([
|
||||
[null],
|
||||
[null],
|
||||
[{ f: '=A1' }],
|
||||
[{ f: '=A2' }],
|
||||
[{ f: '=A3' }],
|
||||
[{ f: '=A4' }],
|
||||
[{ f: '=A1', t: 2, v: 1 }],
|
||||
[{ f: '=A2', t: 2, v: 2 }],
|
||||
[{ f: '=A3', t: 2, v: 3 }],
|
||||
[{ f: '=A4', t: 2, v: 4 }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -696,12 +696,12 @@ describe('Test update formula ', () => {
|
||||
|
||||
expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy();
|
||||
const values1 = getValues(1, 3, 1, 3, sheetId);
|
||||
expect(values1).toStrictEqual([[{ f: '=A2' }]]);
|
||||
expect(values1).toStrictEqual([[{ f: '=A2', t: 2, v: 2 }]]);
|
||||
const values2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(values2).toStrictEqual([
|
||||
[null],
|
||||
[{ f: '=A3' }],
|
||||
[{ f: '=A4' }],
|
||||
[{ f: '=A3', t: 2, v: 3 }],
|
||||
[{ f: '=A4', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
|
||||
@@ -709,19 +709,19 @@ describe('Test update formula ', () => {
|
||||
expect(valuesUndo1).toStrictEqual([[null]]);
|
||||
const valuesUndo2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(valuesUndo2).toStrictEqual([
|
||||
[{ f: '=A2', si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ f: '=A2', si: 'W8Hdfc', t: 2, v: 2 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 3 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
|
||||
const valuesRedo1 = getValues(1, 3, 1, 3, sheetId);
|
||||
expect(valuesRedo1).toStrictEqual([[{ f: '=A2' }]]);
|
||||
expect(valuesRedo1).toStrictEqual([[{ f: '=A2', t: 2, v: 2 }]]);
|
||||
const valuesRedo2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(valuesRedo2).toStrictEqual([
|
||||
[null],
|
||||
[{ f: '=A3' }],
|
||||
[{ f: '=A4' }],
|
||||
[{ f: '=A3', t: 2, v: 3 }],
|
||||
[{ f: '=A4', t: 2, v: 4 }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -753,12 +753,12 @@ describe('Test update formula ', () => {
|
||||
|
||||
expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy();
|
||||
const values1 = getValues(2, 3, 2, 3, sheetId);
|
||||
expect(values1).toStrictEqual([[{ f: '=A3' }]]);
|
||||
expect(values1).toStrictEqual([[{ f: '=A3', t: 2, v: 3 }]]);
|
||||
const values2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(values2).toStrictEqual([
|
||||
[{ f: '=A2', si: 'W8Hdfc' }],
|
||||
[{ f: '=A2', si: 'W8Hdfc', t: 2, v: 2 }],
|
||||
[null],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
|
||||
@@ -766,19 +766,19 @@ describe('Test update formula ', () => {
|
||||
expect(valuesUndo1).toStrictEqual([[null]]);
|
||||
const valuesUndo2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(valuesUndo2).toStrictEqual([
|
||||
[{ f: '=A2', si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ f: '=A2', si: 'W8Hdfc', t: 2, v: 2 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 3 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
|
||||
const valuesRedo1 = getValues(2, 3, 2, 3, sheetId);
|
||||
expect(valuesRedo1).toStrictEqual([[{ f: '=A3' }]]);
|
||||
expect(valuesRedo1).toStrictEqual([[{ f: '=A3', t: 2, v: 3 }]]);
|
||||
const valuesRedo2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(valuesRedo2).toStrictEqual([
|
||||
[{ f: '=A2', si: 'W8Hdfc' }],
|
||||
[{ f: '=A2', si: 'W8Hdfc', t: 2, v: 2 }],
|
||||
[null],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 4 }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -810,30 +810,30 @@ describe('Test update formula ', () => {
|
||||
|
||||
expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy();
|
||||
const values1 = getValues(1, 3, 2, 3, sheetId);
|
||||
expect(values1).toStrictEqual([[{ f: '=A2' }], [{ f: '=A3' }]]);
|
||||
expect(values1).toStrictEqual([[{ f: '=A2', t: 2, v: 2 }], [{ f: '=A3', t: 2, v: 3 }]]);
|
||||
const values2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(values2).toStrictEqual([
|
||||
[null],
|
||||
[null],
|
||||
[{ f: '=A4' }],
|
||||
[{ f: '=A4', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
|
||||
const valuesUndo = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(valuesUndo).toStrictEqual([
|
||||
[{ f: '=A2', si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ si: 'W8Hdfc' }],
|
||||
[{ f: '=A2', si: 'W8Hdfc', t: 2, v: 2 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 3 }],
|
||||
[{ si: 'W8Hdfc', t: 2, v: 4 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
|
||||
const valuesRedo1 = getValues(1, 3, 2, 3, sheetId);
|
||||
expect(valuesRedo1).toStrictEqual([[{ f: '=A2' }], [{ f: '=A3' }]]);
|
||||
expect(valuesRedo1).toStrictEqual([[{ f: '=A2', t: 2, v: 2 }], [{ f: '=A3', t: 2, v: 3 }]]);
|
||||
const valuesRedo2 = getValues(1, 1, 3, 1, sheetId);
|
||||
expect(valuesRedo2).toStrictEqual([
|
||||
[null],
|
||||
[null],
|
||||
[{ f: '=A4' }],
|
||||
[{ f: '=A4', t: 2, v: 4 }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -858,25 +858,25 @@ describe('Test update formula ', () => {
|
||||
expect(await commandService.executeCommand(MoveRangeCommand.id, params)).toBeTruthy();
|
||||
const values = getValues(18, 1, 20, 2);
|
||||
expect(values).toStrictEqual([
|
||||
[null, { f: '=SUM(A19)' }],
|
||||
[null, { f: '=SUM(A20)' }],
|
||||
[null, { f: '=SUM(A21)' }],
|
||||
[null, { f: '=SUM(A19)', t: 2, v: 1 }],
|
||||
[null, { f: '=SUM(A20)', t: 2, v: 2 }],
|
||||
[null, { f: '=SUM(A21)', t: 2, v: 3 }],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
|
||||
const valuesUndo = getValues(18, 1, 20, 2);
|
||||
expect(valuesUndo).toStrictEqual([
|
||||
[{ f: '=SUM(A19)' }, null],
|
||||
[{ f: '=SUM(A20)', si: 'id1' }, null],
|
||||
[{ si: 'id1' }, null],
|
||||
[{ f: '=SUM(A19)', t: 2, v: 1 }, null],
|
||||
[{ f: '=SUM(A20)', si: 'id1', t: 2, v: 2 }, null],
|
||||
[{ si: 'id1', t: 2, v: 3 }, null],
|
||||
]);
|
||||
|
||||
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
|
||||
const valuesRedo = getValues(18, 1, 20, 2);
|
||||
expect(valuesRedo).toStrictEqual([
|
||||
[null, { f: '=SUM(A19)' }],
|
||||
[null, { f: '=SUM(A20)' }],
|
||||
[null, { f: '=SUM(A21)' }],
|
||||
[null, { f: '=SUM(A19)', t: 2, v: 1 }],
|
||||
[null, { f: '=SUM(A20)', t: 2, v: 2 }],
|
||||
[null, { f: '=SUM(A21)', t: 2, v: 3 }],
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -1586,21 +1586,52 @@ describe('Test update formula ', () => {
|
||||
const values = getValues(21, 0, 21, 4);
|
||||
|
||||
// Ignore the calculation results and only verify the offset information
|
||||
expect(values).toStrictEqual([
|
||||
[{ f: '=OFFSET(#REF!,1,1)' }, { f: '=OFFSET(#REF!,1,1)' }, { f: '=OFFSET(A1,1,1)' }, null, null],
|
||||
]);
|
||||
expect(values).toStrictEqual([[{
|
||||
f: '=OFFSET(#REF!,1,1)',
|
||||
v: 0,
|
||||
t: 2,
|
||||
}, {
|
||||
f: '=OFFSET(#REF!,1,1)',
|
||||
v: 1,
|
||||
t: 2,
|
||||
}, {
|
||||
f: '=OFFSET(A1,1,1)',
|
||||
v: 1,
|
||||
t: 2,
|
||||
}, null, null]]);
|
||||
|
||||
expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
|
||||
const valuesUndo = getValues(21, 0, 21, 4);
|
||||
expect(valuesUndo).toStrictEqual([
|
||||
[null, null, { f: '=OFFSET(A1,1,1)' }, { f: '=OFFSET(B1,1,1)', si: 'id2' }, { si: 'id2' }],
|
||||
]);
|
||||
expect(valuesUndo).toStrictEqual([[null, null, {
|
||||
f: '=OFFSET(A1,1,1)',
|
||||
v: 0,
|
||||
t: 2,
|
||||
}, {
|
||||
f: '=OFFSET(B1,1,1)',
|
||||
si: 'id2',
|
||||
v: 1,
|
||||
t: 2,
|
||||
}, {
|
||||
si: 'id2',
|
||||
v: 1,
|
||||
t: 2,
|
||||
}]]);
|
||||
|
||||
expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
|
||||
const valuesRedo = getValues(21, 0, 21, 4);
|
||||
expect(valuesRedo).toStrictEqual([
|
||||
[{ f: '=OFFSET(#REF!,1,1)' }, { f: '=OFFSET(#REF!,1,1)' }, { f: '=OFFSET(A1,1,1)' }, null, null],
|
||||
]);
|
||||
expect(valuesRedo).toStrictEqual([[{
|
||||
f: '=OFFSET(#REF!,1,1)',
|
||||
v: 0,
|
||||
t: 2,
|
||||
}, {
|
||||
f: '=OFFSET(#REF!,1,1)',
|
||||
v: 1,
|
||||
t: 2,
|
||||
}, {
|
||||
f: '=OFFSET(A1,1,1)',
|
||||
v: 1,
|
||||
t: 2,
|
||||
}, null, null]]);
|
||||
});
|
||||
|
||||
it('Remove column, removed column contains formula', async () => {
|
||||
|
||||
@@ -143,12 +143,6 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, bo
|
||||
|
||||
const overwriteCellPropertiesSet = new Set(['f', 'p', 'si', 'custom', 'ref', 'xf']);
|
||||
function mergeCellData(newValue: ICellData, oldValue: ICellData, styles: Styles) {
|
||||
// If there is a formula in the new value, delete the old value v key to avoid conflicts
|
||||
if (newValue.f || newValue.si) {
|
||||
delete oldValue.v;
|
||||
delete oldValue.t;
|
||||
}
|
||||
|
||||
const type = getCellType(styles, newValue, oldValue);
|
||||
Object.keys(newValue).forEach((key) => {
|
||||
const cellPropertyKey = key as keyof ICellData;
|
||||
|
||||
@@ -70,9 +70,6 @@ export async function expectMoveFormulaRowsResultMatchesSnapshot() {
|
||||
const rowSpec = worksheet.getRange('3:3');
|
||||
worksheet.moveRows(rowSpec, 4);
|
||||
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
const resultSnapshot = workbook.save();
|
||||
const snapshotFilePath = path.resolve(snapshotRootDir, `${getTestFilePath()}-result.json`);
|
||||
if (fs.existsSync(snapshotFilePath)) {
|
||||
@@ -87,8 +84,6 @@ export async function expectMoveFormulaRowsResultMatchesSnapshot() {
|
||||
|
||||
// perform undo operation
|
||||
await testBed.api.undo();
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
// compare the result with the snapshot
|
||||
const resultSnapshot_undo = workbook.save();
|
||||
@@ -125,9 +120,6 @@ export async function expectMoveFormulaSiRowsResultMatchesSnapshot() {
|
||||
const rowSpec = worksheet.getRange('3:3');
|
||||
worksheet.moveRows(rowSpec, 4);
|
||||
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
const resultSnapshot = workbook.save();
|
||||
const snapshotFilePath = path.resolve(snapshotRootDir, `${getTestFilePath()}-result.json`);
|
||||
if (fs.existsSync(snapshotFilePath)) {
|
||||
@@ -142,8 +134,6 @@ export async function expectMoveFormulaSiRowsResultMatchesSnapshot() {
|
||||
|
||||
// perform undo operation
|
||||
await testBed.api.undo();
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
// compare the result with the snapshot
|
||||
const resultSnapshot_undo = workbook.save();
|
||||
@@ -184,9 +174,6 @@ export async function expectMoveFormulaCellResultMatchesSnapshot() {
|
||||
toRange,
|
||||
});
|
||||
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
const resultSnapshot = workbook.save();
|
||||
const snapshotFilePath = path.resolve(snapshotRootDir, `${getTestFilePath()}-result.json`);
|
||||
if (fs.existsSync(snapshotFilePath)) {
|
||||
@@ -201,8 +188,6 @@ export async function expectMoveFormulaCellResultMatchesSnapshot() {
|
||||
|
||||
// perform undo operation
|
||||
await testBed.api.undo();
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
// compare the result with the snapshot
|
||||
const resultSnapshot_undo = workbook.save();
|
||||
|
||||
@@ -69,9 +69,6 @@ export async function expectRemoveRowsOfFilterRowsResultMatchesSnapshot() {
|
||||
// remove rows 2 to 5, where the 3 to 4 rows are filtered rows
|
||||
worksheet.deleteRows(1, 4);
|
||||
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
const resultSnapshot = workbook.save();
|
||||
const snapshotFilePath = path.resolve(snapshotRootDir, `${getTestFilePath()}-result.json`);
|
||||
if (fs.existsSync(snapshotFilePath)) {
|
||||
@@ -86,8 +83,6 @@ export async function expectRemoveRowsOfFilterRowsResultMatchesSnapshot() {
|
||||
|
||||
// perform undo operation
|
||||
await testBed.api.undo();
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
// compare the result with the snapshot
|
||||
const resultSnapshot_undo = workbook.save();
|
||||
|
||||
@@ -47,8 +47,8 @@ export async function expectCalculationResultMatchesSnapshot() {
|
||||
const testSnapshot = JSON.parse(testSnapshotRaw) as IWorkbookData;
|
||||
|
||||
const workbook = testBed.api.createWorkbook(testSnapshot);
|
||||
|
||||
await testBed.api.getFormula().onCalculationResultApplied();
|
||||
const formula = testBed.api.getFormula();
|
||||
await formula.onCalculationEnd();
|
||||
|
||||
const resultSnapshot = workbook.save();
|
||||
const snapshotFilePath = path.resolve(snapshotRootDir, `${getTestFilePath()}-result.json`);
|
||||
|
||||
Reference in New Issue
Block a user