-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Datavalidation: coreView plugin should not dispatch
See #5070 - CoreView plugins replay remote revisions and should not take the risk to dispatch during the replay. The code that was assigning arbitrary default values to the cells of a boolean datavalidation has been moved to a UI feature plugin, hence avoiding the problem raised in PR #5070. Task: 4241141
- Loading branch information
Showing
4 changed files
with
82 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getCellPositionsInRanges, isBoolean } from "../../helpers"; | ||
import { CellValueType, Command, isMatrix } from "../../types/index"; | ||
import { UIPlugin } from "../ui_plugin"; | ||
|
||
export class DataValidationInsertionPlugin extends UIPlugin { | ||
handle(cmd: Command) { | ||
switch (cmd.type) { | ||
case "ADD_DATA_VALIDATION_RULE": | ||
if (cmd.rule.criterion.type === "isBoolean") { | ||
const ranges = cmd.ranges.map((range) => this.getters.getRangeFromRangeData(range)); | ||
for (const position of getCellPositionsInRanges(ranges)) { | ||
const cell = this.getters.getCell(position); | ||
const evaluatedCell = this.getters.getEvaluatedCell(position); | ||
|
||
if (!cell?.content) { | ||
this.dispatch("UPDATE_CELL", { ...position, content: "FALSE" }); | ||
// In this case, a cell has been updated in the core plugin but | ||
// not yet evaluated. This can occur after a paste operation. | ||
} else if (cell?.content && evaluatedCell.type === CellValueType.empty) { | ||
let value: string | undefined; | ||
if (cell.content.startsWith("=")) { | ||
const result = this.getters.evaluateFormula(position.sheetId, cell.content); | ||
value = (isMatrix(result) ? result[0][0] : result)?.toString(); | ||
} else { | ||
value = cell.content; | ||
} | ||
if (!value || !isBoolean(value)) { | ||
this.dispatch("UPDATE_CELL", { ...position, content: "FALSE" }); | ||
} | ||
} else if (evaluatedCell.type !== CellValueType.boolean) { | ||
this.dispatch("UPDATE_CELL", { ...position, content: "FALSE" }); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters