Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sheet): defined name update name #1917

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/engine-formula/src/engine/analysis/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export class AstTreeBuilder extends Disposable {
const node = this._parse(lexerNode, astNode);

/**
* If the lexer node has defined names, it means that the current formula contains a reference to the defined name.
* If the lexer node has defined names,
* it means that the current formula contains a reference to the defined name.
*/
if (lexerNode.hasDefinedNames()) {
node?.setDefinedNames(lexerNode.getDefinedNames());
Expand Down Expand Up @@ -184,6 +185,7 @@ export class AstTreeBuilder extends Disposable {
return newLambdaNode;
}

// eslint-disable-next-line max-lines-per-function, complexity
private _parse(lexerNode: LexerNode, parent: BaseAstNode): Nullable<BaseAstNode> {
const children = lexerNode.getChildren();
const childrenCount = children.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
IRemoveColMutationParams,
IRemoveRowsMutationParams,
IRemoveSheetMutationParams,
ISetDefinedNameCommandParams,
ISetRangeValuesMutationParams,
} from '@univerjs/sheets';
import {
Expand All @@ -44,6 +45,7 @@ import {
RemoveColMutation,
RemoveRowMutation,
RemoveSheetMutation,
SetDefinedNameCommand,
SetRangeValuesMutation,
SetStyleCommand,
} from '@univerjs/sheets';
Expand Down Expand Up @@ -100,6 +102,27 @@ export class ActiveDirtyController extends Disposable {
},
});

this._initialMove();

this._initialRowAndColumn();

this._initialSheet();

this._initialDefinedName();

/**
* Changing the name of a sheet triggers an adjustment of the formula references, but does not trigger formula calculation; therefore, this logic has been removed.
*/
// this._activeDirtyManagerService.register(SetWorksheetNameMutation.id, {
// commandId: SetWorksheetNameMutation.id,
// getDirtyData: (command: ICommandInfo) => {
// const params = command.params as ISetWorksheetNameMutationParams;
// return { dirtyNameMap: this._getRemoveSheetMutation(params, params.name) };
// },
// });
}

private _initialMove() {
this._activeDirtyManagerService.register(MoveRangeMutation.id, {
commandId: MoveRangeMutation.id,
getDirtyData: (command: ICommandInfo) => {
Expand Down Expand Up @@ -129,7 +152,9 @@ export class ActiveDirtyController extends Disposable {
};
},
});
}

private _initialRowAndColumn() {
this._activeDirtyManagerService.register(RemoveRowMutation.id, {
commandId: RemoveRowMutation.id,
getDirtyData: (command: ICommandInfo) => {
Expand All @@ -149,7 +174,10 @@ export class ActiveDirtyController extends Disposable {
};
},
});
}


private _initialSheet() {
this._activeDirtyManagerService.register(RemoveSheetMutation.id, {
commandId: RemoveSheetMutation.id,
getDirtyData: (command: ICommandInfo) => {
Expand All @@ -165,7 +193,9 @@ export class ActiveDirtyController extends Disposable {
return { dirtyNameMap: this._getInsertSheetMutation(params) };
},
});
}

private _initialDefinedName() {
this._activeDirtyManagerService.register(SetDefinedNameMutation.id, {
commandId: SetDefinedNameMutation.id,
getDirtyData: (command: ICommandInfo) => {
Expand All @@ -182,16 +212,16 @@ export class ActiveDirtyController extends Disposable {
},
});

/**
* Changing the name of a sheet triggers an adjustment of the formula references, but does not trigger formula calculation; therefore, this logic has been removed.
*/
// this._activeDirtyManagerService.register(SetWorksheetNameMutation.id, {
// commandId: SetWorksheetNameMutation.id,
// getDirtyData: (command: ICommandInfo) => {
// const params = command.params as ISetWorksheetNameMutationParams;
// return { dirtyNameMap: this._getRemoveSheetMutation(params, params.name) };
// },
// });
this._activeDirtyManagerService.register(SetDefinedNameCommand.id, {
commandId: SetDefinedNameCommand.id,
getDirtyData: (command: ICommandInfo) => {
const params = command.params as ISetDefinedNameCommandParams;
const { oldDefinedName, newDefinedName } = params;
return { dirtyDefinedNameMap: this._getDefinedNameMutation({ ...newDefinedName, name: oldDefinedName.name }) };

// return { dirtyDefinedNameMap: this._getDefinedNameMutation(params) };
},
});
}

private _getDefinedNameMutation(definedName: ISetDefinedNameMutationParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const DefinedNameContainer = () => {
} else {
const oldDefinedName = definedNamesService.getValueById(unitId, id);
const newDefinedName = { id, unitId, name, formulaOrRefString, comment, localSheetId, hidden };
commandService.executeCommand(SetDefinedNameCommand.id, { unitId, oldDefinedName, newDefinedName });
commandService.executeCommand(SetDefinedNameCommand.id, { unitId, oldDefinedName: { ...oldDefinedName, unitId }, newDefinedName });
}
setEditState(false);
setEditorKey(null);
Expand Down
Loading