Skip to content

Commit fb62e04

Browse files
committed
[FIX] data_validation: selecting range from another sheet
Steps to reproduce: - Create a new sheet (Sheet2). - On Sheet1, open the Data Validation side panel. - Add a DV with type "isValueInRange". - Click on the selection input to select the range. - Navigate to Sheet2 and select the range. - Click on Save without confirming the ranges. Before this commit: - The DV was created on Sheet2 instead of remaining on Sheet1. After this commit: - The DV is correctly created on the original sheet (Sheet1). closes #7323 Task: 4948201 X-original-commit: be6bf8c Signed-off-by: Dhrutik Patel (dhrp) <dhrp@odoo.com> Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent 7e8bd49 commit fb62e04

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

src/components/side_panel/data_validation/dv_editor/dv_editor.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
DataValidationRule,
1212
DataValidationRuleData,
1313
SpreadsheetChildEnv,
14+
UID,
1415
} from "../../../../types";
1516
import { SelectionInput } from "../../../selection_input/selection_input";
1617
import { DVTerms } from "../../../translations_terms";
@@ -43,14 +44,15 @@ export class DataValidationEditor extends Component<Props, SpreadsheetChildEnv>
4344
};
4445

4546
state = useState<State>({ rule: this.defaultDataValidationRule, errors: [] });
47+
private editingSheetId!: UID;
4648

4749
setup() {
50+
this.editingSheetId = this.env.model.getters.getActiveSheetId();
4851
if (this.props.rule) {
49-
const sheetId = this.env.model.getters.getActiveSheetId();
5052
this.state.rule = {
5153
...this.props.rule,
5254
ranges: this.props.rule.ranges.map((range) =>
53-
this.env.model.getters.getRangeString(range, sheetId)
55+
this.env.model.getters.getRangeString(range, this.editingSheetId)
5456
),
5557
};
5658
this.state.rule.criterion.type = this.props.rule.criterion.type;
@@ -92,17 +94,16 @@ export class DataValidationEditor extends Component<Props, SpreadsheetChildEnv>
9294
const criterion = rule.criterion;
9395
const criterionEvaluator = dataValidationEvaluatorRegistry.get(criterion.type);
9496

95-
const sheetId = this.env.model.getters.getActiveSheetId();
9697
const values = criterion.values
9798
.slice(0, criterionEvaluator.numberOfValues(criterion))
9899
.map((value) => value?.trim())
99100
.filter((value) => value !== "" && value !== undefined)
100101
.map((value) => canonicalizeContent(value, locale));
101102
rule.criterion = { ...criterion, values };
102103
return {
103-
sheetId,
104+
sheetId: this.editingSheetId,
104105
ranges: this.state.rule.ranges.map((xc) =>
105-
this.env.model.getters.getRangeDataFromXc(sheetId, xc)
106+
this.env.model.getters.getRangeDataFromXc(this.editingSheetId, xc)
106107
),
107108
rule,
108109
};

tests/data_validation/data_validation_generics_side_panel_component.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { Model } from "../../src";
22
import { DataValidationPanel } from "../../src/components/side_panel/data_validation/data_validation_panel";
33
import { UID } from "../../src/types";
4-
import { addDataValidation, updateLocale } from "../test_helpers/commands_helpers";
4+
import {
5+
activateSheet,
6+
addDataValidation,
7+
createSheet,
8+
updateLocale,
9+
} from "../test_helpers/commands_helpers";
510
import { FR_LOCALE } from "../test_helpers/constants";
611
import { click, setInputValueAndTrigger, simulateClick } from "../test_helpers/dom_helper";
712
import {
@@ -270,6 +275,29 @@ describe("data validation sidePanel component", () => {
270275
expect(getDataValidationRules(model, sheetId)).toMatchObject([{ id: "id1" }, { id: "id2" }]);
271276
});
272277

278+
test("DV stays on original sheet when range is selected from another sheet and saved", async () => {
279+
createSheet(model, { sheetId: "sh2" });
280+
281+
await simulateClick(".o-dv-add");
282+
await nextTick();
283+
setInputValueAndTrigger(".o-selection-input input", "A1:A5");
284+
await changeCriterionType("isValueInRange");
285+
286+
const rangeInput = fixture.querySelectorAll<HTMLInputElement>(".o-selection-input input")[1];
287+
activateSheet(model, "sh2");
288+
await setInputValueAndTrigger(rangeInput, "A1:A5");
289+
await simulateClick(".o-dv-save");
290+
291+
expect(getDataValidationRules(model, sheetId)).toEqual([
292+
{
293+
id: expect.any(String),
294+
criterion: { type: "isValueInRange", displayStyle: "arrow", values: ["A1:A5"] },
295+
ranges: ["A1:A5"],
296+
},
297+
]);
298+
expect(getDataValidationRules(model, "sh2")).toHaveLength(0);
299+
});
300+
273301
describe("Locale", () => {
274302
test("Number preview is localized", async () => {
275303
updateLocale(model, FR_LOCALE);

0 commit comments

Comments
 (0)