Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { useLocation } from "react-router-dom";
import { viewerRpcs } from "../../../common/ViewerConfig";
import { IModelMergeItemsProvider } from "../../extensions";
import {
getSchemaContext,
unifiedSelectionStorage,
} from "../../selectionStorage";

Expand Down Expand Up @@ -69,7 +68,7 @@ export const ViewerRoute = () => {
getLabel: () => ModelsTreeComponent.getLabel(),
render: (props) => (
<ModelsTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
Comment thread
grigasp marked this conversation as resolved.
density={props.density}
selectionStorage={unifiedSelectionStorage}
selectionMode={"extended"}
Expand All @@ -83,7 +82,7 @@ export const ViewerRoute = () => {
getLabel: () => CategoriesTreeComponent.getLabel(),
render: (props) => (
<CategoriesTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
onPerformanceMeasured={props.onPerformanceMeasured}
Expand Down Expand Up @@ -122,7 +121,6 @@ export const ViewerRoute = () => {
]}
enablePerformanceMonitors={true}
selectionStorage={unifiedSelectionStorage}
getSchemaContext={getSchemaContext}
/>
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => {
unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key });
});

const imodelSchemaContextsCache = new Map<string, SchemaContext>();

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 };
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -167,7 +166,7 @@ const ViewerHome: React.FC = () => {
getLabel: () => ModelsTreeComponent.getLabel(),
render: (props) => (
<ModelsTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
selectionMode={"extended"}
Expand All @@ -181,7 +180,7 @@ const ViewerHome: React.FC = () => {
getLabel: () => CategoriesTreeComponent.getLabel(),
render: (props) => (
<CategoriesTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
onPerformanceMeasured={props.onPerformanceMeasured}
Expand Down Expand Up @@ -233,7 +232,6 @@ const ViewerHome: React.FC = () => {
defaultUiConfig={{ cornerButton: <Itwin /> }}
// renderSys={{doIdleWork: true}}
selectionStorage={unifiedSelectionStorage}
getSchemaContext={getSchemaContext}
/>
</div>
);
Expand Down
19 changes: 1 addition & 18 deletions packages/apps/web-viewer-test/src/selectionStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => {
unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key });
});

const imodelSchemaContextsCache = new Map<string, SchemaContext>();

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 };
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ const IModelLoader = React.memo((viewerProps: ModelLoaderProps) => {
// theme,
loadingComponent,
selectionStorage,
getSchemaContext,
} = viewerProps;
const { error, connection } = useConnection(viewerProps);

useUiProviders(uiProviders);
useUnifiedSelectionSync({
iModelConnection: connection,
selectionStorage,
getSchemaContext,
});

const { finalFrontstages, noConnectionRequired, customDefaultFrontstage } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import type { IModelConnection } from "@itwin/core-frontend";
import type { SchemaContext } from "@itwin/ecschema-metadata";
import {
createECSchemaProvider,
createECSqlQueryExecutor,
Expand All @@ -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),
Expand All @@ -50,7 +47,7 @@ export function useUnifiedSelectionSync({
selectionStorage,
activeScopeProvider: getActiveScope,
});
}, [iModelConnection, selectionStorage, getSchemaContext]);
}, [iModelConnection, selectionStorage]);
}

function getActiveScope(): SelectionScope {
Expand Down
5 changes: 1 addition & 4 deletions packages/modules/viewer-react/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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;
Comment thread
aruniverse marked this conversation as resolved.
}

export interface LoaderProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { useLocation } from "react-router-dom";

import { viewerRpcs } from "../../../common/ViewerConfig";
import {
getSchemaContext,
unifiedSelectionStorage,
} from "../../../selectionStorage";
import { IModelMergeItemsProvider } from "../../extensions";
Expand Down Expand Up @@ -68,7 +67,7 @@ export const ViewerRoute = () => {
getLabel: () => ModelsTreeComponent.getLabel(),
render: (props) => (
<ModelsTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
selectionMode={"extended"}
Expand All @@ -82,7 +81,7 @@ export const ViewerRoute = () => {
getLabel: () => CategoriesTreeComponent.getLabel(),
render: (props) => (
<CategoriesTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
onPerformanceMeasured={props.onPerformanceMeasured}
Expand Down Expand Up @@ -115,7 +114,7 @@ export const ViewerRoute = () => {
]}
enablePerformanceMonitors={true}
selectionStorage={unifiedSelectionStorage}
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this prop was removed from Viewer in this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. that is right

/>
) : null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => {
unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key });
});

const imodelSchemaContextsCache = new Map<string, SchemaContext>();

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 };
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const App: React.FC = () => {
getLabel: () => ModelsTreeComponent.getLabel(),
render: (props) => (
<ModelsTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
selectionMode={"extended"}
Expand All @@ -200,7 +200,7 @@ const App: React.FC = () => {
getLabel: () => CategoriesTreeComponent.getLabel(),
render: (props) => (
<CategoriesTreeComponent
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
density={props.density}
selectionStorage={unifiedSelectionStorage}
onPerformanceMeasured={props.onPerformanceMeasured}
Expand Down Expand Up @@ -234,7 +234,7 @@ const App: React.FC = () => {
new MeasureToolsUiItemsProvider(),
]}
selectionStorage={unifiedSelectionStorage}
getSchemaContext={getSchemaContext}
getSchemaContext={(iModel) => iModel.schemaContext}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this prop was removed from Viewer in this PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that is right.

/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -14,19 +12,4 @@ IModelConnection.onClose.addListener((imodel) => {
unifiedSelectionStorage.clearStorage({ imodelKey: imodel.key });
});

const imodelSchemaContextsCache = new Map<string, SchemaContext>();

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 };
5 changes: 4 additions & 1 deletion releases/CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- please wrap the Viewer component with `ThemeProvider` from `@itwin/itwinui-react` instead

- `getSchemaContext`
- schemaContext is added to iModelConnection, no longer required in props
Loading