Skip to content

Commit 19401a3

Browse files
adding migration for report action fix (#800)
* adding migration for report action fix * improving code following sonarcloud suggestions * reverting version number and implemented patching function --------- Co-authored-by: Alfred Rubin <[email protected]>
1 parent 8772663 commit 19401a3

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

src/dashboard/DashboardReducer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import {
1919
} from './DashboardActions';
2020

2121
export const NEODASH_VERSION = '2.4';
22-
export const VERSION_TO_MIGRATE = { '1.1': '2.0', '2.0': '2.1', '2.1': '2.2', '2.2': '2.3', '2.3': '2.4' };
22+
export const VERSION_TO_MIGRATE = {
23+
'1.1': '2.0',
24+
'2.0': '2.1',
25+
'2.1': '2.2',
26+
'2.2': '2.3',
27+
'2.3': '2.4',
28+
};
2329

2430
export const initialState = {
2531
title: DEFAULT_DASHBOARD_TITLE,

src/dashboard/DashboardThunks.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ export const loadDashboardThunk = (uuid, text) => (dispatch: any, getState: any)
8080
dashboard = dashboard.dashboard;
8181
}
8282

83+
let patched;
84+
[dashboard, patched] = patchDashboardVersion(dashboard, dashboard.version);
85+
if (patched) {
86+
dispatch(
87+
createNotificationThunk(
88+
'Successfully patched dashboard',
89+
`Your old dashboard has been patched. You might need to refresh this page and reactivate extensions.`
90+
)
91+
);
92+
}
93+
8394
// Attempt upgrade if dashboard version is outdated.
8495
while (VERSION_TO_MIGRATE[dashboard.version]) {
8596
const upgradedDashboard = upgradeDashboardVersion(
@@ -540,6 +551,29 @@ export const assignDashboardUuidIfNotPresentThunk = () => (dispatch: any, getSta
540551
dispatch(setDashboardUuid(createUUID()));
541552
}
542553
};
554+
export function patchDashboardVersion(dashboard: any, version: any) {
555+
let patched = false;
556+
if (version == '2.4') {
557+
dashboard.pages.forEach((p) => {
558+
p.reports.forEach((r) => {
559+
if (r.type == 'graph' || r.type == 'map' || r.type == 'graph3d') {
560+
r.settings?.actionsRules.forEach((rule) => {
561+
if (
562+
rule?.field &&
563+
(rule?.condition === 'onNodeClick' || rule?.condition == 'Click') &&
564+
rule.value.includes('.')
565+
) {
566+
let val = rule.value.split('.');
567+
rule.value = val[val.length - 1] || rule.value;
568+
patched = true;
569+
}
570+
});
571+
}
572+
});
573+
});
574+
}
575+
return [dashboard, patched];
576+
}
543577

544578
export function upgradeDashboardVersion(dashboard: any, origin: string, target: string) {
545579
if (origin == '2.3' && target == '2.4') {
@@ -549,6 +583,19 @@ export function upgradeDashboardVersion(dashboard: any, origin: string, target:
549583
r.y *= 2;
550584
r.width *= 2;
551585
r.height *= 2;
586+
587+
if (r.type == 'graph' || r.type == 'map' || r.type == 'graph3d') {
588+
r.settings?.actionsRules.forEach((rule) => {
589+
if (
590+
rule?.field &&
591+
(rule?.condition === 'onNodeClick' || rule?.condition == 'Click') &&
592+
rule.value.includes('.')
593+
) {
594+
let val = rule.value.split('.');
595+
rule.value = val[val.length - 1] || rule.value;
596+
}
597+
});
598+
}
552599
});
553600
});
554601
dashboard.version = '2.4';

0 commit comments

Comments
 (0)