Skip to content

Commit 06b9a6f

Browse files
committed
PowerBI component
1 parent ee59f4e commit 06b9a6f

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

components/webView.android.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import { WebView } from 'react-native';
3+
4+
const webView = props => (
5+
<WebView {...props} />
6+
);
7+
8+
export default webView;

components/webView.ios.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import WKWebView from 'react-native-wkwebview-reborn';
3+
4+
const webView = props => (
5+
<WKWebView {...props} />
6+
);
7+
8+
export default webView;

index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React, { Component } from 'react';
2+
import WebView from './components/webView';
3+
4+
class PowerBIEmbed extends Component {
5+
constructor(props) {
6+
super(props);
7+
this.configuration = this.setConfiguration(props);
8+
}
9+
10+
setConfiguration = (props) => {
11+
let embedConfiguration = {
12+
type: 'report',
13+
tokenType: 1,
14+
accessToken: props.accessToken,
15+
embedUrl: props.embedUrl,
16+
id: props.id,
17+
settings: {
18+
filterPaneEnabled: false,
19+
navContentPaneEnabled: false,
20+
layoutType: 2,
21+
},
22+
};
23+
if (('language' in props)) {
24+
embedConfiguration.settings.localeSettings = {
25+
language: props.language,
26+
formatLocale: props.language,
27+
};
28+
}
29+
30+
if (('embedConfiguration' in props)) {
31+
embedConfiguration = this.merge(embedConfiguration, props.embedConfiguration);
32+
}
33+
34+
return JSON.stringify(embedConfiguration);
35+
}
36+
37+
getTemplate = configuration => (`<!doctype html>
38+
<html>
39+
<head>
40+
<meta charset="utf-8" />
41+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/powerbi.min.js"></script>
42+
<style>
43+
html,
44+
body,
45+
#reportContainer {
46+
width: 100%;
47+
height: 100%;
48+
margin: 0;
49+
background-color: 'white';
50+
-webkit-overflow-scrolling: touch;
51+
}
52+
iframe {
53+
border: 0px
54+
}
55+
</style>
56+
</head>
57+
58+
<body>
59+
<div id="reportContainer"></div>
60+
<script>
61+
var models = window['powerbi-client'].models;
62+
var config = ${configuration};
63+
var reportContainer = document.getElementById('reportContainer');
64+
var report = powerbi.embed(reportContainer, config);
65+
</script>
66+
</body>
67+
</html>`
68+
);
69+
70+
merge = (target, source) => {
71+
for (const key of Object.keys(source)) {
72+
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]));
73+
}
74+
Object.assign(target || {}, source);
75+
return target;
76+
}
77+
78+
render() {
79+
const html = this.getTemplate(this.configuration);
80+
return (
81+
<WebView source={{ html }} />
82+
);
83+
}
84+
}
85+
86+
export default PowerBIEmbed;

0 commit comments

Comments
 (0)