Skip to content

Release 2.17.1 #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
503 changes: 252 additions & 251 deletions .eslintrc.js

Large diffs are not rendered by default.

357 changes: 210 additions & 147 deletions dist/powerbi-client.d.ts

Large diffs are not rendered by default.

880 changes: 566 additions & 314 deletions dist/powerbi.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/powerbi.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-client",
"version": "2.16.5",
"version": "2.17.1",
"description": "JavaScript library for embedding Power BI into your apps. Provides service which makes it easy to embed different types of components and an object model which allows easy interaction with these components such as changing pages, applying filters, and responding to data selection.",
"main": "dist/powerbi.js",
"types": "dist/powerbi-client.d.ts",
Expand Down Expand Up @@ -78,7 +78,7 @@
},
"dependencies": {
"http-post-message": "^0.2",
"powerbi-models": "^1.7.1",
"powerbi-models": "^1.8",
"powerbi-router": "^0.1",
"window-post-message-proxy": "^0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @ignore *//** */
const config = {
version: '2.16.5',
version: '2.17.1',
type: 'js'
};

Expand Down
30 changes: 19 additions & 11 deletions src/ifilterable.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
import * as models from 'powerbi-models';
import { FiltersOperations, IFilter } from 'powerbi-models';
import { IHttpPostMessageResponse } from 'http-post-message';

/**
* Decorates embed components that support filters
* Examples include reports and pages
*
*
* @export
* @interface IFilterable
*/
export interface IFilterable {
/**
* Gets the filters currently applied to the object.
*
* @returns {(Promise<models.IFilter[]>)}
*
* @returns {(Promise<IFilter[]>)}
*/
getFilters(): Promise<models.IFilter[]>;
getFilters(): Promise<IFilter[]>;
/**
* Replaces all filters on the current object with the specified filter values.
*
* @param {(models.IFilter[])} filters
* Update the filters for the current instance according to the operation: Add, replace all, replace by target or remove.
*
* @param {(FiltersOperations)} operation
* @param {(IFilter[])} filters
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
setFilters(filters: models.IFilter[]): Promise<IHttpPostMessageResponse<void>>;
updateFilters(operation: FiltersOperations, filters?: IFilter[]): Promise<IHttpPostMessageResponse<void>>;
/**
* Removes all filters from the current object.
*
*
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
removeFilters(): Promise<IHttpPostMessageResponse<void>>;
}
/**
* Replaces all filters on the current object with the specified filter values.
*
* @param {(IFilter[])} filters
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
setFilters(filters: IFilter[]): Promise<IHttpPostMessageResponse<void>>;
}
139 changes: 87 additions & 52 deletions src/page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { IHttpPostMessageResponse } from 'http-post-message';
import {
DisplayOption,
FiltersOperations,
ICustomPageSize,
IFilter,
IPage,
IUpdateFiltersRequest,
IVisual,
LayoutType,
PageLevelFilters,
SectionVisibility
} from 'powerbi-models';
import { IFilterable } from './ifilterable';
import { IReportNode } from './report';
import { VisualDescriptor } from './visualDescriptor';
import * as models from 'powerbi-models';
import * as utils from './util';
import * as errors from './errors';
import { isRDLEmbed } from './util';
import { APINotSupportedForRDLError } from './errors';

/**
* A Page node within a report hierarchy
Expand Down Expand Up @@ -58,21 +69,23 @@ export class Page implements IPageNode, IFilterable {
* 0 - Always Visible
* 1 - Hidden in View Mode
*
* @type {models.SectionVisibility}
* @type {SectionVisibility}
*/
visibility: models.SectionVisibility;
visibility: SectionVisibility;

/**
* Page size as saved in the report.
* @type {models.ICustomPageSize}
*
* @type {ICustomPageSize}
*/
defaultSize: models.ICustomPageSize;
defaultSize: ICustomPageSize;

/**
* Page display options as saved in the report.
* @type {models.ICustomPageSize}
*
* @type {ICustomPageSize}
*/
defaultDisplayOption: models.DisplayOption;
defaultDisplayOption: DisplayOption;

/**
* Creates an instance of a Power BI report page.
Expand All @@ -81,10 +94,10 @@ export class Page implements IPageNode, IFilterable {
* @param {string} name
* @param {string} [displayName]
* @param {boolean} [isActivePage]
* @param {models.SectionVisibility} [visibility]
* @param {SectionVisibility} [visibility]
* @hidden
*/
constructor(report: IReportNode, name: string, displayName?: string, isActivePage?: boolean, visibility?: models.SectionVisibility, defaultSize?: models.ICustomPageSize, defaultDisplayOption?: models.DisplayOption) {
constructor(report: IReportNode, name: string, displayName?: string, isActivePage?: boolean, visibility?: SectionVisibility, defaultSize?: ICustomPageSize, defaultDisplayOption?: DisplayOption) {
this.report = report;
this.name = name;
this.displayName = displayName;
Expand All @@ -102,31 +115,36 @@ export class Page implements IPageNode, IFilterable {
* .then(filters => { ... });
* ```
*
* @returns {(Promise<models.IFilter[]>)}
* @returns {(Promise<IFilter[]>)}
*/
async getFilters(): Promise<models.IFilter[]> {
async getFilters(): Promise<IFilter[]> {
try {
const response = await this.report.service.hpm.get<models.IFilter[]>(`/report/pages/${this.name}/filters`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
const response = await this.report.service.hpm.get<IFilter[]>(`/report/pages/${this.name}/filters`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
return response.body;
} catch (response) {
throw response.body;
}
}

/**
* Delete the page from the report
* Update the filters for the current page according to the operation: Add, replace all, replace by target or remove.
*
* ```javascript
* // Delete the page from the report
* page.delete();
* page.updateFilters(FiltersOperations.Add, filters)
* .catch(errors => { ... });
* ```
*
* @returns {Promise<void>}
* @param {(IFilter[])} filters
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
async delete(): Promise<void> {
async updateFilters(operation: FiltersOperations, filters?: IFilter[]): Promise<IHttpPostMessageResponse<void>> {
const updateFiltersRequest: IUpdateFiltersRequest = {
filtersOperation: operation,
filters: filters as PageLevelFilters[]
};

try {
const response = await this.report.service.hpm.delete<void>(`/report/pages/${this.name}`, { }, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
return response.body;
return await this.report.service.hpm.post<void>(`/report/pages/${this.name}/filters`, updateFiltersRequest, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
} catch (response) {
throw response.body;
}
Expand All @@ -142,46 +160,65 @@ export class Page implements IPageNode, IFilterable {
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
async removeFilters(): Promise<IHttpPostMessageResponse<void>> {
return await this.setFilters([]);
return await this.updateFilters(FiltersOperations.RemoveAll);
}

/**
* Makes the current page the active page of the report.
* Sets all filters on the current page.
*
* ```javascript
* page.setActive();
* page.setFilters(filters)
* .catch(errors => { ... });
* ```
*
* @param {(IFilter[])} filters
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
async setActive(): Promise<IHttpPostMessageResponse<void>> {
const page: models.IPage = {
name: this.name,
displayName: null,
isActive: true
};
async setFilters(filters: IFilter[]): Promise<IHttpPostMessageResponse<void>> {
try {
return await this.report.service.hpm.put<void>(`/report/pages/${this.name}/filters`, filters, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
} catch (response) {
throw response.body;
}
}

/**
* Delete the page from the report
*
* ```javascript
* // Delete the page from the report
* page.delete();
* ```
*
* @returns {Promise<void>}
*/
async delete(): Promise<void> {
try {
return await this.report.service.hpm.put<void>('/report/pages/active', page, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
const response = await this.report.service.hpm.delete<void>(`/report/pages/${this.name}`, {}, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
return response.body;
} catch (response) {
throw response.body;
}
}

/**
* Sets all filters on the current page.
* Makes the current page the active page of the report.
*
* ```javascript
* page.setFilters(filters);
* .catch(errors => { ... });
* page.setActive();
* ```
*
* @param {(models.IFilter[])} filters
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
async setFilters(filters: models.IFilter[]): Promise<IHttpPostMessageResponse<void>> {
async setActive(): Promise<IHttpPostMessageResponse<void>> {
const page: IPage = {
name: this.name,
displayName: null,
isActive: true
};

try {
return await this.report.service.hpm.put<void>(`/report/pages/${this.name}/filters`, filters, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
return await this.report.service.hpm.put<void>('/report/pages/active', page, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
} catch (response) {
throw response.body;
}
Expand All @@ -197,9 +234,9 @@ export class Page implements IPageNode, IFilterable {
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
async setDisplayName(displayName: string): Promise<IHttpPostMessageResponse<void>> {
const page: models.IPage = {
const page: IPage = {
name: this.name,
displayName,
displayName: displayName,
};

try {
Expand All @@ -220,19 +257,17 @@ export class Page implements IPageNode, IFilterable {
* @returns {Promise<VisualDescriptor[]>}
*/
async getVisuals(): Promise<VisualDescriptor[]> {
if (utils.isRDLEmbed(this.report.config.embedUrl)) {
return Promise.reject(errors.APINotSupportedForRDLError);
if (isRDLEmbed(this.report.config.embedUrl)) {
return Promise.reject(APINotSupportedForRDLError);
}

try {
const response = await this.report.service.hpm.get<models.IVisual[]>(`/report/pages/${this.name}/visuals`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
const response = await this.report.service.hpm.get<IVisual[]>(`/report/pages/${this.name}/visuals`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
return response.body
.map(visual => {
return new VisualDescriptor(this, visual.name, visual.title, visual.type, visual.layout);
});
} catch (response) {
throw response.body;
}
.map(visual => new VisualDescriptor(this, visual.name, visual.title, visual.type, visual.layout));
} catch (response) {
throw response.body;
}
}

/**
Expand All @@ -246,16 +281,16 @@ export class Page implements IPageNode, IFilterable {
* @returns {(Promise<boolean>)}
*/
async hasLayout(layoutType): Promise<boolean> {
if (utils.isRDLEmbed(this.report.config.embedUrl)) {
return Promise.reject(errors.APINotSupportedForRDLError);
if (isRDLEmbed(this.report.config.embedUrl)) {
return Promise.reject(APINotSupportedForRDLError);
}

let layoutTypeEnum = models.LayoutType[layoutType];
const layoutTypeEnum = LayoutType[layoutType];
try {
const response = await this.report.service.hpm.get<boolean>(`/report/pages/${this.name}/layoutTypes/${layoutTypeEnum}`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow);
return response.body;
} catch (response) {
throw response.body;
}
}
}
}
Loading