Skip to content
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
17 changes: 9 additions & 8 deletions dist/powerbi-client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// powerbi-client v2.23.10
// powerbi-client v2.25.0
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
declare module "config" {
Expand Down Expand Up @@ -158,6 +158,7 @@ declare module "embed" {
export type IQnaEmbedConfiguration = models.IQnaEmbedConfiguration;
export type IQuickCreateConfiguration = models.IQuickCreateConfiguration;
export type IReportCreateConfiguration = models.IReportCreateConfiguration;
export type IReportCreateFromDefinitionConfiguration = models.IReportCreateFromDefinitionConfiguration;
export type ILocaleSettings = models.ILocaleSettings;
export type IQnaSettings = models.IQnaSettings;
export type IEmbedSettings = models.ISettings;
Expand Down Expand Up @@ -1673,7 +1674,7 @@ declare module "report" {
}
}
declare module "create" {
import { IReportCreateConfiguration, IError } from 'powerbi-models';
import { IError, IReportCreateConfiguration, IReportCreateFromDefinitionConfiguration } from 'powerbi-models';
import { Service } from "service";
import { Embed, IEmbedConfigurationBase, IEmbedConfiguration } from "embed";
/**
Expand All @@ -1687,11 +1688,11 @@ declare module "create" {
/**
* Gets or sets the configuration settings for creating report.
*
* @type {IReportCreateConfiguration}
* @type {IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration}
* @hidden
*/
createConfig: IReportCreateConfiguration;
constructor(service: Service, element: HTMLElement, config: IEmbedConfiguration | IReportCreateConfiguration, phasedRender?: boolean, isBootstrap?: boolean);
createConfig: IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration;
constructor(service: Service, element: HTMLElement, config: IEmbedConfiguration | IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration, phasedRender?: boolean, isBootstrap?: boolean);
/**
* Gets the dataset ID from the first available location: createConfig or embed url.
*
Expand Down Expand Up @@ -2137,7 +2138,7 @@ declare module "service" {
import { WindowPostMessageProxy } from 'window-post-message-proxy';
import { HttpPostMessage } from 'http-post-message';
import { Router, IExtendedRequest, Response as IExtendedResponse } from 'powerbi-router';
import { IQuickCreateConfiguration, IReportCreateConfiguration } from 'powerbi-models';
import { IQuickCreateConfiguration, IReportCreateConfiguration, IReportCreateFromDefinitionConfiguration } from 'powerbi-models';
import { Embed, IBootstrapEmbedConfiguration, IDashboardEmbedConfiguration, IEmbedConfiguration, IEmbedConfigurationBase, IQnaEmbedConfiguration, IReportEmbedConfiguration, ITileEmbedConfiguration, IVisualEmbedConfiguration } from "embed";
export interface IEvent<T> {
type: string;
Expand Down Expand Up @@ -2257,7 +2258,7 @@ declare module "service" {
* @param {IEmbedConfiguration} [config={}]
* @returns {Embed}
*/
createReport(element: HTMLElement, config: IEmbedConfiguration | IReportCreateConfiguration): Embed;
createReport(element: HTMLElement, config: IEmbedConfiguration | IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration): Embed;
/**
* Creates new dataset
*
Expand Down Expand Up @@ -2967,7 +2968,7 @@ declare module "powerbi-client" {
export { Report } from "report";
export { Dashboard } from "dashboard";
export { Tile } from "tile";
export { IEmbedConfiguration, IQnaEmbedConfiguration, IVisualEmbedConfiguration, IReportEmbedConfiguration, IDashboardEmbedConfiguration, ITileEmbedConfiguration, IQuickCreateConfiguration, IReportCreateConfiguration, Embed, ILocaleSettings, IEmbedSettings, IQnaSettings, } from "embed";
export { IEmbedConfiguration, IQnaEmbedConfiguration, IVisualEmbedConfiguration, IReportEmbedConfiguration, IDashboardEmbedConfiguration, ITileEmbedConfiguration, IQuickCreateConfiguration, IReportCreateConfiguration, IReportCreateFromDefinitionConfiguration, Embed, ILocaleSettings, IEmbedSettings, IQnaSettings, } from "embed";
export { Page } from "page";
export { Qna } from "qna";
export { Visual } from "visual";
Expand Down
3,528 changes: 1,653 additions & 1,875 deletions dist/powerbi.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 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.23.10",
"version": "2.25.0",
"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.3.0",
"powerbi-models": "^2.0.1",
"powerbi-models": "^2.2.0",
"powerbi-router": "^0.1",
"window-post-message-proxy": "^0.3.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/** @ignore *//** */
const config = {
version: '2.23.10',
version: '2.25.0',
type: 'js'
};

Expand Down
34 changes: 28 additions & 6 deletions src/create.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { IReportCreateConfiguration, IError, validateCreateReport } from 'powerbi-models';
import {
IError,
IReportCreateConfiguration,
IReportCreateFromDefinitionConfiguration,
validateCreateReport,
validateCreateReportFromDefinition
} from 'powerbi-models';
import { Service } from './service';
import { Embed, IEmbedConfigurationBase, IEmbedConfiguration, ISessionHeaders } from './embed';
import * as utils from './util';

function isReportCreateFromDefinitionConfiguration(config: IEmbedConfigurationBase): config is IReportCreateFromDefinitionConfiguration {
return "reportDefinition" in config;
}

/**
* A Power BI Report creator component
*
Expand All @@ -17,15 +27,21 @@ export class Create extends Embed {
/**
* Gets or sets the configuration settings for creating report.
*
* @type {IReportCreateConfiguration}
* @type {IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration}
* @hidden
*/
createConfig: IReportCreateConfiguration;
createConfig: IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration;

/*
* @hidden
*/
constructor(service: Service, element: HTMLElement, config: IEmbedConfiguration | IReportCreateConfiguration, phasedRender?: boolean, isBootstrap?: boolean) {
constructor(
service: Service,
element: HTMLElement,
config: IEmbedConfiguration | IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration,
phasedRender?: boolean,
isBootstrap?: boolean
) {
super(service, element, config, /* iframe */ undefined, phasedRender, isBootstrap);
}

Expand All @@ -48,7 +64,9 @@ export class Create extends Embed {
* Validate create report configuration.
*/
validate(config: IEmbedConfigurationBase): IError[] {
return validateCreateReport(config);
return isReportCreateFromDefinitionConfiguration(config)
? validateCreateReportFromDefinition(config)
: validateCreateReport(config);
}

/**
Expand All @@ -64,14 +82,18 @@ export class Create extends Embed {

const config = this.config as IEmbedConfiguration | IReportCreateConfiguration;

this.createConfig = {
const createConfig: IReportCreateConfiguration = {
accessToken: config.accessToken,
datasetId: config.datasetId || this.getId(),
groupId: config.groupId,
settings: config.settings,
tokenType: config.tokenType,
theme: config.theme
};

this.createConfig = isReportCreateFromDefinitionConfiguration(this.config)
? { ...createConfig, reportDefinition: this.config.reportDefinition }
: createConfig;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ export type IQuickCreateConfiguration = models.IQuickCreateConfiguration;

export type IReportCreateConfiguration = models.IReportCreateConfiguration;

export type IReportCreateFromDefinitionConfiguration = models.IReportCreateFromDefinitionConfiguration;

export type ILocaleSettings = models.ILocaleSettings;

export type IQnaSettings = models.IQnaSettings;
Expand Down
1 change: 1 addition & 0 deletions src/powerbi-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export {
ITileEmbedConfiguration,
IQuickCreateConfiguration,
IReportCreateConfiguration,
IReportCreateFromDefinitionConfiguration,
Embed,
ILocaleSettings,
IEmbedSettings,
Expand Down
7 changes: 5 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { WindowPostMessageProxy } from 'window-post-message-proxy';
import { HttpPostMessage } from 'http-post-message';
import { Router, IExtendedRequest, Response as IExtendedResponse } from 'powerbi-router';
import { IPage, IQuickCreateConfiguration, IReportCreateConfiguration } from 'powerbi-models';
import { IPage, IQuickCreateConfiguration, IReportCreateConfiguration, IReportCreateFromDefinitionConfiguration } from 'powerbi-models';
import {
Embed,
IBootstrapEmbedConfiguration,
Expand Down Expand Up @@ -279,7 +279,10 @@ export class Service implements IService {
* @param {IEmbedConfiguration} [config={}]
* @returns {Embed}
*/
createReport(element: HTMLElement, config: IEmbedConfiguration | IReportCreateConfiguration): Embed {
createReport(
element: HTMLElement,
config: IEmbedConfiguration | IReportCreateConfiguration | IReportCreateFromDefinitionConfiguration
): Embed {
config.type = 'create';
const powerBiElement = element as IPowerBiElement;
const component = new Create(this, powerBiElement, config);
Expand Down
34 changes: 34 additions & 0 deletions test/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,40 @@ describe('service', function () {
// Assert
expect(report.createConfig.theme).toBeUndefined();
});

it('reportDefinition should be in create config if exists in embedConfig', function () {
// Arrange
const testDatasetId = "ABC123";
const accessToken = 'ABC123';
const reportDefinition = { definition: '{"version":"2.0.0"}' };
const embedUrl = `https://app.powerbi.com/reportEmbed?datasetId=${testDatasetId}`;
const $reportContainer = $(`<div powerbi-embed-url="${embedUrl}"</div>`)
.appendTo('#powerbi-fixture');

// Act
const report = powerbi.createReport($reportContainer[0], { embedUrl: embedUrl, accessToken: accessToken, datasetId: testDatasetId, reportDefinition: reportDefinition }) as create.Create;

// Assert
expect("reportDefinition" in report.createConfig).toBe(true);
if ("reportDefinition" in report.createConfig) {
expect(report.createConfig.reportDefinition).toEqual(reportDefinition);
}
});

it('reportDefinition should be undefined in create config if not exists in embedConfig', function () {
// Arrange
const testDatasetId = "ABC123";
const accessToken = 'ABC123';
const embedUrl = `https://app.powerbi.com/reportEmbed?datasetId=${testDatasetId}`;
const $reportContainer = $(`<div powerbi-embed-url="${embedUrl}"</div>`)
.appendTo('#powerbi-fixture');

// Act
const report = powerbi.createReport($reportContainer[0], { embedUrl: embedUrl, accessToken: accessToken }) as create.Create;

// Assert
expect("reportDefinition" in report.createConfig).toBe(false);
});
});

describe('reports', function () {
Expand Down