Skip to content

Commit

Permalink
feat: attempted performance improvements powerbi
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav-Eikaas committed May 23, 2024
1 parent 4f536ec commit dc5b4e3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions packages/power-bi/src/lib/components/report/Report.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
import { useSuspenseQuery } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';
import { FusionPowerBiToken, FusionEmbedConfig } from '../../types';

import { IReportEmbedConfiguration, models } from 'powerbi-client';
import { LoadedReport } from '../loadedReport/LoadedReport';
import { PowerBiProps } from '../PowerBi';
import { CircularProgress } from '@equinor/eds-core-react';

export function Report({ getEmbedInfo, getToken, reportUri, controller, filters, bookmark }: PowerBiProps) {
const { data: token } = useSuspenseQuery<FusionPowerBiToken>({

const { data: token, isLoading: isTokenLoading } = useQuery<FusionPowerBiToken>({
queryKey: [reportUri, 'token'],
queryFn: ({ signal }) => getToken(reportUri, signal),
refetchInterval: (query) => generateRefetchInterval(query.state.data),
retry: false,
refetchOnWindowFocus: true,
});

const { data: embed } = useSuspenseQuery({
const { data: embed, isLoading: isEmbedLoading, } = useQuery({
queryKey: [reportUri, 'embed'],
queryFn: async ({ signal }) => {
const { embedUrl, reportId } = await getEmbedInfo(reportUri, token!.token, signal);
return generateEmbedConfig({ embedUrl, reportId }, token!.token, filters);
const { embedUrl, reportId } = await getEmbedInfo(reportUri, "", signal);
return {
embedUrl,
reportId
}
},
});


if (isTokenLoading || isEmbedLoading) {
return <div style={{ height: "100%", display: "flex", width: "100%", alignItems: "center", justifyContent: "center" }}><CircularProgress {...{} as any} size={48} /></div> }

if (!embed) {
throw new Error('No embed');
}

if (!token) {
throw new Error("No token")
}

return (
<LoadedReport
config={embed}
config={generateEmbedConfig(embed, token!.token, filters)}
onReportReady={(rep) => {
if (bookmark) {
rep.bookmarksManager.applyState(bookmark);
Expand Down

0 comments on commit dc5b4e3

Please sign in to comment.