Skip to content

Commit

Permalink
feat: ✨ add bookmarks to handover (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustav-Eikaas committed Nov 17, 2023
1 parent a48ea42 commit 77a8554
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 55 deletions.
13 changes: 11 additions & 2 deletions libs/handoverapp/src/lib/config/workspaceConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { useCCApiAccessCheck, useContextId, usePBIOptions } from '@cc-components/shared';
import {
useCCApiAccessCheck,
useContextId,
usePBIOptions,
useWorkspaceBookmarks,
} from '@cc-components/shared';
import { CCApiAccessLoading } from '@cc-components/sharedcomponents';
import { useFilterConfig } from '@cc-components/shared/workspace-config';
import { useHttpClient } from '@equinor/fusion-framework-react-app/http';
Expand All @@ -21,6 +26,8 @@ export const WorkspaceWrapper = () => {
table: 'Dim_ProjectMaster',
});

const { bookmarkKey, currentBookmark, onBookmarkChange } = useWorkspaceBookmarks();

const filterConfig = useFilterConfig((req) =>
client.fetch(`/api/contexts/${contextId}/handover/filter-model`, req)
);
Expand All @@ -35,11 +42,13 @@ export const WorkspaceWrapper = () => {

return (
<Workspace
key={contextId}
key={contextId + bookmarkKey}
workspaceOptions={{
getIdentifier: (item) => item.commissioningPackageUrlId,
defaultTab: 'garden',
}}
currentBookmark={currentBookmark}
onBookmarkChange={onBookmarkChange}
powerBiOptions={pbi}
filterOptions={filterConfig}
gardenOptions={gardenConfig}
Expand Down
32 changes: 0 additions & 32 deletions libs/handoversidesheet/project.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,11 @@ function EnsureHandover({ id, closeSidesheet, item }: HandoverProps) {
}
return res.json() as Promise<HandoverPackage>;
},
{ refetchOnWindowFocus: false }
{ refetchOnWindowFocus: false, initialData: item ?? undefined }
);

if (isLoading) {
return <SidesheetSkeleton close={close} />;
return <SidesheetSkeleton close={() => closeSidesheet()} />;
}

if (error || !data) {
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@cc-components/sharedcomponents": "workspace:^",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@equinor/workspace-ag-grid": "2.0.2",
"@equinor/workspace-ag-grid": "2.0.3",
"@remirror/pm": "^2.0.8",
"@remirror/react": "^2.0.27",
"@remirror/react-editors": "^1.0.38",
Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/packages/fusion-framework/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './createRender';
export * from './useWorkspaceBookmark';
37 changes: 37 additions & 0 deletions libs/shared/src/packages/fusion-framework/useWorkspaceBookmark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Bookmark } from '@equinor/workspace-fusion';
import { useRef, useEffect } from 'react';
import {
useCurrentBookmark,
useBookmark,
} from '@equinor/fusion-framework-react-app/bookmark';

export function useWorkspaceBookmarks() {
const bookmarkRef = useRef<Partial<Bookmark>>({});
const bookmark = useCurrentBookmark<Bookmark>().currentBookmark;
const id = bookmark?.id;
const payload = bookmark?.payload;
const bookmarkHandler = useBookmark<Partial<Bookmark>>();

useEffect(() => {
console.log('Registering handler');
const unsub = bookmarkHandler.addBookmarkCreator(async () => {
console.log('bookmark requested');
return bookmarkRef.current;
});

return () => {
typeof unsub === 'function' && unsub();
};
}, [bookmarkHandler]);

const onBookmarkChange = (ref: Partial<Bookmark>) => {
bookmarkRef.current = ref;
};

return {
currentBookmark: payload,
bookmarkKey: id,
/** Add as prop to workspace */
onBookmarkChange,
};
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"@equinor/fusion-framework-module-ag-grid": "30.2.0",
"@equinor/fusion-framework-react-app": "^4.1.8",
"@equinor/fusion-framework-react-module-context": "^6.0.14",
"@equinor/workspace-fusion": "6.0.0",
"@equinor/fusion-observable": "8.1.2",
"@equinor/workspace-fusion": "5.4.3",
"@equinor/workspace-sidesheet": "^0.1.6",
"@microsoft/applicationinsights-web": "^3.0.3",
"@swc/helpers": "0.5.2",
Expand Down
34 changes: 17 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 77a8554

Please sign in to comment.