Skip to content

Commit

Permalink
Merge master into hflatval/bump-react-components-0.15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
cognite-bulldozer[bot] authored Sep 13, 2023
2 parents 7db0dc8 + 5a8900e commit d90a994
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { type DmsUniqueIdentifier } from '../../utilities/FdmSDK';
import { type TypedReveal3DModel } from '../Reveal3DResources/types';
import { type ThreeDModelMappings } from '../../hooks/types';
import { DEFAULT_QUERY_STALE_TIME } from '../../utilities/constants';
import { useRevealKeepAlive } from '../RevealKeepAlive/RevealKeepAliveContext';

export type FdmNodeCacheContent = {
cache: FdmNodeCache;
Expand Down Expand Up @@ -97,8 +98,19 @@ export const useFdmAssetMappings = (
export function NodeCacheProvider({ children }: { children?: ReactNode }): ReactElement {
const fdmClient = useFdmSdk();
const cdfClient = useSDK();
const revealKeepAliveData = useRevealKeepAlive();

const fdmCache = useMemo(() => new FdmNodeCache(cdfClient, fdmClient), []);
const fdmCache = useMemo(() => {
const cache =
revealKeepAliveData?.fdmNodeCache.current ?? new FdmNodeCache(cdfClient, fdmClient);

const isRevealKeepAliveContextProvided = revealKeepAliveData !== undefined;
if (isRevealKeepAliveContextProvided) {
revealKeepAliveData.fdmNodeCache.current = cache;
}

return cache;
}, [cdfClient, fdmClient]);

return (
<FdmNodeCacheContext.Provider value={{ cache: fdmCache }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
import { type Cognite3DViewer } from '@cognite/reveal';
import { type ReactNode, type ReactElement, useRef, useEffect } from 'react';
import { RevealKeepAliveContext } from './RevealKeepAliveContext';
import { type FdmNodeCache } from '../NodeCacheProvider/FdmNodeCache';

export function RevealKeepAlive({ children }: { children?: ReactNode }): ReactElement {
const viewerRef = useRef<Cognite3DViewer>();
const isRevealContainerMountedRef = useRef<boolean>(false);
const fdmNodeCache = useRef<FdmNodeCache>();

useEffect(() => {
return () => {
viewerRef.current?.dispose();
viewerRef.current = undefined;
};
}, []);
return (
<RevealKeepAliveContext.Provider value={{ viewerRef, isRevealContainerMountedRef }}>
<RevealKeepAliveContext.Provider
value={{ viewerRef, isRevealContainerMountedRef, fdmNodeCache }}>
{children}
</RevealKeepAliveContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
*/
import { type Cognite3DViewer } from '@cognite/reveal';
import { type MutableRefObject, createContext, useContext } from 'react';
import { type FdmNodeCache } from '../NodeCacheProvider/FdmNodeCache';

export type RevealKeepAliveData = {
viewerRef: MutableRefObject<Cognite3DViewer | undefined>;
isRevealContainerMountedRef: MutableRefObject<boolean>;
fdmNodeCache: MutableRefObject<FdmNodeCache | undefined>;
};

export const RevealKeepAliveContext = createContext<RevealKeepAliveData | undefined>(undefined);
Expand Down
2 changes: 1 addition & 1 deletion viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@types/jsdom": "21.1.2",
"@types/lodash": "4.14.198",
"@types/mixpanel-browser": "2.47.1",
"@types/node": "18.17.14",
"@types/node": "18.17.15",
"@types/random-seed": "0.3.3",
"@types/skmeans": "0.11.4",
"@types/stats": "0.16.30",
Expand Down
10 changes: 5 additions & 5 deletions viewer/yarn.lock

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

0 comments on commit d90a994

Please sign in to comment.