Skip to content

Commit

Permalink
fix(sheets-data-validation): data validation event trigger before dat…
Browse files Browse the repository at this point in the history
…a applied (#3498)
  • Loading branch information
weird94 committed Sep 20, 2024
1 parent 7b89f27 commit c4601a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 9 additions & 5 deletions packages/data-validation/src/models/data-validation-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,28 @@ export class DataValidationModel extends Disposable {
if (oldRule) {
return;
}
this._ruleChange$.next({

return {
rule,
type: 'add',
unitId,
subUnitId,
source,
});
} as const;
}

addRule(unitId: string, subUnitId: string, rule: IDataValidationRule | IDataValidationRule[], source: DataValidationChangeSource, index?: number) {
try {
const subUnitMap = this._ensureMap(unitId, subUnitId);
const rules = Array.isArray(rule) ? rule : [rule];
rules.forEach((item) => {
this._addRuleSideEffect(unitId, subUnitId, item, source);
});
const effects = rules.map((item) => this._addRuleSideEffect(unitId, subUnitId, item, source));

this._addSubUnitRule(subUnitMap, rule, index);
effects.forEach((effect) => {
if (effect) {
this._ruleChange$.next(effect);
}
});
} catch (error) {
this._logService.error(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class DocThreadCommentSelectionController extends Disposable {
const doc = this._univerInstanceService.getUnit<DocumentDataModel>(activeComment.unitId);
if (doc) {
const backScrollController = this._renderManagerService.getRenderById(activeComment.unitId)?.with(DocBackScrollRenderController);
const customRange = doc.getCustomRanges()?.find((range) => range.rangeId === activeComment.commentId);
const customRange = doc.getBody()?.customDecorations?.find((range) => range.id === activeComment.commentId);
if (customRange && backScrollController) {
backScrollController.scrollToRange({
startOffset: customRange.startIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ export class SheetDataValidationModel extends Disposable {
unitMap = new Map();
this._ruleMatrixMap.set(unitId, unitMap);
}
const worksheet = workbook.getSheetBySheetId(subUnitId);
if (!worksheet) {
throw new Error(`worksheet not found, unitId: ${unitId}, subUnitId: ${subUnitId}`);
}

let matrix = unitMap.get(subUnitId);
if (!matrix) {
const worksheet = workbook.getSheetBySheetId(subUnitId);
if (!worksheet) {
throw new Error(`worksheet not found, unitId: ${unitId}, subUnitId: ${subUnitId}`);
}
matrix = new RuleMatrix(new Map(), worksheet);
unitMap.set(subUnitId, matrix);
}
Expand Down

0 comments on commit c4601a0

Please sign in to comment.