Skip to content

Commit 45725c9

Browse files
committed
[FIX] Migration: Fix chart migration after 18.5.1
The current introduction of the carousels came required a change of data structure regarding the charts, namely, split their id from the one of their container. Some migration tools (repairInitialMessages) were adapted accordingly but there were some mmistakes in the adaptation: - the condition set on the versions was inverted - the test was adapted but only acounted for the versions that came after the refactoring, hiding the previous issue - the handler `fixChartDefinitions` did not account for chart definitions existing in the carousels The handler `fixChartDefinitions` was added to level partial definitions in old chart related commands that were issued around version 16.0 This means that if a user were to create a model with data that come from version 18.5.1, the data necessarily have been upgraded (snapshotted) and it is therefore guaranteed that the changes of those commands have been incorporated in the loaded data, which means the `fixChartDefinition` no longer makes sense. This revision fixes the aforementioned issues by skipping `fixChartDefinitions` for data above 18.5.1. The tests have also been adapted to ensure previous versions are still properly adapted. closes #7550 Task: 5365954 Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent e63f36f commit 45725c9

File tree

3 files changed

+99
-92
lines changed

3 files changed

+99
-92
lines changed

src/migrations/data.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,23 @@ function dropCommands(initialMessages: StateUpdateMessage[], commandType: string
278278
}
279279

