Skip to content

Commit 73c46b1

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. closes #7476 Task: 5059484 X-original-commit: f76210a Signed-off-by: Vincent Schippefilt (vsc) <[email protected]> Signed-off-by: Rémi Rahir (rar) <[email protected]>
1 parent 9ca0c4c commit 73c46b1

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 } from "../../../src/constants";
67
import { toHex, toZone } from "../../../src/helpers";
@@ -1412,6 +1413,29 @@ describe("charts", () => {
14121413
]);
14131414
});
14141415

1416+
test("Deleting the second chart after selecting it closes the side panel", async () => {
1417+
createTestChart("basicChart", chartId);
1418+
createTestChart("basicChart", "secondChartId");
1419+
await mountSpreadsheet();
1420+
await openChartConfigSidePanel(model, env, chartId);
1421+
const store = env.getStore(SidePanelStore);
1422+
const sheetId = model.getters.getActiveSheetId();
1423+
1424+
const figures = model.getters.getFigures(sheetId);
1425+
expect(store.panelProps.figureId).toBe(figures[0].id);
1426+
expect(fixture.querySelector(".o-sidePanel")).not.toBeNull();
1427+
1428+
model.dispatch("SELECT_FIGURE", { id: figures[1].id });
1429+
await nextTick();
1430+
expect(store.panelProps.figureId).toBe(figures[1].id);
1431+
expect(fixture.querySelector(".o-sidePanel")).not.toBeNull();
1432+
1433+
model.dispatch("DELETE_FIGURE", { sheetId, id: figures[1].id });
1434+
await nextTick();
1435+
expect(store.isOpen).toBeFalsy();
1436+
expect(fixture.querySelector(".o-sidePanel")).toBeNull();
1437+
});
1438+
14151439
describe("Scorecard specific tests", () => {
14161440
test("can edit chart baseline colors", async () => {
14171441
createTestChart("scorecard");

0 commit comments

Comments
 (0)