Skip to content

Commit c32e38b

Browse files
authored
Merge pull request #397 from akshay5995/feature/bootstrap
Add useBootstrap feature
2 parents a622906 + c5304a2 commit c32e38b

File tree

14 files changed

+518
-69
lines changed

14 files changed

+518
-69
lines changed

README.md

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ This repository is maintained by:
1212
- [Satya J (satya64)](https://github.com/satya64)
1313
- [Muthu (muthu1712)](https://github.com/muthu1712)
1414

15-
Existing users of the package please refer to Change Log [here](https://github.com/akshay5995/powerbi-report-component/wiki/Changelog) and please refer [here](https://github.com/akshay5995/powerbi-report-component/wiki/README-file-for--=-2.0.0) for the README for versions <=2.0.0.
16-
17-
### [New Embed Type] ReportVisual (from >=2.4.0)
18-
19-
### [New] Typescript support from >=2.2.2
20-
21-
### [Change Log] >=2.3.0
22-
- **(Breaking change)** `reportMode` prop and config will accept `View`, `Edit` and `Create`. (previously it was `edit`/`view`/`create`)(case sensitive)
23-
- **(Enhancement)** Now you can use `Edit` mode in `useReport` hook.
24-
15+
Existing users of the package please refer to Change Log [here](https://github.com/akshay5995/powerbi-report-component/wiki/Changelog) and please refer [here](https://github.com/akshay5995/powerbi-report-component/wiki/README-file-for--=-2.0.0) for the README for versions <=2.0.0
2516

2617
## Installation
2718

@@ -180,7 +171,7 @@ import { ReportVisual } from 'powerbi-report-component';
180171

181172
## Like hooks ? You'll love this :)
182173

183-
### useReport (available from v2.1.1)
174+
### useReport
184175

185176
Provides a more fine grained approach for embedding. (where you're in control)
186177

@@ -190,7 +181,7 @@ import { useReport } from 'powerbi-report-component';
190181

191182
const MyReport = ({ accessToken, embedUrl, embedId }) => {
192183
const reportRef = useRef(null);
193-
const [report, setEmbed] = useReport();
184+
const [report, embed] = useReport();
194185

195186
const myReportConfig = {
196187
embedType: 'report',
@@ -209,7 +200,7 @@ const MyReport = ({ accessToken, embedUrl, embedId }) => {
209200
// important
210201
useEffect(() => {
211202
// call inside useEffect so the we have the reportRef (reference available)
212-
setEmbed(reportRef, myReportConfig);
203+
embed(reportRef, myReportConfig);
213204
}, []);
214205

215206
const handleClick = () => {
@@ -228,7 +219,7 @@ const MyReport = ({ accessToken, embedUrl, embedId }) => {
228219
export default MyReport;
229220
```
230221

231-
## Passing in custom layout for useReport hook.
222+
#### Passing in custom layout for useReport hook.
232223

233224
Example is taken from powerbi js wiki: [Custom-Layout](https://github.com/Microsoft/PowerBI-JavaScript/wiki/Custom-Layout).
234225

@@ -291,11 +282,71 @@ const myReportConfig = {
291282

292283
// Inside your component
293284
useEffect(() => {
294-
setEmbed(reportRef, myReportConfig);
285+
embed(reportRef, myReportConfig);
295286
}, []);
296287

297288
```
298289

290+
### useBootstrap
291+
292+
Provided performance gains on loading in an async way
293+
294+
```javascript
295+
import React, { useEffect, useRef } from 'react';
296+
import { useBootstrap } from 'powerbi-report-component';
297+
298+
// Your configuration from server
299+
const simulateAjaxCall = new Promise(function(resolve, reject) {
300+
setTimeout(() => {
301+
console.log("Simulating!!!")
302+
}, 3000);
303+
resolve({
304+
accessToken: "accessToken",
305+
embedUrl: "embedUrl",
306+
embedId: "embedId",
307+
reportMode: "View", // "Edit"
308+
permissions: "View", // "All" (when using "Edit" mode)
309+
});
310+
});
311+
312+
313+
const MyReport = ({ accessToken, embedUrl, embedId }) => {
314+
const reportRef = useRef(null);
315+
const [report, bootstrap, embed] = useBootstrap();
316+
317+
const initialReportConfig = {
318+
embedType: 'report',
319+
tokenType: 'Embed',
320+
extraSettings: {
321+
filterPaneEnabled: false,
322+
navContentPaneEnabled: false,
323+
},
324+
};
325+
326+
const getMyConfigurationFromServer = () => {
327+
simulateAjaxCall.then(data => {
328+
// Embed the report once your configuration is received
329+
embed(reportRef, {...initialReportConfig, ...data});
330+
});
331+
}
332+
333+
// important
334+
useEffect(() => {
335+
// call inside useEffect so the we have the reportRef (reference available)
336+
bootstrap(reportRef, initialReportConfig);
337+
}, []);
338+
339+
return (
340+
<div className="report-container">
341+
<div className="report" ref={reportRef} />
342+
<button onClick={getMyConfiguraionFromServer}>Get config from AJAX call</button>
343+
</div>
344+
);
345+
};
346+
347+
export default MyReport;
348+
```
349+
299350
## Report features and props you can pass into the component
300351

301352
Inside your component where you're using { Report } component.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "powerbi-report-component",
3-
"version": "2.5.0",
3+
"version": "2.6.0",
44
"description": "It's a minimalistic react component to embed a Microsoft PowerBI report, dashboard or tile into your react application.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/docs/App.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import MultiplePageDemo from './MultiplePageDemo';
1212
import './index.css';
1313
import { useLocalStorage } from './hooks/useLocalStorage';
1414
import UseReportDemo from './UseReportDemo';
15+
import UseBootstrapDemo from './UseBootstrapDemo';
1516

1617
const App = () => {
1718
const [embedType, setEmbedType] = React.useState('Report');
@@ -35,6 +36,8 @@ const App = () => {
3536
return <MultiplePageDemo />;
3637
case 'useReport':
3738
return <UseReportDemo />;
39+
case 'useBootstrap':
40+
return <UseBootstrapDemo />;
3841
default:
3942
return null;
4043
}

src/docs/UseBootstrapDemo/Form.jsx

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
import React from 'react';
2+
import { Form, Input, Select } from 'antd';
3+
import { layout } from '../styles/formLayoutStyles';
4+
import FormButtonGroupBootstrap from '../common/FormButtonGroupBootstrap';
5+
6+
7+
const simulateAjaxCall = (reportProps) => new Promise(function(resolve, reject) {
8+
setTimeout(() => {
9+
console.log("Simulating!!!")
10+
}, 3000);
11+
resolve(reportProps);
12+
});
13+
14+
const ReportForm = ({
15+
onSubmit,
16+
initialReportProps,
17+
onReset,
18+
onBootstrap,
19+
}) => {
20+
const [isSubmit, setIsSubmit] = React.useState(false);
21+
const [isSimulation, setIsSimulation] = React.useState(false);
22+
const [isBootstrapped, setIsBootstrapped] = React.useState(false);
23+
24+
const handleBootstrap = () => {
25+
setIsBootstrapped(true);
26+
onBootstrap();
27+
};
28+
29+
const onSubmitForm = ({ reportProps }) => {
30+
console.log("Simulating async embed call");
31+
setIsSimulation(true);
32+
simulateAjaxCall(reportProps).then(data => {
33+
setIsSubmit(true);
34+
onSubmit({ reportProps: data });
35+
setIsSimulation(false);
36+
})
37+
};
38+
39+
const onResetForm = () => {
40+
setIsSubmit(false);
41+
onReset(false);
42+
};
43+
44+
return (
45+
<Form
46+
{...layout}
47+
size="large"
48+
colon={false}
49+
name="reportProps"
50+
onFinish={onSubmitForm}
51+
initialValues={{ reportProps: initialReportProps }}
52+
>
53+
<Form.Item
54+
label="Embed Type"
55+
name={['reportProps', 'embedType']}
56+
rules={[{ required: true }]}
57+
>
58+
<Select placeholder="Embed Type">
59+
<Select.Option value="report">Report</Select.Option>
60+
</Select>
61+
</Form.Item>
62+
<Form.Item
63+
label="Token Type"
64+
name={['reportProps', 'tokenType']}
65+
rules={[{ required: true }]}
66+
>
67+
<Select placeholder="Token Type">
68+
<Select.Option value="Embed">Embed</Select.Option>
69+
<Select.Option value="Aad">Aad</Select.Option>
70+
</Select>
71+
</Form.Item>
72+
<Form.Item
73+
name={['reportProps', 'accessToken']}
74+
label="Token"
75+
hidden={!isBootstrapped}
76+
rules={[
77+
{ required: isBootstrapped, message: 'Token is required' },
78+
]}
79+
>
80+
<Input placeholder="Embed or Aad Token" />
81+
</Form.Item>
82+
<Form.Item
83+
name={['reportProps', 'embedUrl']}
84+
hidden={!isBootstrapped}
85+
label="Embed Url"
86+
rules={[
87+
{
88+
required: isBootstrapped,
89+
message: 'Embed Url is required',
90+
},
91+
]}
92+
>
93+
<Input placeholder="Embed Url" />
94+
</Form.Item>
95+
<Form.Item
96+
name={['reportProps', 'embedId']}
97+
label="Embed Id"
98+
hidden={!isBootstrapped}
99+
rules={[
100+
{
101+
required: isBootstrapped,
102+
message: 'Embed Id is required',
103+
},
104+
]}
105+
>
106+
<Input placeholder="Embed Id" />
107+
</Form.Item>
108+
<Form.Item
109+
label="Permissions"
110+
hidden={!isBootstrapped}
111+
name={['reportProps', 'permissions']}
112+
>
113+
<Select placeholder="Permissions (default: View)">
114+
<Select.Option value="View">View</Select.Option>
115+
<Select.Option value="All">All</Select.Option>
116+
</Select>
117+
</Form.Item>
118+
<Form.Item
119+
hidden={!isBootstrapped}
120+
label="Mode"
121+
name={['reportProps', 'reportMode']}
122+
>
123+
<Select placeholder="Mode (default: View)">
124+
<Select.Option value="View">View</Select.Option>
125+
<Select.Option value="Edit">Edit</Select.Option>
126+
</Select>
127+
</Form.Item>
128+
<FormButtonGroupBootstrap
129+
isBootstrapped={isBootstrapped}
130+
isSubmit={isSubmit}
131+
onReset={onResetForm}
132+
onBootstrap={handleBootstrap}
133+
isLoading={isSimulation}
134+
/>
135+
</Form>
136+
);
137+
};
138+
139+
export default ReportForm;

0 commit comments

Comments
 (0)