diff --git a/packages/apps/desktop-viewer-test/src/frontend/components/routes/ViewerRoute.tsx b/packages/apps/desktop-viewer-test/src/frontend/components/routes/ViewerRoute.tsx index a5b82321..9ad8f0e4 100644 --- a/packages/apps/desktop-viewer-test/src/frontend/components/routes/ViewerRoute.tsx +++ b/packages/apps/desktop-viewer-test/src/frontend/components/routes/ViewerRoute.tsx @@ -27,7 +27,6 @@ import { useLocation } from "react-router-dom"; import { viewerRpcs } from "../../../common/ViewerConfig"; import { IModelMergeItemsProvider } from "../../extensions"; import { - getSchemaContext, unifiedSelectionStorage, } from "../../selectionStorage"; @@ -69,7 +68,7 @@ export const ViewerRoute = () => { getLabel: () => ModelsTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} selectionMode={"extended"} @@ -83,7 +82,7 @@ export const ViewerRoute = () => { getLabel: () => CategoriesTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} onPerformanceMeasured={props.onPerformanceMeasured} @@ -122,7 +121,6 @@ export const ViewerRoute = () => { ]} enablePerformanceMonitors={true} selectionStorage={unifiedSelectionStorage} - getSchemaContext={getSchemaContext} /> ) : null; }; diff --git a/packages/apps/desktop-viewer-test/src/frontend/selectionStorage.ts b/packages/apps/desktop-viewer-test/src/frontend/selectionStorage.ts index ba2a3776..a1c78c91 100644 --- a/packages/apps/desktop-viewer-test/src/frontend/selectionStorage.ts +++ b/packages/apps/desktop-viewer-test/src/frontend/selectionStorage.ts @@ -4,8 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { IModelConnection } from "@itwin/core-frontend"; -import { SchemaContext } from "@itwin/ecschema-metadata"; -import { ECSchemaRpcLocater } from "@itwin/ecschema-rpcinterface-common"; import { createStorage } from "@itwin/unified-selection"; const unifiedSelectionStorage = createStorage(); @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => { unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key }); }); -const imodelSchemaContextsCache = new Map(); - -function getSchemaContext(imodel: IModelConnection) { - let context = imodelSchemaContextsCache.get(imodel.key); - if (!context) { - context = new SchemaContext(); - context.addLocater(new ECSchemaRpcLocater(imodel.getRpcProps())); - imodelSchemaContextsCache.set(imodel.key, context); - imodel.onClose.addListener(() => { - imodelSchemaContextsCache.delete(imodel.key); - }); - } - return context; -} - -export { unifiedSelectionStorage, getSchemaContext }; +export { unifiedSelectionStorage }; diff --git a/packages/apps/web-viewer-test/src/components/home/ViewerHome.tsx b/packages/apps/web-viewer-test/src/components/home/ViewerHome.tsx index 40d555e5..0a7f382c 100644 --- a/packages/apps/web-viewer-test/src/components/home/ViewerHome.tsx +++ b/packages/apps/web-viewer-test/src/components/home/ViewerHome.tsx @@ -37,7 +37,6 @@ import React, { useCallback, useEffect, useMemo, useState } from "react"; // import { LocalExtensionProvider, RemoteExtensionProvider } from "@itwin/core-frontend"; import { ReactComponent as Itwin } from "../../images/itwin.svg"; import { - getSchemaContext, unifiedSelectionStorage, } from "../../selectionStorage"; import { history } from "../routing"; @@ -167,7 +166,7 @@ const ViewerHome: React.FC = () => { getLabel: () => ModelsTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} selectionMode={"extended"} @@ -181,7 +180,7 @@ const ViewerHome: React.FC = () => { getLabel: () => CategoriesTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} onPerformanceMeasured={props.onPerformanceMeasured} @@ -233,7 +232,6 @@ const ViewerHome: React.FC = () => { defaultUiConfig={{ cornerButton: }} // renderSys={{doIdleWork: true}} selectionStorage={unifiedSelectionStorage} - getSchemaContext={getSchemaContext} /> ); diff --git a/packages/apps/web-viewer-test/src/selectionStorage.ts b/packages/apps/web-viewer-test/src/selectionStorage.ts index ba2a3776..a1c78c91 100644 --- a/packages/apps/web-viewer-test/src/selectionStorage.ts +++ b/packages/apps/web-viewer-test/src/selectionStorage.ts @@ -4,8 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { IModelConnection } from "@itwin/core-frontend"; -import { SchemaContext } from "@itwin/ecschema-metadata"; -import { ECSchemaRpcLocater } from "@itwin/ecschema-rpcinterface-common"; import { createStorage } from "@itwin/unified-selection"; const unifiedSelectionStorage = createStorage(); @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => { unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key }); }); -const imodelSchemaContextsCache = new Map(); - -function getSchemaContext(imodel: IModelConnection) { - let context = imodelSchemaContextsCache.get(imodel.key); - if (!context) { - context = new SchemaContext(); - context.addLocater(new ECSchemaRpcLocater(imodel.getRpcProps())); - imodelSchemaContextsCache.set(imodel.key, context); - imodel.onClose.addListener(() => { - imodelSchemaContextsCache.delete(imodel.key); - }); - } - return context; -} - -export { unifiedSelectionStorage, getSchemaContext }; +export { unifiedSelectionStorage }; diff --git a/packages/modules/viewer-react/src/components/iModel/IModelLoader.tsx b/packages/modules/viewer-react/src/components/iModel/IModelLoader.tsx index fce2b1b3..16b00402 100644 --- a/packages/modules/viewer-react/src/components/iModel/IModelLoader.tsx +++ b/packages/modules/viewer-react/src/components/iModel/IModelLoader.tsx @@ -41,7 +41,6 @@ const IModelLoader = React.memo((viewerProps: ModelLoaderProps) => { // theme, loadingComponent, selectionStorage, - getSchemaContext, } = viewerProps; const { error, connection } = useConnection(viewerProps); @@ -49,7 +48,6 @@ const IModelLoader = React.memo((viewerProps: ModelLoaderProps) => { useUnifiedSelectionSync({ iModelConnection: connection, selectionStorage, - getSchemaContext, }); const { finalFrontstages, noConnectionRequired, customDefaultFrontstage } = diff --git a/packages/modules/viewer-react/src/hooks/useUnifiedSelectionSync.tsx b/packages/modules/viewer-react/src/hooks/useUnifiedSelectionSync.tsx index 7bc80308..f8dfda76 100644 --- a/packages/modules/viewer-react/src/hooks/useUnifiedSelectionSync.tsx +++ b/packages/modules/viewer-react/src/hooks/useUnifiedSelectionSync.tsx @@ -4,7 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import type { IModelConnection } from "@itwin/core-frontend"; -import type { SchemaContext } from "@itwin/ecschema-metadata"; import { createECSchemaProvider, createECSqlQueryExecutor, @@ -24,19 +23,17 @@ type SelectionScope = ReturnType< interface UseUnifiedSelectionSyncProps { iModelConnection?: IModelConnection; selectionStorage?: SelectionStorage; - getSchemaContext?: (imodel: IModelConnection) => SchemaContext; } export function useUnifiedSelectionSync({ iModelConnection, selectionStorage, - getSchemaContext, }: UseUnifiedSelectionSyncProps) { React.useEffect(() => { - if (!iModelConnection || !selectionStorage || !getSchemaContext) { + if (!iModelConnection || !selectionStorage) { return; } - const schemaContext = getSchemaContext(iModelConnection); + const { schemaContext } = iModelConnection; return enableUnifiedSelectionSyncWithIModel({ imodelAccess: { ...createECSqlQueryExecutor(iModelConnection), @@ -50,7 +47,7 @@ export function useUnifiedSelectionSync({ selectionStorage, activeScopeProvider: getActiveScope, }); - }, [iModelConnection, selectionStorage, getSchemaContext]); + }, [iModelConnection, selectionStorage]); } function getActiveScope(): SelectionScope { diff --git a/packages/modules/viewer-react/src/types.ts b/packages/modules/viewer-react/src/types.ts index fdf1ef9b..cc050640 100644 --- a/packages/modules/viewer-react/src/types.ts +++ b/packages/modules/viewer-react/src/types.ts @@ -32,7 +32,6 @@ import type { XAndY, XYAndZ, } from "@itwin/core-geometry"; -import type { SchemaContext } from "@itwin/ecschema-metadata"; import type { PresentationProps } from "@itwin/presentation-frontend"; import type { SelectionStorage } from "@itwin/unified-selection"; @@ -82,10 +81,8 @@ export interface ViewerViewportControlOptions } export interface UnifiedSelectionProps { - /** Unified selection storage to synchronize with. Requires `getSchemaContext` prop to also be supplied. */ + /** Unified selection storage to synchronize with. */ selectionStorage?: SelectionStorage; - /** Function for getting schema context for an iModel. */ - getSchemaContext?: (imodel: IModelConnection) => SchemaContext; } export interface LoaderProps { diff --git a/packages/templates/cra-template-desktop-viewer/template/src/frontend/components/routes/ViewerRoute.tsx b/packages/templates/cra-template-desktop-viewer/template/src/frontend/components/routes/ViewerRoute.tsx index ce6aca71..3a985c29 100644 --- a/packages/templates/cra-template-desktop-viewer/template/src/frontend/components/routes/ViewerRoute.tsx +++ b/packages/templates/cra-template-desktop-viewer/template/src/frontend/components/routes/ViewerRoute.tsx @@ -26,7 +26,6 @@ import { useLocation } from "react-router-dom"; import { viewerRpcs } from "../../../common/ViewerConfig"; import { - getSchemaContext, unifiedSelectionStorage, } from "../../../selectionStorage"; import { IModelMergeItemsProvider } from "../../extensions"; @@ -68,7 +67,7 @@ export const ViewerRoute = () => { getLabel: () => ModelsTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} selectionMode={"extended"} @@ -82,7 +81,7 @@ export const ViewerRoute = () => { getLabel: () => CategoriesTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} onPerformanceMeasured={props.onPerformanceMeasured} @@ -115,7 +114,7 @@ export const ViewerRoute = () => { ]} enablePerformanceMonitors={true} selectionStorage={unifiedSelectionStorage} - getSchemaContext={getSchemaContext} + getSchemaContext={(iModel) => iModel.schemaContext} /> ) : null; }; diff --git a/packages/templates/cra-template-desktop-viewer/template/src/selectionStorage.ts b/packages/templates/cra-template-desktop-viewer/template/src/selectionStorage.ts index ba2a3776..a1c78c91 100644 --- a/packages/templates/cra-template-desktop-viewer/template/src/selectionStorage.ts +++ b/packages/templates/cra-template-desktop-viewer/template/src/selectionStorage.ts @@ -4,8 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { IModelConnection } from "@itwin/core-frontend"; -import { SchemaContext } from "@itwin/ecschema-metadata"; -import { ECSchemaRpcLocater } from "@itwin/ecschema-rpcinterface-common"; import { createStorage } from "@itwin/unified-selection"; const unifiedSelectionStorage = createStorage(); @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => { unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key }); }); -const imodelSchemaContextsCache = new Map(); - -function getSchemaContext(imodel: IModelConnection) { - let context = imodelSchemaContextsCache.get(imodel.key); - if (!context) { - context = new SchemaContext(); - context.addLocater(new ECSchemaRpcLocater(imodel.getRpcProps())); - imodelSchemaContextsCache.set(imodel.key, context); - imodel.onClose.addListener(() => { - imodelSchemaContextsCache.delete(imodel.key); - }); - } - return context; -} - -export { unifiedSelectionStorage, getSchemaContext }; +export { unifiedSelectionStorage }; diff --git a/packages/templates/cra-template-web-viewer/template/src/App.tsx b/packages/templates/cra-template-web-viewer/template/src/App.tsx index c1f98413..ad8e02f3 100644 --- a/packages/templates/cra-template-web-viewer/template/src/App.tsx +++ b/packages/templates/cra-template-web-viewer/template/src/App.tsx @@ -186,7 +186,7 @@ const App: React.FC = () => { getLabel: () => ModelsTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} selectionMode={"extended"} @@ -200,7 +200,7 @@ const App: React.FC = () => { getLabel: () => CategoriesTreeComponent.getLabel(), render: (props) => ( iModel.schemaContext} density={props.density} selectionStorage={unifiedSelectionStorage} onPerformanceMeasured={props.onPerformanceMeasured} @@ -234,7 +234,7 @@ const App: React.FC = () => { new MeasureToolsUiItemsProvider(), ]} selectionStorage={unifiedSelectionStorage} - getSchemaContext={getSchemaContext} + getSchemaContext={(iModel) => iModel.schemaContext} /> ); diff --git a/packages/templates/cra-template-web-viewer/template/src/selectionStorage.ts b/packages/templates/cra-template-web-viewer/template/src/selectionStorage.ts index ba2a3776..a1c78c91 100644 --- a/packages/templates/cra-template-web-viewer/template/src/selectionStorage.ts +++ b/packages/templates/cra-template-web-viewer/template/src/selectionStorage.ts @@ -4,8 +4,6 @@ *--------------------------------------------------------------------------------------------*/ import { IModelConnection } from "@itwin/core-frontend"; -import { SchemaContext } from "@itwin/ecschema-metadata"; -import { ECSchemaRpcLocater } from "@itwin/ecschema-rpcinterface-common"; import { createStorage } from "@itwin/unified-selection"; const unifiedSelectionStorage = createStorage(); @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => { unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key }); }); -const imodelSchemaContextsCache = new Map(); - -function getSchemaContext(imodel: IModelConnection) { - let context = imodelSchemaContextsCache.get(imodel.key); - if (!context) { - context = new SchemaContext(); - context.addLocater(new ECSchemaRpcLocater(imodel.getRpcProps())); - imodelSchemaContextsCache.set(imodel.key, context); - imodel.onClose.addListener(() => { - imodelSchemaContextsCache.delete(imodel.key); - }); - } - return context; -} - -export { unifiedSelectionStorage, getSchemaContext }; +export { unifiedSelectionStorage }; diff --git a/releases/CHANGELOG-5.0.md b/releases/CHANGELOG-5.0.md index 5b3dbdec..ec1f700b 100644 --- a/releases/CHANGELOG-5.0.md +++ b/releases/CHANGELOG-5.0.md @@ -7,4 +7,7 @@ The following prop(s) have been removed from the Viewer component. - `theme` - - please wrap the Viewer component with `ThemeProvider` from `@itwin/itwinui-react` instead \ No newline at end of file + - please wrap the Viewer component with `ThemeProvider` from `@itwin/itwinui-react` instead + +- `getSchemaContext` + - schemaContext is added to iModelConnection, no longer required in props \ No newline at end of file