Skip to content

Commit 78750f4

Browse files
authored
Add embed.reload(). Allows reloading embeds using existing configuration. (#37)
Closes #4
1 parent 3a20c54 commit 78750f4

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

demo/app/filters.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $(function () {
1414
var $operatorFields = $('.filter-operators');
1515
var $targetTypeFields = $('input[type=radio][name=filterTarget]');
1616
var $targetFields = $('.filter-target');
17+
var $reloadButton = $('#reload');
1718

1819
var $predefinedFilter1 = $('#predefinedFilter1');
1920
var predefinedFilter1 = new models.AdvancedFilter({
@@ -56,6 +57,13 @@ $(function () {
5657
}
5758
]);
5859

60+
$reloadButton.on('click', function (event) {
61+
event.preventDefault();
62+
63+
console.log('reload');
64+
customFilterPaneReport.reload();
65+
});
66+
5967
$customFilterForm.on('submit', function (event) {
6068
event.preventDefault();
6169
console.log('submit');

demo/filters.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ <h4>Visual</h4>
8888
Not Implemented
8989
</div>
9090
</div>
91+
<div class="row">
92+
<div class="col-md-4">
93+
<button type="button" class="btn btn-danger btn-block" id="reload">Reload</button>
94+
</div>
95+
</div>
9196
</div>
9297
<div class="col-md-3">
9398
<form id="customfilterform" name="abc">

src/embed.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,18 @@ export abstract class Embed {
243243
this.element.addEventListener(eventName, <any>handler)
244244
}
245245

246+
/**
247+
* Reloads embed using existing configuration.
248+
* E.g. For reports this effectively clears all filters and makes the first page active which simulates resetting a report back to loaded state.
249+
*
250+
* ```javascript
251+
* report.reload();
252+
* ```
253+
*/
254+
reload(): Promise<void> {
255+
return this.load(this.config);
256+
}
257+
246258
/**
247259
* Gets an access token from the first available location: config, attribute, global.
248260
*

test/test.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,33 @@ describe('SDK-to-HPM', function () {
21462146
});
21472147
});
21482148

2149+
describe('reload', function () {
2150+
it('report.reload() sends POST /report/load with configuration in body', function () {
2151+
// Arrange
2152+
const testData = {
2153+
loadConfiguration: {
2154+
id: 'fakeId',
2155+
accessToken: 'fakeToken'
2156+
},
2157+
response: {
2158+
body: null
2159+
}
2160+
};
2161+
2162+
spyHpm.post.and.returnValue(Promise.resolve(testData.response));
2163+
report.load(testData.loadConfiguration)
2164+
.then(() => {
2165+
spyHpm.post.calls.reset();
2166+
2167+
// Act
2168+
report.reload();
2169+
2170+
// Assert
2171+
expect(spyHpm.post).toHaveBeenCalledWith('/report/load', jasmine.objectContaining(testData.loadConfiguration), { uid: uniqueId }, iframe.contentWindow);
2172+
});
2173+
});
2174+
});
2175+
21492176
describe('settings', function () {
21502177
it('report.updateSettings(settings) sends PATCH /report/settings with settings object', function () {
21512178
// Arrange

0 commit comments

Comments
 (0)