Skip to content

Commit e4b3ebe

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 #7480 Task: 5059484 X-original-commit: e8d8bcd Signed-off-by: Vincent Schippefilt (vsc) <vsc@odoo.com> Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
1 parent 62dfe8a commit e4b3ebe

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

src/components/side_panel/side_panel/side_panel_store.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const COLLAPSED_SIDE_PANEL_SIZE = 45;
2626
export const MIN_SHEET_VIEW_WIDTH = 150;
2727

2828
interface PanelInfo {
29-
initialPanelProps: SidePanelComponentProps;
29+
currentPanelProps: SidePanelComponentProps;
3030
componentTag: string;
3131
size: number;
3232
isCollapsed?: boolean;
@@ -87,6 +87,7 @@ export class SidePanelStore extends SpreadsheetStore {
8787
private getPanelProps(panelInfo: PanelInfo): SidePanelComponentProps {
8888
const state = this.computeState(panelInfo);
8989
if (state.isOpen) {
90+
panelInfo.currentPanelProps = state.props ?? panelInfo.currentPanelProps;
9091
return state.props ?? {};
9192
}
9293
return {};
@@ -100,12 +101,12 @@ export class SidePanelStore extends SpreadsheetStore {
100101
return undefined;
101102
}
102103

103-
open(componentTag: string, initialPanelProps: SidePanelComponentProps = {}) {
104+
open(componentTag: string, currentPanelProps: SidePanelComponentProps = {}) {
104105
if (this.screenWidthStore.isSmall) {
105106
return;
106107
}
107108

108-
const newPanelInfo = { initialPanelProps, componentTag, size: DEFAULT_SIDE_PANEL_SIZE };
109+
const newPanelInfo = { currentPanelProps, componentTag, size: DEFAULT_SIDE_PANEL_SIZE };
109110
const state = this.computeState(newPanelInfo);
110111
if (!state.isOpen) {
111112
return;
@@ -138,9 +139,9 @@ export class SidePanelStore extends SpreadsheetStore {
138139
replace(
139140
componentTag: string,
140141
currentPanelKey: string,
141-
initialPanelProps: SidePanelComponentProps = {}
142+
currentPanelProps: SidePanelComponentProps = {}
142143
) {
143-
const newPanelInfo = { initialPanelProps, componentTag, size: DEFAULT_SIDE_PANEL_SIZE };
144+
const newPanelInfo = { currentPanelProps, componentTag, size: DEFAULT_SIDE_PANEL_SIZE };
144145
const state = this.computeState(newPanelInfo);
145146
if (!state.isOpen) {
146147
return;
@@ -178,10 +179,10 @@ export class SidePanelStore extends SpreadsheetStore {
178179
const currentPanel = this[panel];
179180

180181
if (currentPanel && newPanel.componentTag !== currentPanel.componentTag) {
181-
currentPanel.initialPanelProps?.onCloseSidePanel?.();
182+
currentPanel.currentPanelProps?.onCloseSidePanel?.();
182183
}
183184
this[panel] = {
184-
initialPanelProps: state.props ?? {},
185+
currentPanelProps: state.props ?? {},
185186
componentTag: newPanel.componentTag,
186187
size: currentPanel?.size || DEFAULT_SIDE_PANEL_SIZE,
187188
isCollapsed: currentPanel?.isCollapsed || false,
@@ -204,17 +205,17 @@ export class SidePanelStore extends SpreadsheetStore {
204205
close() {
205206
if (this.mainPanel?.isPinned) {
206207
if (this.secondaryPanel) {
207-
this.secondaryPanel.initialPanelProps.onCloseSidePanel?.();
208+
this.secondaryPanel.currentPanelProps.onCloseSidePanel?.();
208209
this.secondaryPanel = undefined;
209210
}
210211
return;
211212
}
212-
this.mainPanel?.initialPanelProps.onCloseSidePanel?.();
213+
this.mainPanel?.currentPanelProps.onCloseSidePanel?.();
213214
this.mainPanel = undefined;
214215
}
215216

216217
closeMainPanel() {
217-
this.mainPanel?.initialPanelProps.onCloseSidePanel?.();
218+
this.mainPanel?.currentPanelProps.onCloseSidePanel?.();
218219
this.mainPanel = this.secondaryPanel || undefined;
219220
this.secondaryPanel = undefined;
220221
}
@@ -252,7 +253,7 @@ export class SidePanelStore extends SpreadsheetStore {
252253
}
253254
this.mainPanel.isPinned = !this.mainPanel.isPinned;
254255
if (!this.mainPanel.isPinned && this.secondaryPanel) {
255-
this.secondaryPanel?.initialPanelProps.onCloseSidePanel?.();
256+
this.secondaryPanel?.currentPanelProps.onCloseSidePanel?.();
256257
this.mainPanel = this.secondaryPanel;
257258
this.secondaryPanel = undefined;
258259
}
@@ -272,7 +273,10 @@ export class SidePanelStore extends SpreadsheetStore {
272273
}
273274
}
274275

275-
private computeState({ componentTag, initialPanelProps }: PanelInfo): SidePanelState {
276+
private computeState({
277+
componentTag,
278+
currentPanelProps: initialPanelProps,
279+
}: PanelInfo): SidePanelState {
276280
const customComputeState = sidePanelRegistry.get(componentTag).computeState;
277281
const state: SidePanelState = customComputeState
278282
? customComputeState(this.getters, initialPanelProps)
@@ -283,7 +287,7 @@ export class SidePanelStore extends SpreadsheetStore {
283287
changeSpreadsheetWidth(width: number) {
284288
this.availableWidth = width - MIN_SHEET_VIEW_WIDTH;
285289
if (this.secondaryPanel && width - this.totalPanelSize < MIN_SHEET_VIEW_WIDTH) {
286-
this.secondaryPanel?.initialPanelProps.onCloseSidePanel?.();
290+
this.secondaryPanel?.currentPanelProps.onCloseSidePanel?.();
287291
this.secondaryPanel = undefined;
288292
}
289293
if (this.mainPanel && width - this.totalPanelSize < MIN_SHEET_VIEW_WIDTH) {

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 {
67
BACKGROUND_CHART_COLOR,
@@ -1478,6 +1479,29 @@ describe("charts", () => {
14781479
]);
14791480
});
14801481

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

0 commit comments

Comments
 (0)