Skip to content

Commit 321f34d

Browse files
committed
[FIX] chart: can UPDATE_CHART on a non-chart figure
The `checkChartExists` method is wrong, it only checks that a figure with the id exists, not that it is a chart. closes #6302 Task: 4775605 X-original-commit: 2004785 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com> Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
1 parent 2094035 commit 321f34d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/plugins/core/chart.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ export class ChartPlugin extends CorePlugin<ChartState> implements ChartState {
240240
}
241241

242242
private checkChartExists(cmd: UpdateChartCommand): CommandResult {
243-
return this.getters.getFigureSheetId(cmd.id)
244-
? CommandResult.Success
245-
: CommandResult.ChartDoesNotExist;
243+
return this.isChartDefined(cmd.id) ? CommandResult.Success : CommandResult.ChartDoesNotExist;
246244
}
247245
}

tests/figures/chart/chart_plugin.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,26 @@ describe("datasource tests", function () {
687687
expect(result).toBeCancelledBecause(CommandResult.ChartDoesNotExist);
688688
});
689689

690+
test("reject updates that target a figure that is not a chart", () => {
691+
model.dispatch("CREATE_FIGURE", {
692+
sheetId: model.getters.getActiveSheetId(),
693+
figure: { id: "2", x: 0, y: 0, width: 100, height: 100, tag: "not a chart" },
694+
});
695+
696+
const result = model.dispatch("UPDATE_CHART", {
697+
definition: {
698+
dataSets: [],
699+
dataSetsHaveTitle: false,
700+
stacked: false,
701+
legendPosition: "bottom",
702+
title: { text: "test" },
703+
type: "bar",
704+
},
705+
sheetId: model.getters.getActiveSheetId(),
706+
id: "2",
707+
});
708+
expect(result).toBeCancelledBecause(CommandResult.ChartDoesNotExist);
709+
});
690710
test("chart is not selected after creation and update", () => {
691711
const chartId = "1234";
692712
createChart(

0 commit comments

Comments
 (0)