From f488113071728bf66928e954b291aecff9a037b8 Mon Sep 17 00:00:00 2001 From: muthu1712 Date: Sat, 3 Jul 2021 20:34:38 +0530 Subject: [PATCH 1/4] Specifying Typescript specific prop types --- README.md | 6 +++--- src/lib/hooks/useReport.ts | 16 +++++++++------- src/lib/types.ts | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index aad281df..75ab7842 100644 --- a/README.md +++ b/README.md @@ -190,7 +190,7 @@ const MyReport = ({ accessToken, embedUrl, embedId }) => { embedUrl: embedUrl, embedId: embedId, reportMode: "View", // "Edit" - permissions: "View", // "All" (when using "Edit" mode) + permissions: "Read", // "All" (when using "Edit" mode) extraSettings: { filterPaneEnabled: false, navContentPaneEnabled: false, @@ -305,7 +305,7 @@ const simulateAjaxCall = new Promise(function(resolve, reject) { embedUrl: "embedUrl", embedId: "embedId", reportMode: "View", // "Edit" - permissions: "View", // "All" (when using "Edit" mode) + permissions: "Read", // "All" (when using "Edit" mode) }); }); @@ -339,7 +339,7 @@ const MyReport = ({ accessToken, embedUrl, embedId }) => { return (
- +
); }; diff --git a/src/lib/hooks/useReport.ts b/src/lib/hooks/useReport.ts index 8a09e298..f94ea562 100644 --- a/src/lib/hooks/useReport.ts +++ b/src/lib/hooks/useReport.ts @@ -5,18 +5,20 @@ import { createEmbedConfigBasedOnEmbedType, validateBootrapConfig } from '../utils/config'; -import { Config } from '../types'; +import { Config, ConfigProps } from '../types'; import { Embed } from 'embed'; -declare type UseReport = [any, (ref: any, config: Config) => void]; +declare type _UseReport = [any, (ref: any, config: Config) => void]; -declare type UseBootstrap = [any, (ref: any, config: Config) => void, (ref: any, config: Config) => void]; +declare type UseReport = [any, (ref: any, config: ConfigProps) => void]; + +declare type UseBootstrap = [any, (ref: any, config: ConfigProps) => void, (ref: any, config: ConfigProps) => void]; // powerbi object is global // used inside Embed.jsx has more logic tied to props of Embed. function _useReport( performOnEmbed: (report: any, reportRef?: any) => void -): UseReport { +): _UseReport { const [report, _setEmbedInstance] = useState(null); const setEmbed = (embedDivRef: any, embedConfig: Config): void => { @@ -54,7 +56,7 @@ function _useReport( function useReport(): UseReport { const [report, _setEmbedInstance] = useState(null); - const embed = (ref: any, config: Config): void => { + const embed = (ref: any, config: ConfigProps): void => { const embedConfig = createEmbedConfigBasedOnEmbedType(config); const errors = validateConfig(embedConfig); if (!errors || errors.length === 0) { @@ -75,7 +77,7 @@ function useBootstrap(): UseBootstrap { const [isBotstrapped, setIsBootstrapped] = useState(false); const [report, _setEmbedInstance] = useState(null); - const embed = (ref: any, config: Config): void => { + const embed = (ref: any, config: ConfigProps): void => { if(isBotstrapped) { const embedConfig = createEmbedConfigBasedOnEmbedType(config); const errors = validateConfig(embedConfig); @@ -92,7 +94,7 @@ function useBootstrap(): UseBootstrap { } }; - const bootstrap = (ref: any, config: Config) => { + const bootstrap = (ref: any, config: ConfigProps) => { const bootstrapConfig = createEmbedConfigBasedOnEmbedType(config); if (validateBootrapConfig(bootstrapConfig)) { window.powerbi.bootstrap(ref.current, bootstrapConfig); diff --git a/src/lib/types.ts b/src/lib/types.ts index 1ff557fa..3d802885 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -93,6 +93,8 @@ export interface Config { dashboardId: string; } +export type ConfigProps = ReportProps | DashboardProps | TileProps | ReportVisualProps; + export interface Embed { config: Config; performOnEmbed: (report: any, reportRef?: any) => void; From 5494193c9bbab5593448ed2677dcc6c95820ee6f Mon Sep 17 00:00:00 2001 From: muthu1712 Date: Sun, 11 Jul 2021 16:38:44 +0530 Subject: [PATCH 2/4] Introduce BasicProps config --- src/lib/types.ts | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index 3d802885..e985fae3 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -1,6 +1,6 @@ export type ReportModes = 'View' | 'Edit' | 'Create'; -export type EmbedType = 'report' | 'dashboard' | 'tile'; +export type EmbedType = 'report' | 'dashboard' | 'tile' | 'visual'; export type TokenType = 'Aad' | 'Embed'; @@ -19,41 +19,33 @@ export interface IError { errorCode?: string; } -export interface TileProps { +interface BasicProps { + embedType: EmbedType; tokenType: TokenType; accessToken: string; embedUrl: string; - embedId: string; - dashboardId: string; + embedId?: string; style?: any; onLoad?: Function; +} + +export interface TileProps extends BasicProps { + dashboardId: string; onClick?: Function; } -export interface DashboardProps { - tokenType: TokenType; - accessToken: string; - embedUrl: string; - embedId: string; +export interface DashboardProps extends BasicProps { pageView: PageView; - style?: any; - onLoad?: Function; onTileClicked?: Function; } -export interface ReportProps { - tokenType: TokenType; - accessToken: string; - embedUrl: string; - embedId: string; +export interface ReportProps extends BasicProps { groupId?: string; permissions: Permissions; reportMode: ReportModes; pageName?: string; extraSettings?: any; - style?: any; datasetId?: string; - onLoad?: Function; onRender?: Function; onError?: Function; onButtonClicked?: Function; @@ -63,15 +55,9 @@ export interface ReportProps { onSave?: Function; } -export interface ReportVisualProps { - tokenType: TokenType; - accessToken: string; - embedUrl: string; - embedId: string; +export interface ReportVisualProps extends BasicProps { pageName: string; visualName: string; - style?: any; - onLoad?: Function; onRender?: Function; onSelectData?: Function; } From bec5bbef0e35e6327b25f77b68339fcaae3a43b1 Mon Sep 17 00:00:00 2001 From: muthu1712 Date: Sat, 17 Jul 2021 20:59:13 +0530 Subject: [PATCH 3/4] Rename BasicProps to CommonProps --- src/lib/types.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index e985fae3..9a420e12 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -19,7 +19,7 @@ export interface IError { errorCode?: string; } -interface BasicProps { +interface CommonProps { embedType: EmbedType; tokenType: TokenType; accessToken: string; @@ -29,17 +29,17 @@ interface BasicProps { onLoad?: Function; } -export interface TileProps extends BasicProps { +export interface TileProps extends CommonProps { dashboardId: string; onClick?: Function; } -export interface DashboardProps extends BasicProps { +export interface DashboardProps extends CommonProps { pageView: PageView; onTileClicked?: Function; } -export interface ReportProps extends BasicProps { +export interface ReportProps extends CommonProps { groupId?: string; permissions: Permissions; reportMode: ReportModes; @@ -55,7 +55,7 @@ export interface ReportProps extends BasicProps { onSave?: Function; } -export interface ReportVisualProps extends BasicProps { +export interface ReportVisualProps extends CommonProps { pageName: string; visualName: string; onRender?: Function; From 9b6d49b207805d05f0ded0ccb3bb0ce62f1d024c Mon Sep 17 00:00:00 2001 From: muthu1712 Date: Sat, 17 Jul 2021 21:02:42 +0530 Subject: [PATCH 4/4] bump version 2.6.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05b698a9..d92807e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "powerbi-report-component", - "version": "2.6.0", + "version": "2.6.1", "description": "It's a minimalistic react component to embed a Microsoft PowerBI report, dashboard or tile into your react application.", "main": "lib/index.js", "types": "lib/index.d.ts",