diff --git a/src/4.3_to_5.0/__snapshots__/migrateSettingsFolder.test.ts.snap b/src/4.3_to_5.0/__snapshots__/migrateSettingsFolder.test.ts.snap index 2b6527d..e7946c3 100644 --- a/src/4.3_to_5.0/__snapshots__/migrateSettingsFolder.test.ts.snap +++ b/src/4.3_to_5.0/__snapshots__/migrateSettingsFolder.test.ts.snap @@ -58,7 +58,7 @@ exports[`migrateSettingsFolder returns the folders corresponding to the converte }, "settings": { "entry": { - "content": "{"theme":"dark-activeviam","search.maxResults":10,"userFilters.areEnabled":true}", + "content": "{"theme":"dark-activeviam","search.maxResults":10,"userFilters.areEnabled":true,"smartFiltering.nonEmptyEvaluationMeasureName":"pnl.SUM","smartFiltering.ignoredHierarchies":["[Currency].[Currency]","[Geography].[City]"]}", "owners": [ "admin", ], @@ -97,7 +97,7 @@ exports[`migrateSettingsFolder returns the folders corresponding to the converte }, "settings": { "entry": { - "content": "{"userFilters.areEnabled":false,"drillthrough.defaultSelectedColumns":{"MarketRiskCube":["riskCurrency","subTradeId","EntityName"],"SecondCube":["delta"]}}", + "content": "{"userFilters.areEnabled":false,"drillthrough.defaultSelectedColumns":{"MarketRiskCube":["riskCurrency","subTradeId","EntityName"],"SecondCube":["delta"]},"smartFiltering.isEnabled":false}", "owners": [ "user1", ], diff --git a/src/4.3_to_5.0/legacySettingsFolder.ts b/src/4.3_to_5.0/legacySettingsFolder.ts index f2ac97a..be85851 100644 --- a/src/4.3_to_5.0/legacySettingsFolder.ts +++ b/src/4.3_to_5.0/legacySettingsFolder.ts @@ -66,6 +66,7 @@ const user1Preferences = { ], }, }, + "memberSelection.smartFiltering": false, }, }; @@ -120,6 +121,10 @@ const adminPreferences = { "servers.alias": { "https://activepivot-ranch.activeviam.com:5900": "http://localhost:8080", }, + "memberSelection.smartFiltering.nonEmptyMeasure": "[Measures].[pnl.SUM]", + "memberSelection.smartFiltering.ignoreFromContext.[Currency].[Currency]": + true, + "memberSelection.smartFiltering.ignoreFromContext.[Geography].[City]": true, }, }; diff --git a/src/4.3_to_5.0/migrateSettingsFolder.ts b/src/4.3_to_5.0/migrateSettingsFolder.ts index d590714..2ffb069 100644 --- a/src/4.3_to_5.0/migrateSettingsFolder.ts +++ b/src/4.3_to_5.0/migrateSettingsFolder.ts @@ -2,11 +2,13 @@ import _cloneDeep from "lodash/cloneDeep"; import _mapValues from "lodash/mapValues"; import _uniq from "lodash/uniq"; import _pick from "lodash/pick"; -import type { +import _reduce from "lodash/reduce"; +import { Activity, ContentRecord, Settings, MdxString, + unquote, } from "@activeviam/activeui-sdk-5.0"; import { emptyUIFolder } from "@activeviam/content-server-initialization-5.0"; @@ -76,6 +78,44 @@ function migrateSettingsMap(legacySettingsMap: { ); } + /* Smart filtering settings start. */ + const isSmartFilteringDisabled = + legacySettingsMap["memberSelection.smartFiltering"] === false; + if (isSmartFilteringDisabled) { + migratedSettingsMap["smartFiltering.isEnabled"] = false; + } else { + const nonEmptyEvaluationMeasureUniqueName = + legacySettingsMap["memberSelection.smartFiltering.nonEmptyMeasure"]; + if (nonEmptyEvaluationMeasureUniqueName !== undefined) { + const [, nonEmptyEvaluationMeasureName] = unquote( + nonEmptyEvaluationMeasureUniqueName, + ); + // @ts-expect-error TypeScript rightfully complains that this setting key does not exist in 5.0 + // It was added only in 5.1 indeed, but it makes sense to migrate it as an intermediate step. + migratedSettingsMap["smartFiltering.nonEmptyEvaluationMeasureName"] = + nonEmptyEvaluationMeasureName; + } + + const hierarchiesToIgnoreWhenSmartFiltering = _reduce( + legacySettingsMap, + (hierarchyUniqueNames: string[], settingValue, settingKey) => { + const [, hierarchyUniqueName] = settingKey.split( + "memberSelection.smartFiltering.ignoreFromContext.", + ); + if (hierarchyUniqueName && settingValue === true) { + hierarchyUniqueNames.push(hierarchyUniqueName); + } + return hierarchyUniqueNames; + }, + [], + ); + if (hierarchiesToIgnoreWhenSmartFiltering.length > 0) { + migratedSettingsMap["smartFiltering.ignoredHierarchies"] = + hierarchiesToIgnoreWhenSmartFiltering; + } + } + /* Smart filtering settings end. */ + return migratedSettingsMap; }