-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathconfig.js
More file actions
88 lines (80 loc) · 2.17 KB
/
Copy pathconfig.js
File metadata and controls
88 lines (80 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { models } from 'powerbi-client';
import { clean, isEmpty } from "./utils";
import pbi from 'powerbi-client';
const createConfig = props => {
if (props) {
const {
embedType,
tokenType,
accessToken,
embedUrl,
embedId,
permissions,
pageName,
extraSettings,
dashboardId,
datasetId,
reportMode,
theme,
} = props;
if(reportMode === 'create') {
return clean({
tokenType: models.TokenType[tokenType],
accessToken,
embedUrl,
datasetId,
reportMode,
});
}
return clean({
type: embedType,
tokenType: models.TokenType[tokenType],
accessToken,
embedUrl,
id: embedId,
pageName: pageName,
dashboardId: dashboardId,
permissions: models.Permissions[permissions],
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true,
...extraSettings,
},
datasetId,
reportMode,
theme: !isEmpty(theme)?{themeJson: theme}:null,
});
}
return null;
};
const validateCustomTheme = config => {
if(config.theme) {
err = pbi.models.validateCustomTheme(config.theme);
if(err) {
return []
}
}
return [];
};
const validateTypeConfig = config => {
switch (config.type) {
case 'report':
return pbi.models.validateReportLoad(config) && validateCustomTheme(config);
case 'dashboard':
return pbi.models.validateDashboardLoad(config);
case 'tile':
return pbi.models.validateTileLoad(config);
default:
throw 'Unknown config type allowed types are report, dashboard or tile';
}
};
const validateCreateReportConfig = config => {
if(!config.embedUrl)
return 'Embed URL is required';
return pbi.models.validateCreateReport(config);
};
const validateConfig = config => {
const isCreateMode = config.reportMode === 'create';
return isCreateMode ? validateCreateReportConfig(config) : validateTypeConfig(config);
};
export { createConfig, validateConfig }