Skip to content

Commit 29e6449

Browse files
committed
[FIX] SidePanel: reset initial props on Model change
Currently, we store the initial props which the sidepanel was open with. This specifically occurs for charts sidepanel where we want the state to update when we select another chart BUT we also want it to stay open when clicking the grid (hence - no active chart left). However the moment we click on another chart than the first one, then it is supposed to become the new "default" chart. How to reproduce: - open the sidepanel of the first chart - select the second chart - delete the second chart => the sidepanel is still open and falls back on the first chart instead of closing. Task: 5059484 X-original-commit: f76210a
1 parent f31a752 commit 29e6449

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/components/side_panel/side_panel/side_panel_store.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ export const MIN_SHEET_VIEW_WIDTH = 150;
2323

2424
export class SidePanelStore extends SpreadsheetStore {
2525
mutators = ["open", "toggle", "close", "changePanelSize", "resetPanelSize"] as const;
26-
initialPanelProps: SidePanelProps = {};
26+
currentPanelProps: SidePanelProps = {};
2727
componentTag: string = "";
2828
panelSize = DEFAULT_SIDE_PANEL_SIZE;
2929

3030
get isOpen() {
3131
if (!this.componentTag) {
3232
return false;
3333
}
34-
return this.computeState(this.componentTag, this.initialPanelProps).isOpen;
34+
return this.computeState(this.componentTag, this.currentPanelProps).isOpen;
3535
}
3636

3737
get panelProps(): SidePanelProps {
38-
const state = this.computeState(this.componentTag, this.initialPanelProps);
38+
const state = this.computeState(this.componentTag, this.currentPanelProps);
3939
if (state.isOpen) {
4040
return state.props ?? {};
4141
}
4242
return {};
4343
}
4444

4545
get panelKey(): string | undefined {
46-
const state = this.computeState(this.componentTag, this.initialPanelProps);
46+
const state = this.computeState(this.componentTag, this.currentPanelProps);
4747
if (state.isOpen) {
4848
return state.key;
4949
}
@@ -56,10 +56,10 @@ export class SidePanelStore extends SpreadsheetStore {
5656
return;
5757
}
5858
if (this.isOpen && componentTag !== this.componentTag) {
59-
this.initialPanelProps?.onCloseSidePanel?.();
59+
this.currentPanelProps?.onCloseSidePanel?.();
6060
}
6161
this.componentTag = componentTag;
62-
this.initialPanelProps = state.props ?? {};
62+
this.currentPanelProps = state.props ?? {};
6363
}
6464

6565
toggle(componentTag: string, panelProps: SidePanelProps) {
@@ -71,8 +71,8 @@ export class SidePanelStore extends SpreadsheetStore {
7171
}
7272

7373
close() {
74-
this.initialPanelProps.onCloseSidePanel?.();
75-
this.initialPanelProps = {};
74+
this.currentPanelProps.onCloseSidePanel?.();
75+
this.currentPanelProps = {};
7676
this.componentTag = "";
7777
}
7878

@@ -98,7 +98,11 @@ export class SidePanelStore extends SpreadsheetStore {
9898
props: panelProps,
9999
};
100100
} else {
101-
return customComputeState(this.getters, panelProps);
101+
const state = customComputeState(this.getters, panelProps);
102+
if (state.isOpen) {
103+
this.currentPanelProps = state.props ?? this.currentPanelProps;
104+
}
105+
return state;
102106
}
103107
}
104108
}

tests/figures/chart/charts_component.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { App } from "@odoo/owl";
22
import { CommandResult, Model, Spreadsheet } from "../../../src";
33
import { ChartPanel } from "../../../src/components/side_panel/chart/main_chart_panel/main_chart_panel";
4+
import { SidePanelStore } from "../../../src/components/side_panel/side_panel/side_panel_store";
45
import { ChartTerms } from "../../../src/components/translations_terms";
56
import { BACKGROUND_CHART_COLOR, DEBOUNCE_TIME } from "../../../src/constants";
67
import { toHex, toZone } from "../../../src/helpers";
@@ -1475,6 +1476,29 @@ describe("charts", () => {
14751476
]);
14761477
});
14771478

1479+
test("Deleting the second chart after selecting it closes the side panel", async () => {
1480+
createTestChart("basicChart", chartId);
1481+
createTestChart("basicChart", "secondChartId");
1482+
await mountSpreadsheet();
1483+
await openChartConfigSidePanel(model, env, chartId);
1484+
const store = env.getStore(SidePanelStore);
1485+
const sheetId = model.getters.getActiveSheetId();
1486+
1487+
const figures = model.getters.getFigures(sheetId);
1488+
expect(store.panelProps.figureId).toBe(figures[0].id);
1489+
expect(fixture.querySelector(".o-sidePanel")).not.toBeNull();
1490+
1491+
model.dispatch("SELECT_FIGURE", { id: figures[1].id });
1492+
await nextTick();
1493+
expect(store.panelProps.figureId).toBe(figures[1].id);
1494+
expect(fixture.querySelector(".o-sidePanel")).not.toBeNull();
1495+
1496+
model.dispatch("DELETE_FIGURE", { sheetId, id: figures[1].id });
1497+
await nextTick();
1498+
expect(store.isOpen).toBeFalsy();
1499+
expect(fixture.querySelector(".o-sidePanel")).toBeNull();
1500+
});
1501+
14781502
describe("Scorecard specific tests", () => {
14791503
test("can edit chart baseline colors", async () => {
14801504
createTestChart("scorecard");

0 commit comments

Comments
 (0)