Skip to content

Commit

Permalink
feat(conditional-format): support conditional format (#1681)
Browse files Browse the repository at this point in the history
* feat(conditional-format): init

* feat(cf): init conditional format model

* fix(dev): fix dev config

* feat(cf):  mark dirty when change conditional rule

* feat(numfmt): support serial time  to timestamp

* feat(cf): support text number time operator

* feat(cf): add priority cache

* feat(cf): change cfid type to string from number

* fix(cf): diff value type

* feat(cf): add render highlightCell demo

* chore(cf): add condition format plugin to example

* feat(sheet): add skeleton update

* feat(cf): support average

* feat(cf): support rank

* feat(cf): support cell change and caculate cf

* feat(cf): add caculate cache

* feat(cf): supports rendering linkage

* feat(cf): do not empty style when markDirty

* feat(cf): support mix old style

* docs(cf): docs

* feat(cf): add base command and mutation

* style(cf): format

* fix(cf): can not move to the top

* feat(cf): add undo mutation

* fix(cf): reduce the cell sort time ,50%

* fix(cf): reduce the cost of mark dirty ,80%

* fix(cf): the interval contains the tail

* feat(cf): support data bar

* chore(cf): format code

* fix(cf): data bar suppoer gradient

* feat(cf): support color scale

* feat(ref-range): support default range change util

* feat(cf): conditional format support ref range

* fix(cf): some ref range bug

* feat(cf): conditional format support copy/paste

* feat(cf): support auto fill

* feat(cf): clear cf when sheet is deleted

* fix(cf): the target populated area needs to be cleared

* fix(cf): after each setting, the conditional format is cleared before rendering

* fix(cf): rule priority problem

* feat(cf): support panel set cf

* feat(cf): init menu

* feat(cf): support change priority

* chore(cf): rename

* feat(cf): support set/delete/move undo and redo

* feat(cf): add package config

* feat(cf): support i18n

* feat(cf): support preview

* fix(cf): new rules can not be retracted when added

* feat(cf): panel ui

* feat(cf): i18n support react node

* feat(cf): support t function nesting

* style(cf): ui fix

* fix(cf): serialTimeToTimestamp bugfix

* style(cf): ui fix

* feat(cf): support for persistence

* fix(cf): the node environment executes only the service logic, not the cleanup controller logic

* fix(cf): lint

* fix(cf): formula error

* feat(cf): support formula

* fix(formula): formulaId result

* fix(sheet): formula queue

* feat(formula): other formula dirty

* feat(cf): support formula mark dirty

* fix(sheet): other formula make dirty

* fix(cf): set default bg color is undefined

* feat(cf): support create rule from menu

* fix(cf): formula cache is not worke

* feat(cf): support absolute ref

* fix(formula): config service  ts error

* feat(cf): support formula value type

* feat(cf): reuse the last result before waiting for the result of the calculation

* feat(cf): menu support cf

* feat(formula): support batch register

* fix(formula): add batch interface

* feat(formula): batch remove

* fix(cf): support batch creation and deletion formulas are supported

* chore: delete obsolete file

* chore: delete obsolete file

* fix(cf): databar panel init state error

* chore(cf): extract the public code

* feat(cf): support icon set

* feat(cf): support pre build icon base64

* feat(cf): support icon set panel

* feat(cf): support range selector

* feat(cf): support formula editor

* fix(cf): error when folder does not exist

* feat(cf): iconSet support offset

* feat(cf): support clear conditional format

* fix(cf): add openForUnitId and openForSubUnitId

* feat(cf): add iconSet

* feat(cf): add icon group

* chore: extract scale color util

* feat(cf): preview support databar colorScale iconSet

* feat(cf): support set init range

* style(cf): ui fix

* fix(sheet): cf  recalculation can not be triggered when a date is involved

* fix(sheet): add form validation

* fix(cf): rangeSelector support placeholder

* feat(cf): clear menu support disabled

* feat(cf): update panel when change sheet

* chore: lint

* fix(cf): add i18n

* fix(cf): isShowValue is not work

* feat(cf): support iconSet menu

* fix(cf): init error

* test(cf): add highlight test case

* chore(cf): add type and doc

* chore(debugger): add sheet snapshot util

* style(cf): change default color

* test(cf): add colorscale and databar test case

* fix(cf): optimize dirty logic (#433)

* fix(cf): when previewing a number format, the conditional format style does not take effect (#439)

* fix(cf): fix checkbox error

* fix(cf): add databar min width

* fix(cf): ignore rich text

* fix(cf): some interceptors block subsequent logic execution

* fix(cf): support contains blanks

* feat(cf): support today

* fix(cf): reset formula

* wait

* fix(cf): filter abnormal settings

* fix(cf): can not modify icon set settings

* fix(cf): icon set support formula

* fix(cf): fix formula edit style

* fix(cf): verify not work when iconSet switch valueType

* fix(cf): iconset verify support formula

* fix(cf): duplicate and unique not work with p (#495)

* fix(cf): paste only the content without conditional formatting rules (#489)

* fix(cf): compose bius config (#487)

* fix(cf): different styles of icon set render different results (#485)

* fix(cf): the icon set should be above the data bar (#483)

* fix(cf): the warning prompt is in the wrong position (#480)

* fix(cf): the settings for filtering errors (#475)

* fix(cf): 0 can not be set (#472)

* fix(cf): error highlighting result of custom formula (#468)

* fix(cf): numerical calculations add type checking (#458)

* feat(cf): support clear (#433)

* feat(cf): select changes to update the rules panel(#437)

* fix(cf): 0 can not be set (#446)

* fix(cf): the style of the filter condition format is set after editing (#486)

* feat(cf): data bar gradient color adds border

* feat(cf): formula support absolute ref

* fix(cf): rule list panel were not updated in a timely manner (#437)

* feat(cf): number compare support mixed max and min

* feat(cf): support boolean compare (#461)

* fix(cf): add input validation (#454)

* feat(cf): zenZone hide cf

* fix(cf): error message does not disappear after update the icon set configuration(#480)

* test(core): add test case

* style(cf): enum should have prefix

* fix(ui): do not use hook use if logic

* style(cf): rename

* test(cf): add color scale test case

* fix(cf): not between support mixed max and min

* feat(cf): support empty icon

* style(cf): ui

---------

Co-authored-by: DR-Univer <[email protected]>
Co-authored-by: Dushusir <[email protected]>
  • Loading branch information
3 people committed Mar 28, 2024
1 parent eabe6fb commit 50edd34
Show file tree
Hide file tree
Showing 122 changed files with 12,908 additions and 1,362 deletions.
1 change: 1 addition & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@univerjs/icons": "^0.1.42",
"@univerjs/rpc": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-conditional-format": "workspace:*",
"@univerjs/sheets-find-replace": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ export const SaveSnapshotOptions: ICommand = {
const sheet = snapshot.sheets[sheetId];
snapshot.sheets = { [sheetId]: sheet };
snapshot.sheetOrder = [sheetId];
const text = JSON.stringify(filterStyle(snapshot), null, 2);
exportController.exportJson(text, `${preName} snapshot`);
break;
}

case 'workbook': {
const text = JSON.stringify(filterStyle(snapshot), null, 2);
// navigator.clipboard.writeText(text);
exportController.exportJson(text, `${preName} snapshot`);

break;
Expand Down
5 changes: 4 additions & 1 deletion examples/src/sheets/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { UniverSheetsNumfmtPlugin } from '@univerjs/sheets-numfmt';
import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';
import { UniverUIPlugin } from '@univerjs/ui';

import { SheetsConditionalFormatPlugin } from '@univerjs/sheets-conditional-format';
import { DebuggerPlugin } from '../plugins/debugger';
import { DEFAULT_WORKBOOK_DATA_DEMO } from '../data/sheets/demo/default-workbook-data-demo';
import { locales } from './locales';
Expand Down Expand Up @@ -82,6 +82,9 @@ univer.registerPlugin(UniverSheetsFindReplacePlugin);
// create univer sheet instance
univer.createUniverSheet(DEFAULT_WORKBOOK_DATA_DEMO);

// sheet condition format
univer.registerPlugin(SheetsConditionalFormatPlugin);

declare global {
interface Window {
univer?: Univer;
Expand Down
35 changes: 17 additions & 18 deletions packages/core/src/services/locale/locale.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,8 @@ export class LocaleService extends Disposable {
t = (key: string, ...args: string[]): string => {
if (!this._locales) throw new Error('Locale not initialized');

function resolveKeyPath(obj: ILanguagePack, keys: string[]): LanguageValue | null {
const currentKey = keys.shift();

if (currentKey && obj && currentKey in obj) {
const nextObj = (obj as ILanguagePack)[currentKey];

if (keys.length > 0 && (typeof nextObj === 'object' || Array.isArray(nextObj))) {
return resolveKeyPath(nextObj as ILanguagePack, keys);
} else {
return nextObj;
}
}

return null;
}

const keys = key.split('.');
const resolvedValue = resolveKeyPath(this._locales[this._currentLocale], keys);

const resolvedValue = this.resolveKeyPath(this._locales[this._currentLocale], keys);
if (typeof resolvedValue === 'string') {
let result = resolvedValue;
args.forEach((arg, index) => {
Expand All @@ -116,4 +99,20 @@ export class LocaleService extends Disposable {
getCurrentLocale() {
return this._currentLocale;
}

public resolveKeyPath(obj: ILanguagePack, keys: string[]): LanguageValue | null {
const currentKey = keys.shift();

if (currentKey && obj && currentKey in obj) {
const nextObj = (obj as ILanguagePack)[currentKey];

if (keys.length > 0 && (typeof nextObj === 'object' || Array.isArray(nextObj))) {
return this.resolveKeyPath(nextObj as ILanguagePack, keys);
} else {
return nextObj;
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class ResourceManagerService extends Disposable implements IResourceManag
registerPluginResource<T = any>(unitID: string, resourceName: string, hook: IResourceHook<T>) {
const resourceMap = this._resourceMap.get(unitID) || new Map<string, IResourceHook>();
if (resourceMap.has(resourceName)) {
throw new Error('the pluginName is registered');
throw new Error(`the pluginName is registered {${resourceName}}`);
}
resourceMap.set(resourceName, hook);
this._resourceMap.set(unitID, resourceMap);
Expand Down
33 changes: 33 additions & 0 deletions packages/core/src/shared/__test__/rectangle.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import { describe, expect, it } from 'vitest';

import { Rectangle } from '../rectangle';
import { AbsoluteRefType } from '../../types/interfaces/i-range';
import type { IRange } from '../../types/interfaces/i-range';

const cellToRange = (row: number, col: number) => ({ startRow: row, endRow: row, startColumn: col, endColumn: col } as IRange);
describe('test "Rectangle"', () => {
it('test "subtract"', () => {
// completely covered
Expand Down Expand Up @@ -77,4 +80,34 @@ describe('test "Rectangle"', () => {
{ startRow: 2, startColumn: 3, endRow: 2, endColumn: 3 },
]);
});

it('test getRelativeRange', () => {
const relativeRange = Rectangle.getRelativeRange({ startRow: 5, endRow: 6, startColumn: 5, endColumn: 6 }, cellToRange(10, 10));
expect(relativeRange).toEqual({
endColumn: 1,
endRow: 1,
startColumn: -5,
startRow: -5,
});
});
it('test getPositionRange', () => {
const originRange = { startRow: 5, endRow: 6, startColumn: 5, endColumn: 6 };
const relativeRange = Rectangle.getRelativeRange(originRange, cellToRange(10, 10));
const positionRange = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11));
expect(positionRange).toEqual({ startRow: 6, endRow: 7, startColumn: 6, endColumn: 7 });
const positionRangeWithAbsoluteStartAll = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, startAbsoluteRefType: AbsoluteRefType.ALL });
const positionRangeWithAbsoluteStartRow = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, startAbsoluteRefType: AbsoluteRefType.ROW });
const positionRangeWithAbsoluteStartCol = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, startAbsoluteRefType: AbsoluteRefType.COLUMN });
const positionRangeWithAbsoluteEndALl = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, endAbsoluteRefType: AbsoluteRefType.ALL });
const positionRangeWithAbsoluteEndRow = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, endAbsoluteRefType: AbsoluteRefType.ROW });
const positionRangeWithAbsoluteEndCol = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, endAbsoluteRefType: AbsoluteRefType.COLUMN });
const positionRangeWithALl = Rectangle.getPositionRange(relativeRange, cellToRange(11, 11), { ...originRange, endAbsoluteRefType: AbsoluteRefType.ALL, startAbsoluteRefType: AbsoluteRefType.ALL });
expect(positionRangeWithAbsoluteStartAll).toEqual({ ...originRange, endColumn: 7, endRow: 7, startAbsoluteRefType: AbsoluteRefType.ALL });
expect(positionRangeWithAbsoluteStartRow).toEqual({ ...originRange, startColumn: 6, endColumn: 7, endRow: 7, startAbsoluteRefType: AbsoluteRefType.ROW });
expect(positionRangeWithAbsoluteStartCol).toEqual({ ...originRange, startRow: 6, endColumn: 7, endRow: 7, startAbsoluteRefType: AbsoluteRefType.COLUMN });
expect(positionRangeWithAbsoluteEndALl).toEqual({ ...originRange, startRow: 6, startColumn: 6, endAbsoluteRefType: AbsoluteRefType.ALL });
expect(positionRangeWithAbsoluteEndRow).toEqual({ ...originRange, endColumn: 7, startRow: 6, startColumn: 6, endAbsoluteRefType: AbsoluteRefType.ROW });
expect(positionRangeWithAbsoluteEndCol).toEqual({ ...originRange, endRow: 7, startRow: 6, startColumn: 6, endAbsoluteRefType: AbsoluteRefType.COLUMN });
expect(positionRangeWithALl).toEqual({ ...originRange, endAbsoluteRefType: AbsoluteRefType.ALL, startAbsoluteRefType: AbsoluteRefType.ALL });
});
});
16 changes: 9 additions & 7 deletions packages/core/src/shared/rectangle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { IRange } from '../types/interfaces/i-range';
import { RANGE_TYPE } from '../types/interfaces/i-range';
import { AbsoluteRefType, RANGE_TYPE } from '../types/interfaces/i-range';
import type { Nullable } from './types';

/**
Expand Down Expand Up @@ -193,13 +193,15 @@ export class Rectangle {
endColumn: range.endColumn - range.startColumn,
}) as IRange;

static getPositionRange = (relativeRange: IRange, originRange: IRange) =>
({
startRow: relativeRange.startRow + originRange.startRow,
endRow: relativeRange.endRow + relativeRange.startRow + originRange.startRow,
startColumn: relativeRange.startColumn + originRange.startColumn,
endColumn: relativeRange.endColumn + relativeRange.startColumn + originRange.startColumn,
static getPositionRange = (relativeRange: IRange, originRange: IRange, absoluteRange?: IRange) => {
return ({
...(absoluteRange || {}),
startRow: absoluteRange ? ([AbsoluteRefType.ROW, AbsoluteRefType.ALL].includes(absoluteRange.startAbsoluteRefType || 0) ? absoluteRange.startRow : relativeRange.startRow + originRange.startRow) : (relativeRange.startRow + originRange.startRow),
endRow: absoluteRange ? ([AbsoluteRefType.ROW, AbsoluteRefType.ALL].includes(absoluteRange.endAbsoluteRefType || 0) ? absoluteRange.endRow : relativeRange.endRow + relativeRange.startRow + originRange.startRow) : (relativeRange.endRow + relativeRange.startRow + originRange.startRow),
startColumn: absoluteRange ? ([AbsoluteRefType.COLUMN, AbsoluteRefType.ALL].includes(absoluteRange.startAbsoluteRefType || 0) ? absoluteRange.startColumn : relativeRange.startColumn + originRange.startColumn) : relativeRange.startColumn + originRange.startColumn,
endColumn: absoluteRange ? ([AbsoluteRefType.COLUMN, AbsoluteRefType.ALL].includes(absoluteRange.endAbsoluteRefType || 0) ? absoluteRange.endColumn : relativeRange.endColumn + relativeRange.startColumn + originRange.startColumn) : relativeRange.endColumn + relativeRange.startColumn + originRange.startColumn,
}) as IRange;
};

static moveHorizontal = (range: IRange, step: number = 0, length: number = 0): IRange => ({
...range,
Expand Down
7 changes: 6 additions & 1 deletion packages/engine-formula/src/basics/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface IRuntimeUnitDataPrimitiveType {
}

export interface IRuntimeOtherUnitDataType {
[unitId: string]: Nullable<{ [sheetId: string]: Nullable<{ [formulaId: string]: ICellData }> }>;
[unitId: string]: Nullable<{ [sheetId: string]: Nullable<{ [formulaId: string]: Nullable<ICellData>[][] }> }>;
}

export interface IUnitSheetNameMap {
Expand All @@ -93,6 +93,10 @@ export interface IDirtyUnitFeatureMap {
[unitId: string]: Nullable<{ [sheetId: string]: { [featureId: string]: boolean } }>;
}

export interface IDirtyUnitOtherFormulaMap {
[unitId: string]: Nullable<{ [sheetId: string]: { [formulaId: string]: boolean } }>;
}

export interface IArrayFormulaRangeType {
[unitId: string]: Nullable<{ [sheetId: string]: IObjectMatrixPrimitiveType<IRange> }>;
}
Expand Down Expand Up @@ -154,6 +158,7 @@ export interface IFormulaDatasetConfig {
dirtyRanges: IUnitRange[];
dirtyNameMap: IDirtyUnitSheetNameMap;
dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
numfmtItemMap: INumfmtItemMap;
excludedCell?: IUnitExcludedCell;
allUnitData?: IUnitData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CommandType } from '@univerjs/core';

import type {
IDirtyUnitFeatureMap,
IDirtyUnitOtherFormulaMap,
IDirtyUnitSheetNameMap,
INumfmtItemMap,
IRuntimeOtherUnitDataType,
Expand All @@ -30,6 +31,7 @@ export interface ISetFormulaCalculationStartMutation {
dirtyRanges: IUnitRange[];
dirtyNameMap: IDirtyUnitSheetNameMap;
dirtyUnitFeatureMap: IDirtyUnitFeatureMap;
dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap;
options: Nullable<IExecutionOptions>;
numfmtItemMap: INumfmtItemMap;
forceCalculation?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,29 @@
import type { IMutation } from '@univerjs/core';
import { CommandType } from '@univerjs/core';

import type {
IOtherFormulaManagerInsertParam,
IOtherFormulaManagerSearchParam,
} from '../../services/other-formula-manager.service';
import type { IFormulaDataItem } from '../../basics/common';

export interface ISetOtherFormulaMutationParams {
unitId: string;
subUnitId: string;
formulaMap: Record<string, IFormulaDataItem>;
};
export interface IRemoveOtherFormulaMutationParams {
unitId: string;
subUnitId: string;
formulaIdList: string[];
};
/**
* In the formula engine, the mutation is solely responsible for communication between the worker and the main thread.
* It requires setting local to true during execution.
*/
export const SetOtherFormulaMutation: IMutation<IOtherFormulaManagerInsertParam> = {
export const SetOtherFormulaMutation: IMutation<ISetOtherFormulaMutationParams> = {
id: 'formula.mutation.set-other-formula',
type: CommandType.MUTATION,
handler: () => true,
};

export const RemoveOtherFormulaMutation: IMutation<IOtherFormulaManagerSearchParam> = {
export const RemoveOtherFormulaMutation: IMutation<IRemoveOtherFormulaMutationParams> = {
id: 'formula.mutation.remove-other-formula',
type: CommandType.MUTATION,
handler: () => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { ICommandInfo, IUnitRange } from '@univerjs/core';
import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle, Tools } from '@univerjs/core';
import { Inject } from '@wendellhu/redi';

import type { IDirtyUnitFeatureMap, IDirtyUnitSheetNameMap, IFormulaData, INumfmtItemMap } from '../basics/common';
import type { IDirtyUnitFeatureMap, IDirtyUnitOtherFormulaMap, IDirtyUnitSheetNameMap, IFormulaData, INumfmtItemMap } from '../basics/common';
import type { ISetArrayFormulaDataMutationParams } from '../commands/mutations/set-array-formula-data.mutation';
import { SetArrayFormulaDataMutation } from '../commands/mutations/set-array-formula-data.mutation';
import type { ISetFormulaCalculationStartMutation } from '../commands/mutations/set-formula-calculation.mutation';
Expand Down Expand Up @@ -71,9 +71,9 @@ export class CalculateController extends Disposable {
if (params.forceCalculation === true) {
this._calculate(true);
} else {
const { dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap, numfmtItemMap } = params;
const { dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, numfmtItemMap } = params;

this._calculate(false, dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap, numfmtItemMap);
this._calculate(false, dirtyRanges, dirtyNameMap, dirtyUnitFeatureMap, dirtyUnitOtherFormulaMap, numfmtItemMap);
}
} else if (command.id === SetArrayFormulaDataMutation.id) {
const params = command.params as ISetArrayFormulaDataMutationParams;
Expand All @@ -95,12 +95,14 @@ export class CalculateController extends Disposable {
dirtyRanges: IUnitRange[] = [],
dirtyNameMap: IDirtyUnitSheetNameMap = {},
dirtyUnitFeatureMap: IDirtyUnitFeatureMap = {},
dirtyUnitOtherFormulaMap: IDirtyUnitOtherFormulaMap = {},
numfmtItemMap: INumfmtItemMap = {}
) {
if (
dirtyRanges.length === 0 &&
Object.keys(dirtyNameMap).length === 0 &&
Object.keys(dirtyUnitFeatureMap).length === 0 &&
Object.keys(dirtyUnitOtherFormulaMap).length === 0 &&
forceCalculate === false
) {
return;
Expand All @@ -119,6 +121,7 @@ export class CalculateController extends Disposable {
dirtyRanges,
dirtyNameMap,
dirtyUnitFeatureMap,
dirtyUnitOtherFormulaMap,
numfmtItemMap,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
import type { ICommandInfo } from '@univerjs/core';
import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';

import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation';
import {
type IOtherFormulaManagerInsertParam,
type IOtherFormulaManagerSearchParam,
IOtherFormulaManagerService,
} from '../services/other-formula-manager.service';
import { RemoveOtherFormulaMutation, SetOtherFormulaMutation } from '../commands/mutations/set-other-formula.mutation';
import type { IRemoveOtherFormulaMutationParams, ISetOtherFormulaMutationParams } from '../commands/mutations/set-other-formula.mutation';

@OnLifecycle(LifecycleStages.Ready, SetOtherFormulaController)
export class SetOtherFormulaController extends Disposable {
Expand All @@ -43,19 +42,21 @@ export class SetOtherFormulaController extends Disposable {
this.disposeWithMe(
this._commandService.onCommandExecuted((command: ICommandInfo) => {
if (command.id === SetOtherFormulaMutation.id) {
const params = command.params as IOtherFormulaManagerInsertParam;
const params = command.params as ISetOtherFormulaMutationParams;
if (params == null) {
return;
}

this._otherFormulaManagerService.register(params);
const config = { [params.unitId]: { [params.subUnitId]: params.formulaMap } };
this._otherFormulaManagerService.batchRegister(config);
} else if (command.id === RemoveOtherFormulaMutation.id) {
const params = command.params as IOtherFormulaManagerSearchParam;
const params = command.params as IRemoveOtherFormulaMutationParams;
if (params == null) {
return;
}

this._otherFormulaManagerService.remove(params);
const obj: Record<string, true> = {};
params.formulaIdList.forEach((id) => obj[id] = true);
const config = { [params.unitId]: { [params.subUnitId]: obj } };
this._otherFormulaManagerService.batchRemove(config);
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('Test indirect', () => {
dirtyRanges: [],
dirtyNameMap: {},
dirtyUnitFeatureMap: {},
dirtyUnitOtherFormulaMap: {},
excludedCell: {},
allUnitData: {
[testBed.unitId]: testBed.sheetData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,18 @@ export class FormulaDependencyGenerator extends Disposable {
}
}

/**
* Specify a specific other formula for flagging a functionality as dirty.
*/
const formulaId = tree.formulaId;
if (formulaId != null) {
const otherFormulaMap = this._currentConfigService.getDirtyUnitOtherFormulaMap();
const state = otherFormulaMap?.[unitId]?.[subUnitId]?.[formulaId];
if (state != null) {
return true;
}
}

const excludedCell = this._currentConfigService.getExcludedRange()?.[unitId]?.[subUnitId];

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ describe('Test nested functions', () => {
dirtyRanges: [],
dirtyNameMap: {},
dirtyUnitFeatureMap: {},
dirtyUnitOtherFormulaMap: {},
excludedCell: {},
allUnitData: {
[testBed.unitId]: testBed.sheetData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ describe('Test isref function', () => {
allUnitData: {
[testBed.unitId]: testBed.sheetData,
},
dirtyUnitOtherFormulaMap: {},
});

const sheetItem = testBed.sheetData[testBed.sheetId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('Test column', () => {
allUnitData: {
[testBed.unitId]: testBed.sheetData,
},
dirtyUnitOtherFormulaMap: {},
});

const sheetItem = testBed.sheetData[testBed.sheetId];
Expand Down
Loading

0 comments on commit 50edd34

Please sign in to comment.