Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presentation: Introduce nth level element selection scope support #3743

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions common/api/presentation-backend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { RegisteredRuleset } from '@bentley/presentation-common';
import { Ruleset } from '@bentley/presentation-common';
import { SelectionInfo } from '@bentley/presentation-common';
import { SelectionScope } from '@bentley/presentation-common';
import { SelectionScopeParams } from '@bentley/presentation-common';
import { SelectionScopeRequestOptions } from '@bentley/presentation-common';
import { UpdateInfoJSON } from '@bentley/presentation-common';
import { VariableValue } from '@bentley/presentation-common';
Expand Down Expand Up @@ -162,6 +163,7 @@ export class PresentationManager {
computeSelection(requestOptions: WithClientRequestContext<SelectionScopeRequestOptions<IModelDb> & {
ids: Id64String[];
scopeId: string;
scopeParams?: SelectionScopeParams;
}>): Promise<KeySet>;
dispose(): void;
// @deprecated
Expand Down
26 changes: 24 additions & 2 deletions common/api/presentation-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,19 @@ export type CompressedDescriptorJSON = Omit<DescriptorJSON, "selectClasses" | "f
// @public
export type ComputeDisplayValueCallback = (type: string, value: PrimitivePropertyValue, displayValue: string) => Promise<string>;

// @alpha (undocumented)
export interface ComputeElementSelectionScopeProps {
// (undocumented)
id: "element";
// (undocumented)
params?: ElementSelectionScopeParams;
}

// @alpha (undocumented)
export type ComputeSelectionScopeProps = ComputeElementSelectionScopeProps | {
id: string;
};

// @public
export interface ConditionContainer {
condition?: string;
Expand Down Expand Up @@ -837,6 +850,12 @@ export interface ElementPropertiesStructPropertyItem extends ElementPropertiesPr
type: "struct";
}

// @alpha (undocumented)
export interface ElementSelectionScopeParams {
// (undocumented)
level?: number;
}

// @public
export interface EnumerationChoice {
label: string;
Expand Down Expand Up @@ -1962,7 +1981,7 @@ export class PresentationRpcInterface extends RpcInterface {
// (undocumented)
compareHierarchiesPaged(_token: IModelRpcProps, _options: HierarchyCompareRpcOptions): PresentationRpcResponse<HierarchyCompareInfoJSON>;
// (undocumented)
computeSelection(_token: IModelRpcProps, _options: SelectionScopeRpcRequestOptions, _ids: Id64String[], _scopeId: string): PresentationRpcResponse<KeySetJSON>;
computeSelection(_token: IModelRpcProps, _options: SelectionScopeRpcRequestOptions, _ids: Id64String[], _scopeId: string, _scopeParams?: any): PresentationRpcResponse<KeySetJSON>;
// @deprecated (undocumented)
getContent(_token: IModelRpcProps, _options: ContentRpcRequestOptions, _descriptorOrOverrides: DescriptorJSON | DescriptorOverrides, _keys: KeySetJSON): PresentationRpcResponse<ContentJSON | undefined>;
// @deprecated (undocumented)
Expand Down Expand Up @@ -2550,7 +2569,7 @@ export class RpcRequestsHandler implements IDisposable {
// (undocumented)
compareHierarchiesPaged(options: HierarchyCompareOptions<IModelRpcProps, NodeKeyJSON, RulesetVariableJSON>): Promise<HierarchyCompareInfoJSON>;
// (undocumented)
computeSelection(options: SelectionScopeRequestOptions<IModelRpcProps>, ids: Id64String[], scopeId: string): Promise<KeySetJSON>;
computeSelection(options: SelectionScopeRequestOptions<IModelRpcProps>, ids: Id64String[], scopeId: string, scopeParams?: SelectionScopeParams): Promise<KeySetJSON>;
// (undocumented)
dispose(): void;
// (undocumented)
Expand Down Expand Up @@ -2767,6 +2786,9 @@ export interface SelectionScope {
label: string;
}

// @alpha (undocumented)
export type SelectionScopeParams = ElementSelectionScopeParams;

// @public
export interface SelectionScopeRequestOptions<TIModel> extends RequestOptions<TIModel> {
}
Expand Down
22 changes: 15 additions & 7 deletions common/api/presentation-frontend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
```ts

import { BeEvent } from '@bentley/bentleyjs-core';
import { ComputeSelectionScopeProps } from '@bentley/presentation-common';
import { Content } from '@bentley/presentation-common';
import { ContentDescriptorRequestOptions } from '@bentley/presentation-common';
import { ContentRequestOptions } from '@bentley/presentation-common';
Expand Down Expand Up @@ -51,6 +52,7 @@ import { Ruleset } from '@bentley/presentation-common';
import { RulesetVariable } from '@bentley/presentation-common';
import { SelectionInfo } from '@bentley/presentation-common';
import { SelectionScope } from '@bentley/presentation-common';
import { SelectionScopeParams } from '@bentley/presentation-common';
import { SetRulesetVariableParams } from '@bentley/presentation-common';
import { UnsetRulesetVariableParams } from '@bentley/presentation-common';
import { UpdateHierarchyStateParams } from '@bentley/presentation-common';
Expand Down Expand Up @@ -123,9 +125,15 @@ export enum FavoritePropertiesScope {
// @internal (undocumented)
export const getFieldInfos: (field: Field) => Set<PropertyFullName>;

// @public
// @public @deprecated
export function getScopeId(scope: SelectionScope | string | undefined): string;

// @internal
export function getScopeRequestProps(scope: ComputeSelectionScopeProps | SelectionScope | string | undefined): {
id: string;
params?: SelectionScopeParams;
};

// @internal (undocumented)
export const HILITE_RULESET: Ruleset;

Expand Down Expand Up @@ -477,15 +485,15 @@ export class SelectionHelper {
export class SelectionManager implements ISelectionProvider {
constructor(props: SelectionManagerProps);
addToSelection(source: string, imodel: IModelConnection, keys: Keys, level?: number, rulesetId?: string): void;
addToSelectionWithScope(source: string, imodel: IModelConnection, ids: Id64Arg, scope: SelectionScope | string, level?: number, rulesetId?: string): Promise<void>;
addToSelectionWithScope(source: string, imodel: IModelConnection, ids: Id64Arg, scope: ComputeSelectionScopeProps | SelectionScope | string, level?: number, rulesetId?: string): Promise<void>;
clearSelection(source: string, imodel: IModelConnection, level?: number, rulesetId?: string): void;
getHiliteSet(imodel: IModelConnection): Promise<HiliteSet>;
getSelection(imodel: IModelConnection, level?: number): Readonly<KeySet>;
getSelectionLevels(imodel: IModelConnection): number[];
removeFromSelection(source: string, imodel: IModelConnection, keys: Keys, level?: number, rulesetId?: string): void;
removeFromSelectionWithScope(source: string, imodel: IModelConnection, ids: Id64Arg, scope: SelectionScope | string, level?: number, rulesetId?: string): Promise<void>;
removeFromSelectionWithScope(source: string, imodel: IModelConnection, ids: Id64Arg, scope: ComputeSelectionScopeProps | SelectionScope | string, level?: number, rulesetId?: string): Promise<void>;
replaceSelection(source: string, imodel: IModelConnection, keys: Keys, level?: number, rulesetId?: string): void;
replaceSelectionWithScope(source: string, imodel: IModelConnection, ids: Id64Arg, scope: SelectionScope | string, level?: number, rulesetId?: string): Promise<void>;
replaceSelectionWithScope(source: string, imodel: IModelConnection, ids: Id64Arg, scope: ComputeSelectionScopeProps | SelectionScope | string, level?: number, rulesetId?: string): Promise<void>;
readonly scopes: SelectionScopesManager;
readonly selectionChange: SelectionChangeEvent;
setSyncWithIModelToolSelection(imodel: IModelConnection, sync?: boolean): void;
Expand All @@ -501,9 +509,9 @@ export interface SelectionManagerProps {
export class SelectionScopesManager {
constructor(props: SelectionScopesManagerProps);
get activeLocale(): string | undefined;
get activeScope(): SelectionScope | string | undefined;
set activeScope(scope: SelectionScope | string | undefined);
computeSelection(imodel: IModelConnection, ids: Id64Arg, scope: SelectionScope | string): Promise<KeySet>;
get activeScope(): ComputeSelectionScopeProps | SelectionScope | string | undefined;
set activeScope(scope: ComputeSelectionScopeProps | SelectionScope | string | undefined);
computeSelection(imodel: IModelConnection, ids: Id64Arg, scope: ComputeSelectionScopeProps | SelectionScope | string): Promise<KeySet>;
getSelectionScopes(imodel: IModelConnection, locale?: string): Promise<SelectionScope[]>;
}

Expand Down
4 changes: 4 additions & 0 deletions common/api/summary/presentation-common.exports.csv
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal;CommonIpcParams
public;CompressedClassInfoJSON
public;CompressedDescriptorJSON = Omit
public;ComputeDisplayValueCallback = (type: string, value: PrimitivePropertyValue, displayValue: string) => Promise
alpha;ComputeElementSelectionScopeProps
alpha;ComputeSelectionScopeProps = ComputeElementSelectionScopeProps |
public;ConditionContainer
public;Content
public;ContentDescriptorRequestOptions
Expand Down Expand Up @@ -120,6 +122,7 @@ beta;ElementPropertiesRequestOptions
beta;ElementPropertiesRpcRequestOptions = PresentationRpcRequestOptions
beta;ElementPropertiesStructArrayPropertyItem
beta;ElementPropertiesStructPropertyItem
alpha;ElementSelectionScopeParams
public;EnumerationChoice
public;EnumerationInfo
alpha;ExpandedNodeUpdateRecord
Expand Down Expand Up @@ -366,6 +369,7 @@ public;SelectClassInfoJSON
public;SelectedNodeInstancesSpecification
public;SelectionInfo
public;SelectionScope
alpha;SelectionScopeParams = ElementSelectionScopeParams
public;SelectionScopeRequestOptions
public;SelectionScopeRpcRequestOptions = PresentationRpcRequestOptions
internal;SetRulesetVariableParams
Expand Down
2 changes: 2 additions & 0 deletions common/api/summary/presentation-frontend.exports.csv
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public;FavoritePropertiesOrderInfo
public;FavoritePropertiesScope
internal;getFieldInfos: (field: Field) => Set
public;getScopeId(scope: SelectionScope | string | undefined): string
deprecated;getScopeId(scope: SelectionScope | string | undefined): string
internal;getScopeRequestProps(scope: ComputeSelectionScopeProps | SelectionScope | string | undefined):
internal;HILITE_RULESET: Ruleset
public;HiliteSet
public;HiliteSetProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@bentley/presentation-backend",
"comment": "Add support for nth level element selection scopes.",
"type": "none"
}
],
"packageName": "@bentley/presentation-backend",
"email": "35135765+grigasp@users.noreply.github.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@bentley/presentation-common",
"comment": "Add support for nth level element selection scopes.",
"type": "none"
}
],
"packageName": "@bentley/presentation-common",
"email": "35135765+grigasp@users.noreply.github.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@bentley/presentation-components",
"comment": "",
"type": "none"
}
],
"packageName": "@bentley/presentation-components",
"email": "35135765+grigasp@users.noreply.github.com"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@bentley/presentation-frontend",
"comment": "Add support for nth level element selection scopes.",
"type": "none"
}
],
"packageName": "@bentley/presentation-frontend",
"email": "35135765+grigasp@users.noreply.github.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ describe("Selection Scopes", () => {
expect(selection.has({ className: elementProps[0].classFullName, id: elementProps[0].id! }));
});

it("sets correct selection with 'element' 1st parent level selection scope", async () => {
const elementProps = await imodel.elements.getProps(Id64.fromUint32Pair(28, 0));
await Presentation.selection.addToSelectionWithScope("", imodel, elementProps[0].id!, { id: "element", params: { level: 1 } });
const selection = Presentation.selection.getSelection(imodel);
expect(selection.size).to.eq(1);
expect(selection.has({ className: "BisCore:Subject", id: Id64.fromUint32Pair(27, 0) }));
});

it("sets correct selection with 'assembly' selection scope", async () => {
const elementProps = await imodel.elements.getProps(Id64.fromUint32Pair(28, 0));
await Presentation.selection.addToSelectionWithScope("", imodel, elementProps[0].id!, "assembly");
Expand All @@ -49,6 +57,22 @@ describe("Selection Scopes", () => {
expect(selection.has({ className: "BisCore:Subject", id: Id64.fromUint32Pair(27, 0) }));
});

it("sets correct selection with 'element' 2nd parent level selection scope", async () => {
const elementProps = await imodel.elements.getProps(Id64.fromUint32Pair(28, 0));
await Presentation.selection.addToSelectionWithScope("", imodel, elementProps[0].id!, { id: "element", params: { level: 2 } });
const selection = Presentation.selection.getSelection(imodel);
expect(selection.size).to.eq(1);
expect(selection.has({ className: "BisCore:Subject", id: Id64.fromUint32Pair(1, 0) }));
});

it("sets correct selection with 'element' exceeding parent level selection scope", async () => {
const elementProps = await imodel.elements.getProps(Id64.fromUint32Pair(28, 0));
await Presentation.selection.addToSelectionWithScope("", imodel, elementProps[0].id!, { id: "element", params: { level: 999 } });
const selection = Presentation.selection.getSelection(imodel);
expect(selection.size).to.eq(1);
expect(selection.has({ className: "BisCore:Subject", id: Id64.fromUint32Pair(1, 0) }));
});

it("sets correct selection with 'top-assembly' selection scope", async () => {
const elementProps = await imodel.elements.getProps(Id64.fromUint32Pair(28, 0));
await Presentation.selection.addToSelectionWithScope("", imodel, elementProps[0].id!, "top-assembly");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ElementProperties, ElementPropertiesRequestOptions, ExtendedContentRequestOptions, ExtendedHierarchyRequestOptions, getLocalesDirectory,
HierarchyCompareInfo, HierarchyCompareOptions, HierarchyRequestOptions, InstanceKey, KeySet, LabelDefinition, LabelRequestOptions, Node, NodeKey,
NodePathElement, Paged, PagedResponse, PartialHierarchyModification, PresentationError, PresentationStatus, PresentationUnitSystem, RequestPriority,
Ruleset, SelectionInfo, SelectionScope, SelectionScopeRequestOptions,
Ruleset, SelectionInfo, SelectionScope, SelectionScopeParams, SelectionScopeRequestOptions,
} from "@bentley/presentation-common";
import { PresentationBackendLoggerCategory } from "./BackendLoggerCategory";
import { PRESENTATION_BACKEND_ASSETS_ROOT, PRESENTATION_COMMON_ASSETS_ROOT } from "./Constants";
Expand Down Expand Up @@ -901,13 +901,13 @@ export class PresentationManager {
* Computes selection set based on provided selection scope.
* @public
*/
public async computeSelection(requestOptions: WithClientRequestContext<SelectionScopeRequestOptions<IModelDb> & { ids: Id64String[], scopeId: string }>): Promise<KeySet>;
public async computeSelection(requestContextOrOptions: ClientRequestContext | WithClientRequestContext<SelectionScopeRequestOptions<IModelDb> & { ids: Id64String[], scopeId: string }>, deprecatedRequestOptions?: SelectionScopeRequestOptions<IModelDb>, deprecatedIds?: Id64String[], deprecatedScopeId?: string): Promise<KeySet> {
public async computeSelection(requestOptions: WithClientRequestContext<SelectionScopeRequestOptions<IModelDb> & { ids: Id64String[], scopeId: string, scopeParams?: SelectionScopeParams }>): Promise<KeySet>;
public async computeSelection(requestContextOrOptions: ClientRequestContext | WithClientRequestContext<SelectionScopeRequestOptions<IModelDb> & { ids: Id64String[], scopeId: string, scopeParams?: SelectionScopeParams }>, deprecatedRequestOptions?: SelectionScopeRequestOptions<IModelDb>, deprecatedIds?: Id64String[], deprecatedScopeId?: string): Promise<KeySet> {
if (requestContextOrOptions instanceof ClientRequestContext) {
return this.computeSelection({ ...deprecatedRequestOptions!, requestContext: requestContextOrOptions, ids: deprecatedIds!, scopeId: deprecatedScopeId! });
}
const { requestContext, ids, scopeId, ...requestOptions } = requestContextOrOptions; // eslint-disable-line @typescript-eslint/no-unused-vars
return SelectionScopesHelper.computeSelection(requestOptions, ids, scopeId);
const { requestContext, ids, scopeId, scopeParams, ...requestOptions } = requestContextOrOptions; // eslint-disable-line @typescript-eslint/no-unused-vars
return SelectionScopesHelper.computeSelection(requestOptions, ids, scopeId, scopeParams);
}

private async request<TParams extends { requestContext: ClientRequestContext, diagnostics?: DiagnosticsOptionsWithHandler, requestId: string, imodel: IModelDb, locale?: string, unitSystem?: PresentationUnitSystem }, TResult>(params: TParams, reviver?: (key: string, value: any) => any): Promise<TResult> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
isExtendedHierarchyRequestOptions, ItemJSON, KeySet, KeySetJSON, LabelDefinition, LabelDefinitionJSON, LabelRpcRequestOptions, Node, NodeJSON,
NodeKey, NodeKeyJSON, NodePathElement, NodePathElementJSON, Paged, PagedResponse, PageOptions, PartialHierarchyModification,
PartialHierarchyModificationJSON, PresentationError, PresentationRpcInterface, PresentationRpcResponse, PresentationStatus, Ruleset,
RulesetVariable, RulesetVariableJSON, SelectionInfo, SelectionScope, SelectionScopeRpcRequestOptions,
RulesetVariable, RulesetVariableJSON, SelectionInfo, SelectionScope, SelectionScopeParams, SelectionScopeRpcRequestOptions,
} from "@bentley/presentation-common";
import { PresentationBackendLoggerCategory } from "./BackendLoggerCategory";
import { Presentation } from "./Presentation";
Expand Down Expand Up @@ -369,8 +369,8 @@ export class PresentationRpcImpl extends PresentationRpcInterface {
);
}

public override async computeSelection(token: IModelRpcProps, requestOptions: SelectionScopeRpcRequestOptions, ids: Id64String[], scopeId: string): PresentationRpcResponse<KeySetJSON> {
return this.makeRequest(token, "computeSelection", { ...requestOptions, ids, scopeId }, async (options) => {
public override async computeSelection(token: IModelRpcProps, requestOptions: SelectionScopeRpcRequestOptions, ids: Id64String[], scopeId: string, scopeParams?: SelectionScopeParams): PresentationRpcResponse<KeySetJSON> {
return this.makeRequest(token, "computeSelection", { ...requestOptions, ids, scopeId, scopeParams }, async (options) => {
const keys = await this.getManager(requestOptions.clientId).computeSelection(options);
return keys.toJSON();
});
Expand Down
Loading