@equinor/fusion-react-power-bi
Version:
React component for displaying an person information
59 lines • 2.41 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useContext, useState, useEffect } from 'react';
import { context, PowerBIEmbedEvents } from '../context';
import { filter, first } from 'rxjs/operators';
import { useSelector } from '@equinor/fusion';
// import { BookmarksManager } from '@equinor/fusion-components';
const BookmarksManager = (_props) => {
console.error('no bookmark manager defined!');
return null;
};
const nextRender = (event$) => {
return event$.pipe(filter((x) => x.type === PowerBIEmbedEvents.rendered), first());
};
export const PowerBIBookmark = ({ hasContext }) => {
const [isLoaded, setIsLoaded] = useState(false);
const pbiContext = useContext(context);
if (!pbiContext)
return null;
const { component, store, event$ } = pbiContext;
/**
* @eskil - seems like the bookmark sidesheet does not display if the AppSettingsManager is rendered to early
* this only triggers re-render when status of the store changes
*/
useSelector(store, 'status');
const report = component?.current;
const captureBookmark = async () => {
if (!report)
return '';
try {
const bookmark = await report.bookmarksManager.capture();
return bookmark.state || '';
}
catch (err) {
console.error(err);
return '';
}
};
/**
* @todo - test if this can be applied on next load
*/
const applyBookmark = async (bookmark, awaitForContextSwitch) => {
awaitForContextSwitch
? nextRender(event$).subscribe(() => report.bookmarksManager.applyState(bookmark))
: report.bookmarksManager.applyState(bookmark);
};
applyBookmark;
useEffect(() => {
const loaded$ = event$.pipe(filter((x) => x.type === PowerBIEmbedEvents.Loaded), first());
const subscription = loaded$.subscribe(() => setIsLoaded(true));
return () => {
subscription.unsubscribe();
};
}, [event$]);
return isLoaded ? (_jsx(BookmarksManager, { capturePayload: captureBookmark,
// applyBookmark={(bookmark, awaitForContextSwitch) => applyBookmark(bookmark.payload, awaitForContextSwitch)}
hasContext: hasContext, anchorId: "pbi-bookmarks-btn", name: "Power BI bookmarks" })) : null;
};
export default PowerBIBookmark;
//# sourceMappingURL=PowerBIBookmark.js.map