diff --git a/src/4.3_to_5.0/migrateSettingsFolder.ts b/src/4.3_to_5.0/migrateSettingsFolder.ts index 82b7ec7..d590714 100644 --- a/src/4.3_to_5.0/migrateSettingsFolder.ts +++ b/src/4.3_to_5.0/migrateSettingsFolder.ts @@ -1,5 +1,6 @@ import _cloneDeep from "lodash/cloneDeep"; import _mapValues from "lodash/mapValues"; +import _uniq from "lodash/uniq"; import _pick from "lodash/pick"; import type { Activity, @@ -38,6 +39,43 @@ function migrateSettingsMap(legacySettingsMap: { migratedSettingsMap["userFilters.areEnabled"] = areUserFiltersEnabled; } + const legacyDrillthroughColumns: + | { + [serverUrl: string]: { + [cubeName: string]: { + functionName: "Value" | "Caption" | "MemberValue" | "MemberCaption"; + columnName: string; + }[]; + }; + } + | undefined = + legacySettingsMap["widgets.Tabular.drillthrough.selectedColumns"]; + + if (legacyDrillthroughColumns !== undefined) { + const migratedDrillthroughColumns: Settings["drillthrough.defaultSelectedColumns"] = + {}; + // The legacy settings are per server and per cube. + // The new ones are only per cube: the assumption is that no customer has multiple servers containing a cube with the same name but exposing a different data model. + for (const serverUrl in legacyDrillthroughColumns) { + for (const cubeName in legacyDrillthroughColumns[serverUrl]) { + if (migratedDrillthroughColumns[cubeName] === undefined) { + migratedDrillthroughColumns[cubeName] = []; + } + migratedDrillthroughColumns[cubeName].push( + ...legacyDrillthroughColumns[serverUrl][cubeName].map( + ({ columnName }) => columnName, + ), + ); + } + } + + // Remove duplicates. + migratedSettingsMap["drillthrough.defaultSelectedColumns"] = _mapValues( + migratedDrillthroughColumns, + _uniq, + ); + } + return migratedSettingsMap; }