Skip to content

Commit 5395a3b

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 #7146 Task: 4948201 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent 03fc65a commit 5395a3b

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
@@ -10,6 +10,7 @@ import {
1010
DataValidationRule,
1111
DataValidationRuleData,
1212
SpreadsheetChildEnv,
13+
UID,
1314
} from "../../../../types";
1415
import { css } from "../../../helpers";
1516
import { SelectionInput } from "../../../selection_input/selection_input";
@@ -40,14 +41,15 @@ export class DataValidationEditor extends Component<Props, SpreadsheetChildEnv>
4041
static components = { SelectionInput, SelectMenu };
4142

4243
state = useState<State>({ rule: this.defaultDataValidationRule });
44+
private editingSheetId!: UID;
4345

4446
setup() {
47+
this.editingSheetId = this.env.model.getters.getActiveSheetId();
4548
if (this.props.rule) {
46-
const sheetId = this.env.model.getters.getActiveSheetId();
4749
this.state.rule = {
4850
...this.props.rule,
4951
ranges: this.props.rule.ranges.map((range) =>
50-
this.env.model.getters.getRangeString(range, sheetId)
52+
this.env.model.getters.getRangeString(range, this.editingSheetId)
5153
),
5254
};
5355
this.state.rule.criterion.type = this.props.rule.criterion.type;
@@ -91,17 +93,16 @@ export class DataValidationEditor extends Component<Props, SpreadsheetChildEnv>
9193
const criterion = rule.criterion;
9294
const criterionEvaluator = dataValidationEvaluatorRegistry.get(criterion.type);
9395

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

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
@@ -2,7 +2,12 @@ import { Component, onMounted, onWillUnmount, xml } from "@odoo/owl";
22
import { Model } from "../../src";
33
import { DataValidationPanel } from "../../src/components/side_panel/data_validation/data_validation_panel";
44
import { SpreadsheetChildEnv, UID } from "../../src/types";
5-
import { addDataValidation, updateLocale } from "../test_helpers/commands_helpers";
5+
import {
6+
activateSheet,
7+
addDataValidation,
8+
createSheet,
9+
updateLocale,
10+
} from "../test_helpers/commands_helpers";
611
import { FR_LOCALE } from "../test_helpers/constants";
712
import { click, setInputValueAndTrigger, simulateClick } from "../test_helpers/dom_helper";
813
import { getDataValidationRules, mountComponent, nextTick } from "../test_helpers/helpers";
@@ -202,6 +207,29 @@ describe("data validation sidePanel component", () => {
202207
expect(getDataValidationRules(model, sheetId)).toMatchObject([{ id: "id1" }, { id: "id2" }]);
203208
});
204209

210+
test("DV stays on original sheet when range is selected from another sheet and saved", async () => {
211+
createSheet(model, { sheetId: "sh2" });
212+
213+
await simulateClick(".o-dv-add");
214+
await nextTick();
215+
setInputValueAndTrigger(".o-selection-input input", "A1:A5");
216+
await changeCriterionType("isValueInRange");
217+
218+
const rangeInput = fixture.querySelectorAll<HTMLInputElement>(".o-selection-input input")[1];
219+
activateSheet(model, "sh2");
220+
await setInputValueAndTrigger(rangeInput, "A1:A5");
221+
await simulateClick(".o-dv-save");
222+
223+
expect(getDataValidationRules(model, sheetId)).toEqual([
224+
{
225+
id: expect.any(String),
226+
criterion: { type: "isValueInRange", displayStyle: "arrow", values: ["A1:A5"] },
227+
ranges: ["A1:A5"],
228+
},
229+
]);
230+
expect(getDataValidationRules(model, "sh2")).toHaveLength(0);
231+
});
232+
205233
describe("Locale", () => {
206234
test("Number preview is localized", async () => {
207235
updateLocale(model, FR_LOCALE);

0 commit comments

Comments
 (0)