From 28a954997fcb7eb0c096d77b3baad94d50d750ef Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Tue, 23 Jan 2024 11:17:51 +0100 Subject: [PATCH] [FIX] spreadsheet_dashboard: prevent crash on chart double click MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce ================== - Use a mobile viewport / device (small window) - Go to Dashboard - Double click on a chart => `this.env.openSidePanel is not a function` Cause of the issue ================== On mobile, the MobileFigureContainer is used instead of the Spreadsheet component. The both use `useSubEnv` but the mobile one was missing the openSidePanel function. Solution ======== Add an empty `openSidePanel` function that does nothing. opw-3677552 closes odoo/odoo#150702 X-original-commit: 990452ad985b1515ba565ff1fe8c6bbaa14fb031 Signed-off-by: Lucas Lefèvre (lul) --- .../mobile_figure_container.js | 1 + .../mobile/mobile_dashboard_action_test.js | 51 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/mobile_figure_container/mobile_figure_container.js b/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/mobile_figure_container/mobile_figure_container.js index 3ec13b10dfb..f15a329dff9 100644 --- a/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/mobile_figure_container/mobile_figure_container.js +++ b/addons/spreadsheet_dashboard/static/src/bundle/dashboard_action/mobile_figure_container/mobile_figure_container.js @@ -11,6 +11,7 @@ export class MobileFigureContainer extends Component { useSubEnv({ model: this.props.spreadsheetModel, isDashboard: () => this.props.spreadsheetModel.getters.isDashboard(), + openSidePanel: () => {}, }); } diff --git a/addons/spreadsheet_dashboard/static/tests/mobile/mobile_dashboard_action_test.js b/addons/spreadsheet_dashboard/static/tests/mobile/mobile_dashboard_action_test.js index 0c5923d4690..08062b3a2d0 100644 --- a/addons/spreadsheet_dashboard/static/tests/mobile/mobile_dashboard_action_test.js +++ b/addons/spreadsheet_dashboard/static/tests/mobile/mobile_dashboard_action_test.js @@ -1,6 +1,6 @@ /** @odoo-module */ -import { click, getFixture } from "@web/../tests/helpers/utils"; +import { click, getFixture, triggerEvent } from "@web/../tests/helpers/utils"; import { createSpreadsheetDashboard } from "../utils/dashboard_action"; import { getDashboardServerData } from "../utils/data"; @@ -77,6 +77,55 @@ QUnit.test("displays figures in first sheet", async (assert) => { assert.containsOnce(fixture, ".o-chart-container"); }); +QUnit.test("double clicking on a figure doesn't open the side panel", async (assert) => { + const figure = { + tag: "chart", + height: 500, + width: 500, + x: 100, + y: 100, + data: { + type: "line", + dataSetsHaveTitle: false, + dataSets: ["A1"], + legendPosition: "top", + verticalAxisPosition: "left", + title: "", + }, + }; + const spreadsheetData = { + sheets: [ + { + id: "sheet1", + figures: [{ ...figure, id: "figure1" }], + }, + ], + }; + const serverData = getDashboardServerData(); + serverData.models["spreadsheet.dashboard.group"].records = [ + { + dashboard_ids: [789], + id: 1, + name: "Chart", + }, + ]; + serverData.models["spreadsheet.dashboard"].records = [ + { + id: 789, + name: "Spreadsheet with chart figure", + json_data: JSON.stringify(spreadsheetData), + spreadsheet_data: JSON.stringify(spreadsheetData), + dashboard_group_id: 1, + }, + ]; + const fixture = getFixture(); + await createSpreadsheetDashboard({ serverData }); + await triggerEvent(fixture, ".o-chart-container", "focus"); + await triggerEvent(fixture, ".o-chart-container", "dblclick"); + assert.containsOnce(fixture, ".o-chart-container"); + assert.containsNone(fixture, ".o-sidePanel"); +}); + QUnit.test("can switch dashboard", async (assert) => { await createSpreadsheetDashboard(); const fixture = getFixture();