280280
function fixChartDefinitions(data: Partial<WorkbookData>, initialMessages: StateUpdateMessage[]) {
281+
/**
282+
* Revisions created after version 18.5.1 contain the full chart definition in the command
283+
* if the data was alreay updated to 18.5.1, then those older revision cannot (by definition) be reaplied
284+
* and should not be replayed.
285+
* FIXME: every command should be versionned when upgraded to allow finer tuning.
286+
*/
287+
if (!data.version || compareVersions(String(data.version), "18.5.1") >= 0) {
288+
return initialMessages;
289+
}
281290
const messages: StateUpdateMessage[] = [];
282291
const map = {};
283292
for (const sheet of data.sheets || []) {
284293
sheet.figures?.forEach((figure) => {
285294
if (figure.tag === "chart") {
286295
// chart definition
287-
if (data.version && compareVersions(String(data.version), "18.5.1") <= 0) {
288-
map[figure.data.chartId] = figure.data;
289-
} else {
290-
map[figure.id] = figure.data;
291-
}
296+
297+
map[figure.id] = figure.data;
292298
}
293299
});
294300
}

tests/collaborative/collaborative_history.test.ts

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Model } from "../../src";
22
import { DEFAULT_REVISION_ID, MESSAGE_VERSION } from "../../src/constants";
33
import { toZone } from "../../src/helpers";
44
import { CommandResult, UpdateCellCommand } from "../../src/types";
5-
import { LineChartDefinition } from "../../src/types/chart/line_chart";
65
import { StateUpdateMessage } from "../../src/types/collaborative/transport_service";
76
import { MockTransportService } from "../__mocks__/transport_service";
87
import {
@@ -425,92 +424,6 @@ describe("Collaborative local history", () => {
425424
expect(getCell(model, "A1")?.format).toBeUndefined();
426425
});
427426

428-
test("Update chart revisions contain the full definition", () => {
429-
const initialMessages: StateUpdateMessage[] = [
430-
{
431-
type: "REMOTE_REVISION",
432-
version: MESSAGE_VERSION,
433-
nextRevisionId: "1",
434-
clientId: "bob",
435-
commands: [
436-
{
437-
type: "UPDATE_CHART",
438-
figureId: "fig1",
439-
chartId: "chart1",
440-
//@ts-ignore the old command would handle a partial definition
441-
definition: { dataSets: [{ dataRange: "A1:A3" }] },
442-
},
443-
{
444-
type: "CREATE_CHART",
445-
sheetId: "sheet1",
446-
figureId: "fig2",
447-
chartId: "chart2",
448-
col: 0,
449-
row: 0,
450-
offset: {
451-
x: 0,
452-
y: 0,
453-
},
454-
size: {
455-
width: 100,
456-
height: 100,
457-
},
458-
definition: {
459-
title: { text: "" },
460-
dataSets: [{ dataRange: "A1", yAxisId: "y" }],
461-
type: "bar",
462-
stacked: false,
463-
dataSetsHaveTitle: false,
464-
legendPosition: "none",
465-
},
466-
},
467-
{
468-
type: "UPDATE_CHART",
469-
figureId: "fig2",
470-
chartId: "chart2",
471-
//@ts-ignore the old command would handle a partial definition
472-
definition: { dataSets: [{ dataRange: "B1:B3" }] },
473-
},
474-
],
475-
serverRevisionId: "initial_revision",
476-
},
477-
];
478-
const data = {
479-
revisionId: "initial_revision",
480-
version: "18.5.1",
481-
sheets: [
482-
{
483-
id: "sheet1",
484-
figures: [
485-
{
486-
id: "fig1",
487-
tag: "chart",
488-
width: 400,
489-
height: 300,
490-
x: 100,
491-
y: 100,
492-
data: {
493-
chartId: "chart1",
494-
type: "line",
495-
dataSetsHaveTitle: false,
496-
dataSets: [{ dataRange: "Sheet1!B26:B35" }, { dataRange: "Sheet1!C26:C35" }],
497-
legendPosition: "top",
498-
title: "Line",
499-
stacked: false,
500-
cumulative: false,
501-
},
502-
},
503-
],
504-
},
505-
],
506-
};
507-
const model = new Model(data, {}, initialMessages);
508-
const definition1 = model.getters.getChartDefinition("chart1") as LineChartDefinition;
509-
expect(definition1.dataSets).toEqual([{ dataRange: "A1:A3" }]);
510-
const definition2 = model.getters.getChartDefinition("chart2") as LineChartDefinition;
511-
expect(definition2.dataSets).toEqual([{ dataRange: "B1:B3" }]);
512-
});
513-
514427
test("Undo/redo your own change only", () => {
515428
setCellContent(alice, "A1", "hello in A1");
516429
setCellContent(bob, "B2", "hello in B2");

tests/model/model_import_export.test.ts

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
DEFAULT_CELL_WIDTH,
66
DEFAULT_REVISION_ID,
77
FORBIDDEN_SHEETNAME_CHARS,
8+
MESSAGE_VERSION,
89
} from "../../src/constants";
910
import { toCartesian, toZone } from "../../src/helpers";
1011
import { DEFAULT_TABLE_CONFIG } from "../../src/helpers/table_presets";
@@ -16,6 +17,8 @@ import {
1617
DEFAULT_LOCALES,
1718
IconSetRule,
1819
} from "../../src/types";
20+
import { LineChartDefinition } from "../../src/types/chart";
21+
import { StateUpdateMessage } from "../../src/types/collaborative/transport_service";
1922
import {
2023
activateSheet,
2124
resizeColumns,
@@ -1130,3 +1133,88 @@ test("Can import spreadsheet with only version", () => {
11301133
// We expect the model to be loaded without traceback
11311134
expect(true).toBeTruthy();
11321135
});
1136+
1137+
test("Update chart revisions contain the full definition pre 18.5.1", () => {
1138+
const initialMessages: StateUpdateMessage[] = [
1139+
{
1140+
type: "REMOTE_REVISION",
1141+
version: MESSAGE_VERSION,
1142+
nextRevisionId: "1",
1143+
clientId: "bob",
1144+
commands: [
1145+
{
1146+
type: "UPDATE_CHART",
1147+
figureId: "fig1",
1148+
chartId: "fig1",
1149+
//@ts-ignore the old command would handle a partial definition
1150+
definition: { dataSets: [{ dataRange: "A1:A3" }] },
1151+
},
1152+
{
1153+
type: "CREATE_CHART",
1154+
sheetId: "sheet1",
1155+
figureId: "fig2",
1156+
chartId: "fig2",
1157+
col: 0,
1158+
row: 0,
1159+
offset: {
1160+
x: 0,
1161+
y: 0,
1162+
},
1163+
size: {
1164+
width: 100,
1165+
height: 100,
1166+
},
1167+
definition: {
1168+
title: { text: "" },
1169+
dataSets: [{ dataRange: "A1", yAxisId: "y" }],
1170+
type: "bar",
1171+
stacked: false,
1172+
dataSetsHaveTitle: false,
1173+
legendPosition: "none",
1174+
},
1175+
},
1176+
{
1177+
type: "UPDATE_CHART",
1178+
figureId: "fig2",
1179+
chartId: "fig2",
1180+
//@ts-ignore the old command would handle a partial definition
1181+
definition: { dataSets: [{ dataRange: "B1:B3" }] },
1182+
},
1183+
],
1184+
serverRevisionId: "initial_revision",
1185+
},
1186+
];
1187+
const data = {
1188+
revisionId: "initial_revision",
1189+
version: "18.4.3",
1190+
sheets: [
1191+
{
1192+
id: "sheet1",
1193+
figures: [
1194+
{
1195+
id: "fig1",
1196+
tag: "chart",
1197+
width: 400,
1198+
height: 300,
1199+
x: 100,
1200+
y: 100,
1201+
data: {
1202+
type: "line",
1203+
dataSetsHaveTitle: false,
1204+
dataSets: [{ dataRange: "Sheet1!B26:B35" }, { dataRange: "Sheet1!C26:C35" }],
1205+
legendPosition: "top",
1206+
title: "Line",
1207+
stacked: false,
1208+
cumulative: false,
1209+
},
1210+
},
1211+
],
1212+
},
1213+
],
1214+
};
1215+
const model = new Model(data, {}, initialMessages);
1216+
const definition1 = model.getters.getChartDefinition("fig1") as LineChartDefinition;
1217+
expect(definition1.dataSets).toEqual([{ dataRange: "A1:A3" }]);
1218+
const definition2 = model.getters.getChartDefinition("fig2") as LineChartDefinition;
1219+
expect(definition2.dataSets).toEqual([{ dataRange: "B1:B3" }]);
1220+
});

0 commit comments

Comments
 (0)