Skip to content

Commit

Permalink
UI-8797 - Migrate smart filtering settings
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinetissier committed May 16, 2024
1 parent 0f2732f commit 8cb3d7a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down Expand Up @@ -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",
],
Expand Down
5 changes: 5 additions & 0 deletions src/4.3_to_5.0/legacySettingsFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const user1Preferences = {
],
},
},
"memberSelection.smartFiltering": false,
},
};

Expand Down Expand Up @@ -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,
},
};

Expand Down
42 changes: 41 additions & 1 deletion src/4.3_to_5.0/migrateSettingsFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 8cb3d7a

Please sign in to comment.