Skip to content

Commit dad9584

Browse files
committed
[FIX] standalone_composer: wrong composer content on start edition
When we have the pivot side panel open and that someone in collaborative updates a calculated measure formula, the composer correctly shows the updated formula. But if the composer is focused, it will show the previous formula instead of the updated one. This happens since 53f7692. In this commit, we update the composer store `this.editionMode` before calling `getComposerContent`, which make sense. But the `getComposerContent` implementation of the standalone composer store does not return the updated formula if `this.editionMode` is not inactive. With this commit, `getComposerContent` of the standalone composer always returns the updated formula and never the current store state. I don't think it should cause any issues, since `getComposerContent` is only called when displaying the inactive composer content, and when starting the edition. In both cases, we want to show the updated formula. closes #8102 Task: 6022743 X-original-commit: 4052315 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
1 parent 04d519e commit dad9584

File tree

2 files changed

+45
-16
lines changed

2 files changed

+45
-16
lines changed

src/components/composer/standalone_composer/standalone_composer_store.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,19 @@ export class StandaloneComposerStore extends AbstractComposerStore {
4747
}
4848

4949
protected getComposerContent() {
50-
let content = this._currentContent;
51-
if (this.editionMode === "inactive") {
52-
// References in the content might not be linked to the current active sheet
53-
// We here force the sheet name prefix for all references that are not in
54-
// the current active sheet
55-
const defaultRangeSheetId = this.args().defaultRangeSheetId;
56-
content = rangeTokenize(this.args().content)
57-
.map((token) => {
58-
if (token.type === "REFERENCE") {
59-
const range = this.getters.getRangeFromSheetXC(defaultRangeSheetId, token.value);
60-
return this.getters.getRangeString(range, this.getters.getActiveSheetId());
61-
}
62-
return token.value;
63-
})
64-
.join("");
65-
}
50+
// References in the content might not be linked to the current active sheet
51+
// We here force the sheet name prefix for all references that are not in
52+
// the current active sheet
53+
const defaultRangeSheetId = this.args().defaultRangeSheetId;
54+
const content = rangeTokenize(this.args().content)
55+
.map((token) => {
56+
if (token.type === "REFERENCE") {
57+
const range = this.getters.getRangeFromSheetXC(defaultRangeSheetId, token.value);
58+
return this.getters.getRangeString(range, this.getters.getActiveSheetId());
59+
}
60+
return token.value;
61+
})
62+
.join("");
6663
return { text: localizeContent(content, this.getters.getLocale()) };
6764
}
6865

tests/pivots/pivot_side_panel.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,38 @@ describe("Pivot side panel", () => {
212212
expect(definition.collapsedDomains?.ROW).toHaveLength(0);
213213
});
214214

215+
test("External update of the calulated formula impacts the side panel", async () => {
216+
// prettier-ignore
217+
setGrid(model, {
218+
A1: "Partner", B1: "Amount",
219+
A2: "Alice", B2: "10",
220+
A5: "=PIVOT(1)"
221+
});
222+
223+
const sheetId = model.getters.getActiveSheetId();
224+
const calculatedMeasure = {
225+
id: "calc",
226+
fieldName: "calc",
227+
aggregator: "sum",
228+
computedBy: { formula: "=25", sheetId },
229+
};
230+
updatePivot(model, "1", { measures: [calculatedMeasure] });
231+
env.openSidePanel("PivotSidePanel", { pivotId: "1" });
232+
await nextTick();
233+
234+
expect(".o-sidePanel .o-composer").toHaveText("=25");
235+
236+
updatePivot(model, "1", {
237+
measures: [{ ...calculatedMeasure, computedBy: { formula: "=50", sheetId } }],
238+
});
239+
await nextTick();
240+
expect(".o-sidePanel .o-composer").toHaveText("=50");
241+
242+
// Focus the composer. It should stay the same value
243+
await simulateClick(".o-sidePanel .o-composer");
244+
expect(".o-sidePanel .o-composer").toHaveText("=50");
245+
});
246+
215247
test("Collapsed dimension with correct field but wrong value is not filtered out at pivot update", async () => {
216248
// Note: we don't want to remove those, because different users may have different value,
217249
// and a domain might be valid for one user and not for another

0 commit comments

Comments
 (0)