Skip to content

Commit 31756d7

Browse files
author
Matt Mazzola
committed
Update report component to get filterPaneEnabled and navContentPaneEnabled settings from powerbi-settings attributes.
1 parent 65a19b7 commit 31756d7

4 files changed

Lines changed: 53 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
5151
- Embed url attribute changed from `powerbi-embed` to `powerbi-embed-url`
5252
- Component type is specified by attribute `powerbi-type`. Use `powerbi-type="report"` instead of applying the attribute `powerbi-report`
53-
- Configuration option attributes all start with prefix `powerbi-options-`. Example (`powerbi-options-filter`)
53+
- Configuration settings attributes all start with prefix `powerbi-settings-`.
5454
5555
## Changes
5656

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,21 @@ If your app is dynamically adding new embed components after page load you will
6969

7070
# Embed configuration and other options
7171

72-
All configuration and options will be provided as attributes prefixed with `powerbi-options-` on the containing html element.
72+
All configuration and settings will be provided as attributes prefixed with `powerbi-settings-` on the containing html element.
73+
7374

7475
1. **Filter Pane**
7576

76-
FilterPane is enabled by default but can be disabled by adding the attribute:
77+
FilterPane is enabled/visible by default but can be disabled/hidden by adding the attribute:
78+
```
79+
<div ... powerbi-settings-filter-pane-enabled="false"></div>
80+
```
81+
82+
2. **Page Navigation**
83+
84+
Page navigation is enabled/visible by default but can be disabled/hidden by adding the attribute:
7785
```
78-
<div ... powerbi-options-filter-pane-enabled="false"`></div>
86+
<div ... powerbi-settings-nav-content-pane-enabled="false"></div>
7987
```
8088

8189
## Setting the size of embedded components

src/report.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@ import * as embed from './embed';
33
import * as models from 'powerbi-models';
44
import * as wpmp from 'window-post-message-proxy';
55
import * as hpm from 'http-post-message';
6+
import * as utils from './util';
67

78
export class Report extends embed.Embed {
89
static allowedEvents = ["dataSelected", "filterAdded", "filterUpdated", "filterRemoved", "pageChanged", "error"];
910
static reportIdAttribute = 'powerbi-report-id';
11+
static filterPaneEnabledAttribute = 'powerbi-settings-filter-pane-enabled';
12+
static navContentPaneEnabledAttribute = 'powerbi-settings-nav-content-pane-enabled';
13+
static typeAttribute = 'powerbi-type';
1014
static type = "Report";
1115

1216
constructor(service: service.Service, element: HTMLElement, config: embed.IEmbedConfiguration) {
13-
super(service, element, config);
17+
const filterPaneEnabled = (config.settings && config.settings.filterPaneEnabled) || !(element.getAttribute(Report.filterPaneEnabledAttribute) === "false");
18+
const navContentPaneEnabled = (config.settings && config.settings.navContentPaneEnabled) || !(element.getAttribute(Report.navContentPaneEnabledAttribute) === "false");
19+
const settings = utils.assign({
20+
filterPaneEnabled,
21+
navContentPaneEnabled
22+
}, config.settings);
23+
const configCopy = utils.assign({ settings }, config);
24+
25+
super(service, element, configCopy);
1426
Array.prototype.push.apply(this.allowedEvents, Report.allowedEvents);
1527
}
1628

test/test.spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,34 @@ describe('service', function () {
213213
expect(report.config.uniqueId).toEqual(jasmine.any(String));
214214
});
215215

216+
it('should get filterPaneEnabled setting from attribute from config and then attribute', function () {
217+
// Arrange
218+
const testUniqueId = 'fakeUniqueId';
219+
const embedUrl = `https://embedded.powerbi.com/appTokenReportEmbed`;
220+
const $reportContainer = $(`<div powerbi-embed-url="${embedUrl}" powerbi-type="report" powerbi-report-id="abc123" powerbi-settings-filter-pane-enabled="false"></div>`)
221+
.appendTo('#powerbi-fixture');
222+
223+
// Act
224+
const report = powerbi.embed($reportContainer[0]);
225+
226+
// Assert
227+
expect(report.config.settings.filterPaneEnabled).toEqual(false);
228+
});
229+
230+
it('should get navContentPaneEnabled setting from attribute from config and then attribute', function () {
231+
// Arrange
232+
const testUniqueId = 'fakeUniqueId';
233+
const embedUrl = `https://embedded.powerbi.com/appTokenReportEmbed`;
234+
const $reportContainer = $(`<div powerbi-embed-url="${embedUrl}" powerbi-type="report" powerbi-report-id="abc123" powerbi-settings-nav-content-pane-enabled="false"></div>`)
235+
.appendTo('#powerbi-fixture');
236+
237+
// Act
238+
const report = powerbi.embed($reportContainer[0]);
239+
240+
// Assert
241+
expect(report.config.settings.navContentPaneEnabled).toEqual(false);
242+
});
243+
216244
it('if component is already embedded in element re-use the existing component by calling load with the new information', function () {
217245
// Arrange
218246
const $element = $('<div powerbi-embed-url="https://app.powerbi.com/reportEmbed?reportId=ABC123" powerbi-type="report"></div>')

0 commit comments

Comments
 (0)