Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'powerbi-client' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
// embed configuration.
// generate the access token with "powerbi create-embed-token -r"
// get the report id via "powerbi get-reports"
var embedConfiguration = {
type: 'report',
accessToken: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXIiOiIwLjIuMCIsImF1ZCI6Imh0dHBzOi8vYW5hbHlzaXMud2luZG93cy5uZXQvcG93ZXJiaS9hcGkiLCJpc3MiOiJQb3dlciBCSSBOb2RlIFNESyIsIndjbiI6IlBvd2VyQkktUm9sYW5kIiwid2lkIjoiN2JmNmU0ZDMtNjJkZi00YmY1LWJhZDQtYjA0OTI3OWQ0NmQxIiwicmlkIjoiY2NhMGVjYjQtYjc4Yi00Njk4LWJlYzQtZjc3YmU4OGY0YTFmIiwibmJmIjoxNDczNzI2MTcyLCJleHAiOjE0NzM3Mjk3NzJ9.tI-yc_YGuw0krR0T-FNZ9e1ueyMcdQLlbP5L2o3K2I0',
id: 'cca0ecb4-b78b-4698-bec4-f77be88f4a1f',
embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed'
};
// grab a reference to the HTML element containing the report
var reportContainer = document.getElementById('reportContainer');
// construct a PBI service; according to the documentation this should be already available as a global variable,
// but in my case that did not work.
let powerbi = new pbi.service.Service(pbi.factories.hpmFactory, pbi.factories.wpmpFactory, pbi.factories.routerFactory);
var report = powerbi.embed(reportContainer, embedConfiguration);
// attach an event handler for the
document.getElementById("fullscreen").addEventListener("click", () => {
var report = powerbi.get(reportContainer);
report.fullscreen();
});
}
predefinedFilter1Clicked() {
console.log('predefinedFilter1Clicked');
const predefinedFilter1 = new pbi.models.AdvancedFilter({
table: "Store",
column: "Name"
}, "Or",
{
operator: "Contains",
value: "Direct"
},
{
operator: "None",
value: "x"
}
);
this.report.setFilters([predefinedFilter1.toJSON()]);
},
onSubmit() {
const data = {
target: this.getFilterTypeTarget(),
operator: this.getFilterOperatorAndValues(),
filterable: this.getFilterableTarget()
};
let filter;
if (data.operator.type === "Basic") {
filter = new pbi.models.BasicFilter(data.target, data.operator.operator, data.operator.values);
}
else if (data.operator.type === "Advanced") {
filter = new pbi.models.AdvancedFilter(data.target, data.operator.logicalOperator, data.operator.conditions);
}
this.get('onAddFilter')(filter, data.filterable);
},
predefinedFilter3Clicked() {
console.log('predefinedFIlter3Clicked');
const predefinedFilter3 = new pbi.models.AdvancedFilter({
table: "Store",
column: "Name"
}, "Or",
{
operator: "Contains",
value: "Wash"
},
{
operator: "Contains",
value: "Park"
}
);
this.report.page('ReportSection2').setFilters([predefinedFilter3.toJSON()]);
}
},
import Ember from 'ember';
import fetch from 'ember-network/fetch';
import pbi from 'powerbi-client';
const filter = new pbi.models.AdvancedFilter({
table: "Store",
column: "Name"
}, "Or", {
operator: "Contains",
value: "Wash"
},
{
operator: "Contains",
value: "Park"
});
export default Ember.Route.extend({
model() {
return fetch('https://powerbiembedapi.azurewebsites.net/api/reports/c52af8ab-0468-4165-92af-dc39858d66ad')
.then(response => response.json())
.then(embedConfiguration => {
const validateConfig = config => {
switch (config.type) {
case 'report':
return pbi.models.validateReportLoad(config);
case 'dashboard':
return pbi.models.validateDashboardLoad(config);
default:
return 'Unknown config type';
}
};