Skip to content

Commit 331cc7d

Browse files
committed
[FIX] Range: Clean-up of plugins adaptRange
Following the refactoring that allows specific range transformations inside commands, we always provide the sheetId and sheetName to the range providers, which allows to clear some useless code. Task: 4868971 X-original-commit: e031b43 Part-of: #7030 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com> Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent 82a26ff commit 331cc7d

File tree

10 files changed

+16
-32
lines changed

10 files changed

+16
-32
lines changed

src/plugins/core/cell.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,12 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
7272
readonly nextId = 1;
7373
public readonly cells: { [sheetId: string]: { [id: string]: Cell } } = {};
7474

75-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string) {
75+
adaptRanges(applyChange: ApplyRangeChange, sheetId: UID, sheetName: string) {
7676
for (const sheet of Object.keys(this.cells)) {
7777
for (const cell of Object.values(this.cells[sheet] || {})) {
7878
if (cell.isFormula) {
7979
for (const range of cell.compiledFormula.dependencies) {
80-
if (
81-
!sheetId ||
82-
range.sheetId === sheetId ||
83-
(sheetName && range.invalidSheetName === sheetName)
84-
) {
80+
if (range.sheetId === sheetId || range.invalidSheetName === sheetName) {
8581
const change = applyChange(range);
8682
if (change.changeType !== "NONE") {
8783
this.history.update(

src/plugins/core/data_validation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ export class DataValidationPlugin
4141

4242
readonly rules: { [sheet: string]: DataValidationRule[] } = {};
4343

44-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string) {
45-
const sheetIds = sheetId ? [sheetId] : Object.keys(this.rules);
46-
for (const sheetId of sheetIds) {
47-
this.adaptDVRanges(sheetId, applyChange);
48-
}
44+
adaptRanges(applyChange: ApplyRangeChange, sheetId: UID) {
45+
this.adaptDVRanges(sheetId, applyChange);
4946
this.adaptDVFormulas(applyChange);
5047
}
5148

src/plugins/core/figures.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export class FigurePlugin extends CorePlugin<FigureState> implements FigureState
3232
// Command Handling
3333
// ---------------------------------------------------------------------------
3434

35-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID) {
36-
if (!sheetId) {
37-
return;
38-
}
35+
adaptRanges(applyChange: ApplyRangeChange, sheetId: UID) {
3936
for (const figure of this.getFigures(sheetId)) {
4037
const change = applyChange(
4138
this.getters.getRangeFromZone(sheetId, {

src/plugins/core/merge.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,8 @@ export class MergePlugin extends CorePlugin<MergeState> implements MergeState {
123123
}
124124
}
125125

126-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string) {
127-
const sheetIds = sheetId ? [sheetId] : Object.keys(this.merges);
128-
for (const sheetId of sheetIds) {
129-
this.applyRangeChangeOnSheet(sheetId, applyChange);
130-
}
126+
adaptRanges(applyChange: ApplyRangeChange, sheetId: UID) {
127+
this.applyRangeChangeOnSheet(sheetId, applyChange);
131128
}
132129

133130
// ---------------------------------------------------------------------------

src/plugins/core/pivot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class PivotCorePlugin extends CorePlugin<CoreState> implements CoreState
139139
}
140140
}
141141

142-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string) {
142+
adaptRanges(applyChange: ApplyRangeChange) {
143143
for (const sheetId in this.compiledMeasureFormulas) {
144144
for (const formulaString in this.compiledMeasureFormulas[sheetId]) {
145145
const compiledFormula = this.compiledMeasureFormulas[sheetId][formulaString];

src/plugins/core/range.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class RangeAdapter implements CommandHandler<CoreCommand> {
9999
};
100100
}
101101

102-
private executeOnAllRanges(adaptRange: ApplyRangeChange, sheetId?: UID, sheetName?: string) {
102+
private executeOnAllRanges(adaptRange: ApplyRangeChange, sheetId: UID, sheetName: string) {
103103
const func = this.verifyRangeRemoved(adaptRange);
104104
for (const provider of this.providers) {
105105
provider(func, sheetId, sheetName);

src/plugins/core/tables.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,9 @@ export class TablePlugin extends CorePlugin<TableState> implements TableState {
5151
readonly tables: Record<UID, Record<TableId, CoreTable | undefined>> = {};
5252
readonly nextTableId: number = 1;
5353

54-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string) {
55-
const sheetIds = sheetId ? [sheetId] : this.getters.getSheetIds();
56-
for (const sheetId of sheetIds) {
57-
for (const table of this.getCoreTables(sheetId)) {
58-
this.applyRangeChangeOnTable(sheetId, table, applyChange);
59-
}
54+
adaptRanges(applyChange: ApplyRangeChange, sheetId: UID) {
55+
for (const table of this.getCoreTables(sheetId)) {
56+
this.applyRangeChangeOnTable(sheetId, table, applyChange);
6057
}
6158
}
6259

src/plugins/core_plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class CorePlugin<State = any>
6666
* @param applyChange a function that, when called, will adapt the range according to the change on the grid
6767
* @param sheetId an optional sheetId to adapt either range of that sheet specifically, or ranges pointing to that sheet
6868
*/
69-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string): void {}
69+
adaptRanges(applyChange: ApplyRangeChange, sheetId: UID, sheetName: string): void {}
7070

7171
/**
7272
* Implement this method to clean unused external resources, such as images

src/types/misc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ export type Dimension = "COL" | "ROW";
304304
export type ConsecutiveIndexes = HeaderIndex[];
305305

306306
export interface RangeProvider {
307-
adaptRanges: (applyChange: ApplyRangeChange, sheetId?: UID, sheetName?: string) => void;
307+
adaptRanges: (applyChange: ApplyRangeChange, sheetId: UID, sheetName: string) => void;
308308
}
309309

310310
export type Validation<T> = (toValidate: T) => CommandResult | CommandResult[];

tests/range_plugin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { CorePlugin, coreTypes, Model } from "../src";
22
import { duplicateRangeInDuplicatedSheet } from "../src/helpers";
33
import { corePluginRegistry } from "../src/plugins";
4-
import { ApplyRangeChange, Command, Range, UID } from "../src/types";
4+
import { ApplyRangeChange, Command, Range } from "../src/types";
55
import { CellErrorType } from "../src/types/errors";
66
import {
77
addColumns,
@@ -39,7 +39,7 @@ class PluginTestRange extends CorePlugin {
3939

4040
ranges: Range[] = [];
4141

42-
adaptRanges(applyChange: ApplyRangeChange, sheetId?: UID) {
42+
adaptRanges(applyChange: ApplyRangeChange) {
4343
for (let i = 0; i < this.ranges.length; i++) {
4444
const range = this.ranges[i];
4545
const change = applyChange(range);

0 commit comments

Comments
 (0)