Skip to content

Commit

Permalink
feat(handover): facility context pbi (#1090)
Browse files Browse the repository at this point in the history
* feat(handover): facility context pbi

* .

* .

* .

* .

* .revert
  • Loading branch information
Gustav-Eikaas authored Sep 10, 2024
1 parent fc9e58a commit da9432e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion libs/handoverapp/src/lib/config/frameworkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import buildQuery from 'odata-query';

export const configure = async (config: IAppConfigurator, c: ComponentRenderArgs) => {
enableContext(config, async (builder) => {
builder.setContextType(['ProjectMaster']);
builder.setContextType(['ProjectMaster', 'Facility']);
builder.setContextParameterFn(({ search, type }) => {
return buildQuery({
search,
Expand Down
20 changes: 16 additions & 4 deletions libs/handoverapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,30 @@ import { useGardenConfig } from './gardenConfig';
import { sidesheetConfig } from './sidesheetConfig';
import { useStatusBarConfig } from './statusBarConfig';
import { useTableConfig } from './tableConfig';
import { useModuleCurrentContext } from '@equinor/fusion-framework-react-module-context';

const pbi_context_mapping = {
Facility: {
column: "Facility",
table: "Dim_Facility"
},
ProjectMaster: {
column: "ProjectMaster GUID",
table: "Dim_ProjectMaster"
},
} as const


export const WorkspaceWrapper = () => {
const contextId = useContextId();
useCloseSidesheetOnContextChange();
const client = useHttpClient('cc-app');
const { isLoading } = useCCApiAccessCheck(contextId, client, 'handover');

const pbi = usePBIOptions('handoveranalytics', {
column: 'ProjectMaster GUID',
table: 'Dim_ProjectMaster',
});

const { currentContext } = useModuleCurrentContext()

const pbi = usePBIOptions('handoveranalytics', pbi_context_mapping[(currentContext?.type.id) as "ProjectMaster" | "Facility"]);
const { bookmarkKey, currentBookmark, onBookmarkChange } = useWorkspaceBookmarks();

const filterConfig = useFilterConfig((req) =>
Expand Down
10 changes: 6 additions & 4 deletions libs/shared/src/packages/pbi-helpers/src/lib/usePBIHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useServiceDiscovery } from '../../../hooks/src/lib/useServiceDiscovery'
import { EmbedInfo, EmbedToken, ReportInfo } from './types';
import { useExternalContextId } from '../../../hooks';
import { type IHttpClient } from '@equinor/fusion-framework-module-http';
import { useContext } from 'react';
import { ContextItem, useCurrentContext, useModuleCurrentContext } from '@equinor/fusion-framework-react-module-context';

const isEmbedInfo = (embedInfo: unknown): embedInfo is EmbedInfo => {
return (embedInfo as EmbedInfo).embedConfig.embedUrl !== undefined ? true : false;
Expand All @@ -18,14 +20,15 @@ const isEmbedToken = (embedToken: unknown): embedToken is EmbedToken => {
export const usePBIHelpers = () => {
const serviceDisco = useServiceDiscovery();
const contextId = useExternalContextId();
const { currentContext } = useModuleCurrentContext();

const getEmbed = async (reportUri: string, _token: string, signal?: AbortSignal) => {
if (!contextId) {
throw new Error('No context selected');
}
const client = await serviceDisco.createClient('reports');

await checkAccess(client, contextId, reportUri);
await checkAccess(client, reportUri, currentContext!);

const res = await client.fetch(`reports/${reportUri}/config/embedinfo`, { signal });
if (!res.ok) {
Expand Down Expand Up @@ -77,11 +80,10 @@ export const usePBIHelpers = () => {
};
};

async function checkAccess(client: IHttpClient, contextId: string, reportUri: string) {
const contextType = 'ProjectMaster';
async function checkAccess(client: IHttpClient, reportUri: string, ctx: ContextItem) {

const res = await client.fetch(
`reports/${reportUri}/contexts/${contextId}/contexttypes/${contextType}/checkaccess`,
`reports/${reportUri}/contexts/${ctx.externalId}/contexttypes/${ctx.type.id!}/checkaccess`,
{ method: 'OPTIONS' }
);

Expand Down

0 comments on commit da9432e

Please sign in to comment.