Skip to content

Commit

Permalink
fix(formula): worker error (#1565)
Browse files Browse the repository at this point in the history
* fix(formula): worker error

* fix(formula): merge interface
  • Loading branch information
DR-Univer committed Mar 13, 2024
1 parent 5aeb65f commit 47377ae
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/engine-formula/src/basics/common.ts
Expand Up @@ -69,6 +69,10 @@ export interface IRuntimeUnitDataType {
[unitId: string]: Nullable<{ [sheetId: string]: ObjectMatrix<Nullable<ICellData>> }>;
}

export interface IRuntimeUnitDataPrimitiveType {
[unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<ICellData>> }>;
}

export interface IRuntimeOtherUnitDataType {
[unitId: string]: Nullable<{ [sheetId: string]: Nullable<{ [formulaId: string]: ICellData }> }>;
}
Expand All @@ -93,9 +97,7 @@ export interface IFeatureDirtyRangeType {
[unitId: string]: Nullable<{ [sheetId: string]: IRange[] }>;
}

export interface IArrayFormulaUnitCellType {
[unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<Nullable<ICellData>> }>;
}
export interface IArrayFormulaUnitCellType extends IRuntimeUnitDataPrimitiveType {}

export interface IFormulaData {
[unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<IFormulaDataItem> }>;
Expand Down
25 changes: 24 additions & 1 deletion packages/engine-formula/src/basics/runtime.ts
Expand Up @@ -16,7 +16,7 @@

import { ObjectMatrix } from '@univerjs/core';

import type { IArrayFormulaUnitCellType, IRuntimeUnitDataType } from './common';
import type { IArrayFormulaUnitCellType, IRuntimeUnitDataPrimitiveType, IRuntimeUnitDataType } from './common';

export function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType) {
const arrayFormulaCellData: IRuntimeUnitDataType = {};
Expand All @@ -40,3 +40,26 @@ export function convertUnitDataToRuntime(unitData: IArrayFormulaUnitCellType) {

return arrayFormulaCellData;
}

export function convertRuntimeToUnitData(unitData: IRuntimeUnitDataType) {
const unitPrimitiveData: IRuntimeUnitDataPrimitiveType = {};
Object.keys(unitData).forEach((unitId) => {
const sheetData = unitData[unitId];

if (sheetData == null) {
return true;
}

if (unitPrimitiveData[unitId] == null) {
unitPrimitiveData[unitId] = {};
}

Object.keys(sheetData).forEach((sheetId) => {
const cellData = sheetData[sheetId];

unitPrimitiveData[unitId]![sheetId] = cellData.getData();
});
});

return unitPrimitiveData;
}
Expand Up @@ -22,7 +22,7 @@ import type {
IDirtyUnitSheetNameMap,
INumfmtItemMap,
IRuntimeOtherUnitDataType,
IRuntimeUnitDataType,
IRuntimeUnitDataPrimitiveType,
} from '../../basics/common';
import type { FormulaExecutedStateType, IExecutionInProgressParams } from '../../services/runtime.service';

Expand Down Expand Up @@ -64,7 +64,7 @@ export const SetFormulaCalculationNotificationMutation: IMutation<ISetFormulaCal
};

export interface ISetFormulaCalculationResultMutation {
unitData: IRuntimeUnitDataType;
unitData: IRuntimeUnitDataPrimitiveType;
unitOtherData: IRuntimeOtherUnitDataType;
}

Expand Down
Expand Up @@ -35,6 +35,7 @@ import { CalculateFormulaService } from '../services/calculate-formula.service';
import type { IAllRuntimeData } from '../services/runtime.service';
import { FormulaExecutedStateType } from '../services/runtime.service';
import { SetNumfmtFormulaDataMutation } from '../commands/mutations/set-numfmt-formula-data.mutation';
import { convertRuntimeToUnitData } from '../basics/runtime';

@OnLifecycle(LifecycleStages.Ready, CalculateController)
export class CalculateController extends Disposable {
Expand Down Expand Up @@ -234,7 +235,7 @@ export class CalculateController extends Disposable {
this._commandService.executeCommand(
SetFormulaCalculationResultMutation.id,
{
unitData,
unitData: convertRuntimeToUnitData(unitData),
unitOtherData,
},
{
Expand Down
Expand Up @@ -70,7 +70,7 @@ export class CalculateResultApplyController extends Disposable {
const setRangeValuesMutation = {
subUnitId: sheetId,
unitId,
cellValue: cellData.getData(),
cellValue: cellData,
};

redoMutationsInfo.push({
Expand Down

0 comments on commit 47377ae

Please sign in to comment.