Skip to content

Commit

Permalink
Updated Power BI Package to be fusion-independent
Browse files Browse the repository at this point in the history
Removed deps to fusion libraries
Implemented fallback component handler to report error boundary.
  • Loading branch information
kjellhaaland committed Feb 15, 2024
1 parent 3e14c47 commit 3dfc414
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 32 deletions.
1 change: 0 additions & 1 deletion packages/power-bi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@equinor/eds-core-react": "^0.28.0",
"@equinor/eds-icons": "^0.18.0",
"@equinor/eds-tokens": "^0.9.0",
"@equinor/fusion-react-person": "^0.7.0",
"@tanstack/react-query": "^4.24.4",
"markdown-to-jsx": "^7.1.9",
"powerbi-client": "^2.22.2",
Expand Down
24 changes: 11 additions & 13 deletions packages/power-bi/src/lib/components/PowerBi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ import { Loading } from './loading';
import { chevron_down, chevron_up } from '@equinor/eds-icons';
import { Icon } from '@equinor/eds-core-react';
import { QueryClient, QueryClientProvider, QueryErrorResetBoundary } from '@tanstack/react-query';
import { ErrorBoundary } from 'react-error-boundary';
import { FusionEmbedConfig, FusionPowerBiToken, ReportAccessInfo } from '../types';
import { ErrorComponent } from './error/ErrorComponent';
import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
import { FusionEmbedConfig, FusionPowerBiToken } from '../types';

import { PowerBiController } from '../classes';
import { IBasicFilter } from 'index';
import { Report } from './report/Report';
import React from 'react';

Icon.add({ chevron_down, chevron_up });

export type ErrorComponentProps = {
reportUri: string;
} & FallbackProps;

export interface PowerBiProps {
reportUri: string;
getToken: (reportUri: string, signal?: AbortSignal) => Promise<FusionPowerBiToken>;
getEmbedInfo: (reportUri: string, token: string, signal?: AbortSignal) => Promise<FusionEmbedConfig>;
getErrorMessage: (reportUri: string) => Promise<string>;
getAccessInfo: (reportUri: string) => Promise<ReportAccessInfo>;
ErrorComponent: React.ComponentType<ErrorComponentProps>;
filters?: IBasicFilter;
bookmark?: string;
controller: PowerBiController;
Expand All @@ -26,21 +30,15 @@ export interface PowerBiProps {
const client = new QueryClient();

export const PowerBi = (props: PowerBiProps) => {
const { reportUri, ErrorComponent } = props;
return (
<QueryClientProvider client={client}>
<Suspense fallback={<Loading />}>
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary
onReset={reset}
fallbackRender={(e) => (
<ErrorComponent
{...e}
getAccessInfo={props.getAccessInfo}
getErrorMessage={props.getErrorMessage}
reportUri={props.reportUri}
/>
)}
FallbackComponent={(errorProps) => <ErrorComponent {...errorProps} reportUri={reportUri} />}
>
<Report {...props} />
</ErrorBoundary>
Expand Down
13 changes: 0 additions & 13 deletions packages/power-bi/src/lib/types/access.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/power-bi/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from './error';
export * from './filter';
export * from './observable';
export * from './slicer';
export * from './access';

export type FusionPowerBiToken = {
token: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Integrations folder for exporting types from the integration
* namespace: @equinor/workspace-fusion/power-bi
*/
import { FallbackProps } from 'react-error-boundary';

import {
ActiveFilter,
Expand Down Expand Up @@ -56,6 +57,10 @@ type EmbedConfiguration = {
reportId: string;
};

export type ErrorComponentProps = {
reportUri: string;
} & FallbackProps;

type PowerBiConfig = {
reportUri: string;
getEmbed: (reportUri: string, token: string, signal?: AbortSignal) => Promise<EmbedConfiguration>;
Expand All @@ -70,8 +75,7 @@ type PowerBiConfig = {
* }
* ```
*/
getAccessInfo: (reportUri: string, signal?: AbortSignal) => Promise<ReportAccessInfo>;
getErrorMessage: (reportUri: string, signal?: AbortSignal) => Promise<string>;
ErrorComponent: React.ComponentType<ErrorComponentProps>;
filters?: FilterConfig;
ReportMetaData?: (props: ReportMetaDataProps) => JSX.Element;
getClassification?: (reportUri: string, signal?: AbortSignal) => Promise<string>;
Expand Down
3 changes: 1 addition & 2 deletions packages/workspace-fusion/src/modules/power-bi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ const PowerBiWrapper = (powerBiConfig: PowerBiConfig & { controller: PowerBiCont

return (
<PowerBI
getErrorMessage={powerBiConfig.getErrorMessage}
controller={powerBiConfig.controller}
getToken={powerBiConfig.getToken}
getEmbedInfo={powerBiConfig.getEmbed}
getAccessInfo={powerBiConfig.getAccessInfo}
reportUri={powerBiConfig.reportUri}
filters={createBasicFilter(powerBiConfig.filters)}
ErrorComponent={powerBiConfig.ErrorComponent}
/>
);
};
Expand Down

0 comments on commit 3dfc414

Please sign in to comment.