|
| 1 | +"use strict"; |
| 2 | +Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 | +exports.useBootstrap = exports.useReport = exports._useReport = void 0; |
| 4 | +var react_1 = require("react"); |
| 5 | +var config_1 = require("../utils/config"); |
| 6 | +function _useReport(performOnEmbed) { |
| 7 | + var _a = (0, react_1.useState)(null), report = _a[0], _setEmbedInstance = _a[1]; |
| 8 | + var setEmbed = function (embedDivRef, embedConfig) { |
| 9 | + var errors = (0, config_1.validateConfig)(embedConfig); |
| 10 | + if (!errors || errors.length === 0) { |
| 11 | + embed(embedDivRef.current, embedConfig); |
| 12 | + } |
| 13 | + else { |
| 14 | + var errorString = (0, config_1.parseConfigErrors)(errors); |
| 15 | + throw new Error(errorString || 'invalid configuration passed'); |
| 16 | + } |
| 17 | + }; |
| 18 | + var embed = function (ref, config) { |
| 19 | + var reportMode = config.reportMode; |
| 20 | + var isCreateMode = reportMode === 'Create'; |
| 21 | + var embedInstance; |
| 22 | + if (isCreateMode) |
| 23 | + embedInstance = window.powerbi.createReport(ref, config); |
| 24 | + else { |
| 25 | + embedInstance = window.powerbi.embed(ref, config); |
| 26 | + } |
| 27 | + if (performOnEmbed) { |
| 28 | + performOnEmbed(embedInstance, ref); |
| 29 | + } |
| 30 | + _setEmbedInstance(embedInstance); |
| 31 | + }; |
| 32 | + return [report, setEmbed]; |
| 33 | +} |
| 34 | +exports._useReport = _useReport; |
| 35 | +function useReport() { |
| 36 | + var _a = (0, react_1.useState)(null), report = _a[0], _setEmbedInstance = _a[1]; |
| 37 | + var embed = function (ref, config) { |
| 38 | + var embedConfig = (0, config_1.createEmbedConfigBasedOnEmbedType)(config); |
| 39 | + var errors = (0, config_1.validateConfig)(embedConfig); |
| 40 | + if (!errors || errors.length === 0) { |
| 41 | + var _embed = window.powerbi.embed(ref.current, embedConfig); |
| 42 | + var embedInstance = window.powerbi.get(ref.current); |
| 43 | + _setEmbedInstance(embedInstance); |
| 44 | + } |
| 45 | + else { |
| 46 | + var errorString = (0, config_1.parseConfigErrors)(errors); |
| 47 | + throw new Error(errorString || 'invalid configuration passed'); |
| 48 | + } |
| 49 | + }; |
| 50 | + return [report, embed]; |
| 51 | +} |
| 52 | +exports.useReport = useReport; |
| 53 | +function useBootstrap() { |
| 54 | + var _a = (0, react_1.useState)(false), isBotstrapped = _a[0], setIsBootstrapped = _a[1]; |
| 55 | + var _b = (0, react_1.useState)(null), report = _b[0], _setEmbedInstance = _b[1]; |
| 56 | + var embed = function (ref, config) { |
| 57 | + if (isBotstrapped) { |
| 58 | + var embedConfig = (0, config_1.createEmbedConfigBasedOnEmbedType)(config); |
| 59 | + var errors = (0, config_1.validateConfig)(embedConfig); |
| 60 | + if (!errors || errors.length === 0) { |
| 61 | + var _embed = window.powerbi.embed(ref.current, embedConfig); |
| 62 | + var embedInstance = window.powerbi.get(ref.current); |
| 63 | + _setEmbedInstance(embedInstance); |
| 64 | + } |
| 65 | + else { |
| 66 | + var errorString = (0, config_1.parseConfigErrors)(errors); |
| 67 | + throw new Error(errorString || 'invalid configuration passed'); |
| 68 | + } |
| 69 | + } |
| 70 | + else { |
| 71 | + throw new Error('bootstrap was not called'); |
| 72 | + } |
| 73 | + }; |
| 74 | + var bootstrap = function (ref, config) { |
| 75 | + var bootstrapConfig = (0, config_1.createEmbedConfigBasedOnEmbedType)(config); |
| 76 | + if ((0, config_1.validateBootrapConfig)(bootstrapConfig)) { |
| 77 | + window.powerbi.bootstrap(ref.current, bootstrapConfig); |
| 78 | + setIsBootstrapped(true); |
| 79 | + } |
| 80 | + else { |
| 81 | + throw new Error('invalid configuration passed'); |
| 82 | + } |
| 83 | + }; |
| 84 | + return [report, bootstrap, embed]; |
| 85 | +} |
| 86 | +exports.useBootstrap = useBootstrap; |
0 commit comments