Skip to content

Commit

Permalink
[REV] charts: Fix chart duplicated ids
Browse files Browse the repository at this point in the history
This change is not compatible with some commands in odoo ,which do not
contain the sheet id.

This reverts commit dbf469f.

closes #2150

Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
  • Loading branch information
rrahir committed Mar 2, 2023
1 parent 313e965 commit fe7b9ff
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 339 deletions.
27 changes: 6 additions & 21 deletions src/components/figures/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,15 @@ export class ChartFigure extends Component<Props, SpreadsheetEnv> {

mounted() {
const figure = this.props.figure;
const chartData = this.env.getters.getChartRuntime(
this.env.getters.getActiveSheetId(),
figure.id
);
const chartData = this.env.getters.getChartRuntime(figure.id);
if (chartData) {
this.createChart(chartData);
}
}

patched() {
const figure = this.props.figure;
const sheetId = this.env.getters.getActiveSheetId();
const chartData = this.env.getters.getChartRuntime(sheetId, figure.id);
const chartData = this.env.getters.getChartRuntime(figure.id);
if (chartData) {
if (chartData.type !== this.chart!.config.type) {
// Updating a chart type requires to update its options accordingly, if feasible at all.
Expand All @@ -110,7 +106,7 @@ export class ChartFigure extends Component<Props, SpreadsheetEnv> {
} else {
this.chart && this.chart.destroy();
}
const def = this.env.getters.getChartDefinition(sheetId, figure.id);
const def = this.env.getters.getChartDefinition(figure.id);
if (def) {
this.state.background = def.background;
}
Expand All @@ -120,10 +116,7 @@ export class ChartFigure extends Component<Props, SpreadsheetEnv> {
const canvas = this.canvas.el as HTMLCanvasElement;
const ctx = canvas.getContext("2d")!;
this.chart = new window.Chart(ctx, chartData);
const def = this.env.getters.getChartDefinition(
this.env.getters.getActiveSheetId(),
this.props.figure.id
);
const def = this.env.getters.getChartDefinition(this.props.figure.id);
if (def) {
this.state.background = def.background;
}
Expand All @@ -134,11 +127,7 @@ export class ChartFigure extends Component<Props, SpreadsheetEnv> {
registry.add("edit", {
name: _lt("Edit"),
sequence: 1,
action: () =>
this.env.openSidePanel("ChartPanel", {
sheetId: this.env.getters.getActiveSheetId(),
figure: this.props.figure,
}),
action: () => this.env.openSidePanel("ChartPanel", { figure: this.props.figure }),
});
registry.add("delete", {
name: _lt("Delete"),
Expand All @@ -149,10 +138,7 @@ export class ChartFigure extends Component<Props, SpreadsheetEnv> {
id: this.props.figure.id,
});
if (this.props.sidePanelIsOpen) {
this.env.toggleSidePanel("ChartPanel", {
sheetId: this.env.getters.getActiveSheetId(),
figure: this.props.figure,
});
this.env.toggleSidePanel("ChartPanel", { figure: this.props.figure });
}
this.trigger("figure-deleted");
},
Expand All @@ -162,7 +148,6 @@ export class ChartFigure extends Component<Props, SpreadsheetEnv> {
sequence: 11,
action: () => {
this.env.dispatch("REFRESH_CHART", {
sheetId: this.env.getters.getActiveSheetId(),
id: this.props.figure.id,
});
},
Expand Down
5 changes: 1 addition & 4 deletions src/components/figures/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,7 @@ export class FiguresContainer extends Component<{ sidePanelIsOpen: Boolean }, Sp
return;
}
if (this.props.sidePanelIsOpen) {
this.env.openSidePanel("ChartPanel", {
sheetId: this.env.getters.getActiveSheetId(),
figure,
});
this.env.openSidePanel("ChartPanel", { figure });
}
const initialX = ev.clientX;
const initialY = ev.clientY;
Expand Down
6 changes: 2 additions & 4 deletions src/components/side_panel/chart_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
DispatchResult,
Figure,
SpreadsheetEnv,
UID,
} from "../../types/index";
import { ColorPicker } from "../color_picker";
import * as icons from "../icons";
Expand Down Expand Up @@ -150,7 +149,6 @@ const STYLE = css/* scss */ `
`;

interface Props {
sheetId: UID;
figure: Figure;
}

Expand All @@ -171,7 +169,7 @@ export class ChartPanel extends Component<Props, SpreadsheetEnv> {
private state: ChartPanelState = useState(this.initialState(this.props.figure));

async willUpdateProps(nextProps: Props) {
if (!this.getters.getChartDefinition(nextProps.sheetId, nextProps.figure.id)) {
if (!this.getters.getChartDefinition(nextProps.figure.id)) {
this.trigger("close-side-panel");
return;
}
Expand Down Expand Up @@ -241,7 +239,7 @@ export class ChartPanel extends Component<Props, SpreadsheetEnv> {
private updateChart(definition: ChartUIDefinitionUpdate): DispatchResult {
return this.env.dispatch("UPDATE_CHART", {
id: this.props.figure.id,
sheetId: this.props.sheetId,
sheetId: this.getters.getActiveSheetId(),
definition,
});
}
Expand Down
Loading

0 comments on commit fe7b9ff

Please sign in to comment.