From 1fc912d1207b67dce8f5c980f89151739949433f Mon Sep 17 00:00:00 2001 From: Vincent Schippefilt Date: Thu, 14 Mar 2024 17:16:50 +0100 Subject: [PATCH] [FIX] figures: deleting a sheet will remove all figures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when deleting a sheet, we expect all the figures of that sheet to be deleted. However overrides of figures might only implement "DELETE_FIGURE". Also, implementing correctly "DELETE_SHEET" in all plugins that extends figures means that they would have to use beforeHandle to store the references of the figures of the sheet to be deleted, then in the handle do the deleting based on the saved values. It's a bit ugly. From 16.0, we need to remove the figures in the beforeHandle because the figures themselves need the sheet to still be present to be removed. opw-3783745 closes odoo/o-spreadsheet#3838 X-original-commit: fe43a5b4c80bbff97c5a845219d145fcd7eeeacf Signed-off-by: Lucas Lefèvre (lul) Signed-off-by: Vincent Schippefilt (vsc) --- src/plugins/core/figures.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plugins/core/figures.ts b/src/plugins/core/figures.ts index 7cafb7c17..4ea878ab4 100644 --- a/src/plugins/core/figures.ts +++ b/src/plugins/core/figures.ts @@ -35,6 +35,16 @@ export class FigurePlugin extends CorePlugin implements FigureState } } + beforeHandle(cmd: CoreCommand) { + switch (cmd.type) { + case "DELETE_SHEET": + this.getters.getFigures(cmd.sheetId).forEach((figure) => { + this.dispatch("DELETE_FIGURE", { id: figure.id, sheetId: cmd.sheetId }); + }); + break; + } + } + handle(cmd: CoreCommand) { switch (cmd.type) { case "CREATE_SHEET":