Skip to content

Commit

Permalink
wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nouzbe committed Oct 10, 2023
1 parent 520cc1c commit 61aab3c
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 47 deletions.
47 changes: 37 additions & 10 deletions src/4.3_to_5.0/migrateChart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { servers } from "./__test_resources__/servers";

describe("migrateChart", () => {
it("returns the ActiveUI5 chart widget state corresponding to the given ActiveUI4 chart widget state", () => {
expect(migrateChart(legacyChart, servers)).toMatchInlineSnapshot(`
expect(migrateChart(legacyChart, { servers, shouldUpdateFiltersMdx: true }))
.toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -82,7 +83,9 @@ describe("migrateChart", () => {
});

it("migrates a legacy line chart to a Plotly line chart", () => {
expect(migrateChart(legacyLineChart, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(legacyLineChart, { servers, shouldUpdateFiltersMdx: true }),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -113,7 +116,9 @@ describe("migrateChart", () => {
});

it("migrates a legacy area chart to a Plotly area chart", () => {
expect(migrateChart(legacyAreaChart, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(legacyAreaChart, { servers, shouldUpdateFiltersMdx: true }),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -144,7 +149,12 @@ describe("migrateChart", () => {
});

it("migrates a legacy column chart to a Plotly column chart", () => {
expect(migrateChart(legacyColumnChart, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(legacyColumnChart, {
servers,
shouldUpdateFiltersMdx: true,
}),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -174,7 +184,9 @@ describe("migrateChart", () => {
});

it("migrates a legacy bar chart to a Plotly bar chart", () => {
expect(migrateChart(legacyBarChart, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(legacyBarChart, { servers, shouldUpdateFiltersMdx: true }),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -204,7 +216,9 @@ describe("migrateChart", () => {
});

it("migrates a legacy pie chart to a Plotly pie chart", () => {
expect(migrateChart(legacyPieChart, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(legacyPieChart, { servers, shouldUpdateFiltersMdx: true }),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand All @@ -231,7 +245,12 @@ describe("migrateChart", () => {
});

it("migrates a legacy scatter plot to a Plotly scatter plot", () => {
expect(migrateChart(legacyScatterPlot, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(legacyScatterPlot, {
servers,
shouldUpdateFiltersMdx: true,
}),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -267,7 +286,9 @@ describe("migrateChart", () => {
});

it("migrates an empty chart widget to a plotly-line-chart", () => {
expect(migrateChart(emptyLegacyChart, servers)).toMatchInlineSnapshot(`
expect(
migrateChart(emptyLegacyChart, { servers, shouldUpdateFiltersMdx: true }),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -306,7 +327,10 @@ describe("migrateChart", () => {
},
);

const chartState = migrateChart(partialLegacyChartState, servers);
const chartState = migrateChart(partialLegacyChartState, {
servers,
shouldUpdateFiltersMdx: true,
});

// Notice that `splitBy`, `horizontalSubplots` and `verticalSubplots` are present in the migrated chart state,
// even though they are missing in the input legacy chart state.
Expand Down Expand Up @@ -338,7 +362,10 @@ describe("migrateChart", () => {
// ActiveUI 4 charts did not have this capability: "all measures" could never be moved.
// For this ActiveUI 5 feature to work, charts supporting measures redirection in ActiveUI 5 should see the "ALL_MEASURES" tile added to their mapping during the migration.

const migratedChartState = migrateChart(legacyChart, servers);
const migratedChartState = migrateChart(legacyChart, {
servers,
shouldUpdateFiltersMdx: true,
});

// Even though the ALL_MEASURES tile is missing in the legacy chart state, the migrated state does contain it.
expect(migratedChartState.mapping.splitBy).toContain("ALL_MEASURES");
Expand Down
7 changes: 7 additions & 0 deletions src/4.3_to_5.0/migrateDashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("migrateDashboard", () => {
it("turns the pages content from arrays into maps", () => {
const [dashboard] = migrateDashboard(legacyDashboard, {
servers,
shouldUpdateFiltersMdx: true,
});

expect(dashboard.pages["p-0"].content).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -145,6 +146,7 @@ describe("migrateDashboard", () => {
it("flattens the page layouts", () => {
const [dashboard] = migrateDashboard(legacyDashboard, {
servers,
shouldUpdateFiltersMdx: true,
});
expect(dashboard.pages["p-0"].layout).toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -181,6 +183,7 @@ describe("migrateDashboard", () => {
// Due to the flattening, the context values from the first cube that are also defined in the second cube are overriden.
const [dashboard] = migrateDashboard(legacyDashboard, {
servers,
shouldUpdateFiltersMdx: true,
});
expect(dashboard.queryContext).toMatchInlineSnapshot(`
[
Expand All @@ -203,6 +206,7 @@ describe("migrateDashboard", () => {
it("migrates page context values", () => {
const [dashboard] = migrateDashboard(legacyDashboard, {
servers,
shouldUpdateFiltersMdx: true,
});
expect(_mapValues(dashboard.pages, ({ queryContext }) => queryContext))
.toMatchInlineSnapshot(`
Expand Down Expand Up @@ -242,6 +246,7 @@ describe("migrateDashboard", () => {
} as unknown as LegacyDashboardState;
const [emptyDashboard] = migrateDashboard(legacyEmptyDashboard, {
servers,
shouldUpdateFiltersMdx: true,
});
expect(emptyDashboard).toMatchInlineSnapshot(`
{
Expand Down Expand Up @@ -285,6 +290,7 @@ describe("migrateDashboard", () => {
const [dashboard] = migrateDashboard(legacyDashboard, {
servers,
keysOfWidgetPluginsToRemove,
shouldUpdateFiltersMdx: true,
});

const { content, layout } = dashboard.pages["p-0"];
Expand Down Expand Up @@ -336,6 +342,7 @@ describe("migrateDashboard", () => {
legacyDashboardWithDisconnectedWidget,
{
servers,
shouldUpdateFiltersMdx: true,
},
);

Expand Down
8 changes: 5 additions & 3 deletions src/4.3_to_5.0/migrateDashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ export function migrateDashboard(
servers,
keysOfWidgetPluginsToRemove,
doesReportIncludeStacks,
shouldUpdateFiltersMdx,
treeTableColumnWidth,
}: {
servers: { [serverKey: string]: { dataModel: DataModel; url: string } };
keysOfWidgetPluginsToRemove?: string[];
doesReportIncludeStacks?: boolean;
shouldUpdateFiltersMdx: boolean;
treeTableColumnWidth?: [number, number];
},
): [DashboardState<"serialized">, PartialDashboardErrorReport?] {
Expand Down Expand Up @@ -93,11 +95,11 @@ export function migrateDashboard(
} else {
let migratedWidget: AWidgetState<"serialized"> | undefined = undefined;
try {
migratedWidget = migrateWidget(
widget.bookmark,
migratedWidget = migrateWidget(widget.bookmark, {
servers,
treeTableColumnWidth,
);
shouldUpdateFiltersMdx,
});
if (isDisconnectedWidget(widget.bookmark)) {
keysOfPageDisconnectedWidgets.add(leafKey);
}
Expand Down
16 changes: 12 additions & 4 deletions src/4.3_to_5.0/migrateDrillthrough.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import { servers } from "./__test_resources__/servers";

describe("migrateDrillthrough", () => {
it("returns the ActiveUI5 drillthrough-table widget state corresponding to the given ActiveUI4 drillthrough widget state", () => {
expect(migrateDrillthrough(legacyDrillthrough, servers))
.toMatchInlineSnapshot(`
expect(
migrateDrillthrough(legacyDrillthrough, {
servers,
shouldUpdateFiltersMdx: true,
}),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"columnWidths": {},
Expand All @@ -26,8 +30,12 @@ describe("migrateDrillthrough", () => {
});

it("migrates an empty drillthrough widget", () => {
expect(migrateDrillthrough(emptyLegacyDrillthrough, servers))
.toMatchInlineSnapshot(`
expect(
migrateDrillthrough(emptyLegacyDrillthrough, {
servers,
shouldUpdateFiltersMdx: true,
}),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"columnWidths": {},
Expand Down
14 changes: 11 additions & 3 deletions src/4.3_to_5.0/migrateKpi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { servers } from "./__test_resources__/servers";

describe("migrateKpi", () => {
it("returns the ActiveUI5 KPI widget state corresponding to the given ActiveUI4 KPI widget state", () => {
expect(migrateKpi(legacyKpi, servers)).toMatchInlineSnapshot(`
expect(migrateKpi(legacyKpi, { servers, shouldUpdateFiltersMdx: true }))
.toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down Expand Up @@ -45,7 +46,12 @@ describe("migrateKpi", () => {
});

it("migrates a KPI widget with a comparison", () => {
expect(migrateKpi(legacyComparisonValues, servers)).toMatchInlineSnapshot(`
expect(
migrateKpi(legacyComparisonValues, {
servers,
shouldUpdateFiltersMdx: true,
}),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"comparison": {
Expand Down Expand Up @@ -83,7 +89,9 @@ describe("migrateKpi", () => {
});

it("migrates an empty KPI widget", () => {
expect(migrateKpi(emptyLegacyKpi, servers)).toMatchInlineSnapshot(`
expect(
migrateKpi(emptyLegacyKpi, { servers, shouldUpdateFiltersMdx: true }),
).toMatchInlineSnapshot(`
{
"areFiltersDrivenByMdx": true,
"filters": [],
Expand Down
10 changes: 5 additions & 5 deletions src/4.3_to_5.0/migrateQuickFilter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("migrateQuickFilter", () => {
draft.value.body.configuration.multipleSelection = true;
},
);
expect(migrateQuickFilter(legacyQuickFilterInCheckboxMode, servers))
expect(migrateQuickFilter(legacyQuickFilterInCheckboxMode, { servers }))
.toMatchInlineSnapshot(`
{
"cubeName": "EquityDerivativesCube",
Expand All @@ -34,7 +34,7 @@ describe("migrateQuickFilter", () => {
draft.value.body.configuration.displayedAsSelect = false;
draft.value.body.configuration.multipleSelection = false;
});
expect(migrateQuickFilter(legacyQuickFilterInRadioMode, servers))
expect(migrateQuickFilter(legacyQuickFilterInRadioMode, { servers }))
.toMatchInlineSnapshot(`
{
"cubeName": "EquityDerivativesCube",
Expand All @@ -59,7 +59,7 @@ describe("migrateQuickFilter", () => {
draft.value.body.configuration.multipleSelection = true;
},
);
expect(migrateQuickFilter(legacyQuickFilterInMultiSelectMode, servers))
expect(migrateQuickFilter(legacyQuickFilterInMultiSelectMode, { servers }))
.toMatchInlineSnapshot(`
{
"cubeName": "EquityDerivativesCube",
Expand All @@ -84,7 +84,7 @@ describe("migrateQuickFilter", () => {
draft.value.body.configuration.multipleSelection = false;
},
);
expect(migrateQuickFilter(legacyQuickFilterInSingleSelectMode, servers))
expect(migrateQuickFilter(legacyQuickFilterInSingleSelectMode, { servers }))
.toMatchInlineSnapshot(`
{
"cubeName": "EquityDerivativesCube",
Expand Down Expand Up @@ -115,7 +115,7 @@ describe("migrateQuickFilter", () => {
draft.value.body.configuration.multipleSelection = undefined;
},
);
expect(migrateQuickFilter(legacyQuickFilterOnSlicingLevel, servers))
expect(migrateQuickFilter(legacyQuickFilterOnSlicingLevel, { servers }))
.toMatchInlineSnapshot(`
{
"cubeName": "EquityDerivativesCube",
Expand Down
6 changes: 5 additions & 1 deletion src/4.3_to_5.0/migrateQuickFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ export function migrateQuickFilter(
// Legacy widget states are not typed.
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
legacyQuickFilterState: any,
servers: { [serverKey: string]: { dataModel: DataModel; url: string } },
{
servers,
}: {
servers: { [serverKey: string]: { dataModel: DataModel; url: string } };
},
): QuickFilterWidgetState<"serialized"> {
const {
cube: cubeName,
Expand Down
Loading

0 comments on commit 61aab3c

Please sign in to comment.