Skip to content

Commit

Permalink
Presentation: getElementProperties RPC (iTwin#1508)
Browse files Browse the repository at this point in the history
* Make `PresentationUnitSystem` @beta

* Extract logic for traversing presentation content

* Add `PresentationRpcInterface.getElementProperties`

* Add rpc full stack test for `PresentationRpcInterface.getElementProperties`

* cleanup

* Add `ElementPropertiesRequestOptions` for non-RPC requests

* Add `PresentationManager.getElementProperties` on the backend

* Add missing change file for `rpcinterface-full-stack-tests`

* Add `PresentationManager.getElementProperties` on the frontend

* Improve test and fix PresentationTableDataProvider
  • Loading branch information
grigasp authored Jun 11, 2021
1 parent d269f1c commit f3b22c5
Show file tree
Hide file tree
Showing 62 changed files with 4,261 additions and 3,020 deletions.
8 changes: 6 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,12 @@
"program": "${workspaceFolder}/presentation/testing/node_modules/mocha/bin/_mocha",
"args": [
"--config",
".mocharc.json",
"../.mocharc.json",
"--no-timeouts",
"-r",
"ignore-styles",
"-r",
"jsdom-global/register",
"lib/test/**/*.test.js"
],
"outFiles": [
Expand Down Expand Up @@ -1857,4 +1861,4 @@
]
}
]
}
}
4 changes: 4 additions & 0 deletions common/api/presentation-backend.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { DisplayLabelRequestOptions } from '@bentley/presentation-common';
import { DisplayLabelsRequestOptions } from '@bentley/presentation-common';
import { DisplayValueGroup } from '@bentley/presentation-common';
import { DistinctValuesRequestOptions } from '@bentley/presentation-common';
import { ElementProperties } from '@bentley/presentation-common';
import { ElementPropertiesRequestOptions } from '@bentley/presentation-common';
import { ExtendedContentRequestOptions } from '@bentley/presentation-common';
import { ExtendedHierarchyRequestOptions } from '@bentley/presentation-common';
import { FormatProps } from '@bentley/imodeljs-quantity';
Expand Down Expand Up @@ -184,6 +186,8 @@ export class PresentationManager {
getDisplayLabelDefinitions(requestOptions: WithClientRequestContext<Paged<DisplayLabelsRequestOptions<IModelDb, InstanceKey>>>): Promise<LabelDefinition[]>;
// @deprecated
getDistinctValues(requestContext: ClientRequestContext, requestOptions: ContentRequestOptions<IModelDb>, descriptor: Descriptor | DescriptorOverrides, keys: KeySet, fieldName: string, maximumValueCount?: number): Promise<string[]>;
// @beta
getElementProperties(requestOptions: WithClientRequestContext<ElementPropertiesRequestOptions<IModelDb>>): Promise<ElementProperties | undefined>;
// @deprecated
getFilteredNodePaths(requestContext: ClientRequestContext, requestOptions: HierarchyRequestOptions<IModelDb>, filterText: string): Promise<NodePathElement[]>;
getFilteredNodePaths(requestOptions: WithClientRequestContext<HierarchyRequestOptions<IModelDb> & {
Expand Down
236 changes: 234 additions & 2 deletions common/api/presentation-common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import { IModelRpcProps } from '@bentley/imodeljs-common';
import { LogFunction } from '@bentley/bentleyjs-core';
import { RpcInterface } from '@bentley/imodeljs-common';

// @alpha (undocumented)
export function addFieldHierarchy(rootHierarchies: FieldHierarchy[], hierarchy: FieldHierarchy): void;

// @internal (undocumented)
export function applyOptionalPrefix(str: string, prefix?: string): string;

// @public
export interface ArrayTypeDescription extends BaseTypeDescription {
memberType: TypeDescription;
Expand Down Expand Up @@ -726,6 +732,88 @@ export interface EditorDescription {
params: any;
}

// @beta
export interface ElementProperties {
class: string;
id: Id64String;
items: {
[label: string]: ElementPropertiesItem;
};
label: string;
}

// @beta
export type ElementPropertiesArrayPropertyItem = ElementPropertiesPrimitiveArrayPropertyItem | ElementPropertiesStructArrayPropertyItem;

// @beta
export interface ElementPropertiesArrayPropertyItemBase extends ElementPropertiesPropertyItemBase {
type: "array";
valueType: "primitive" | "struct";
}

// @beta
export interface ElementPropertiesCategoryItem extends ElementPropertiesItemBase {
items: {
[label: string]: ElementPropertiesItem;
};
type: "category";
}

// @beta
export type ElementPropertiesItem = ElementPropertiesCategoryItem | ElementPropertiesPropertyItem;

// @beta
export interface ElementPropertiesItemBase {
type: "category" | ElementPropertiesPropertyValueType;
}

// @beta
export interface ElementPropertiesPrimitiveArrayPropertyItem extends ElementPropertiesArrayPropertyItemBase {
values: string[];
valueType: "primitive";
}

// @beta
export interface ElementPropertiesPrimitivePropertyItem extends ElementPropertiesPropertyItemBase {
type: "primitive";
value: string;
}

// @beta
export type ElementPropertiesPropertyItem = ElementPropertiesPrimitivePropertyItem | ElementPropertiesArrayPropertyItem | ElementPropertiesStructPropertyItem;

// @beta
export interface ElementPropertiesPropertyItemBase extends ElementPropertiesItemBase {
type: ElementPropertiesPropertyValueType;
}

// @beta
export type ElementPropertiesPropertyValueType = "primitive" | "array" | "struct";

// @beta
export interface ElementPropertiesRequestOptions<TIModel> extends RequestOptions<TIModel> {
elementId: Id64String;
}

// @beta
export type ElementPropertiesRpcRequestOptions = PresentationRpcRequestOptions<ElementPropertiesRequestOptions<never>>;

// @beta
export interface ElementPropertiesStructArrayPropertyItem extends ElementPropertiesArrayPropertyItemBase {
values: Array<{
[memberLabel: string]: ElementPropertiesPropertyItem;
}>;
valueType: "struct";
}

// @beta
export interface ElementPropertiesStructPropertyItem extends ElementPropertiesPropertyItemBase {
members: {
[memberLabel: string]: ElementPropertiesPropertyItem;
};
type: "struct";
}

// @public
export interface EnumerationChoice {
label: string;
Expand Down Expand Up @@ -817,6 +905,9 @@ export class Field {
type: TypeDescription;
}

// @internal (undocumented)
export const FIELD_NAMES_SEPARATOR = "$";

// @public
export type FieldDescriptor = NamedFieldDescriptor | PropertiesFieldDescriptor;

Expand All @@ -840,6 +931,14 @@ export enum FieldDescriptorType {
Properties = "properties"
}

// @alpha (undocumented)
export interface FieldHierarchy {
// (undocumented)
childFields: FieldHierarchy[];
// (undocumented)
field: Field;
}

// @public
export type FieldJSON = BaseFieldJSON | PropertiesFieldJSON | NestedContentFieldJSON;

Expand Down Expand Up @@ -975,6 +1074,40 @@ export interface HierarchyUpdateRecordJSON {
parent?: NodeKeyJSON;
}

// @alpha (undocumented)
export interface IContentVisitor {
// (undocumented)
finishArray(): void;
// (undocumented)
finishCategory(): void;
// (undocumented)
finishContent(): void;
// (undocumented)
finishField(): void;
// (undocumented)
finishItem(): void;
// (undocumented)
finishStruct(): void;
// (undocumented)
processFieldHierarchies(props: ProcessFieldHierarchiesProps): void;
// (undocumented)
processMergedValue(props: ProcessMergedValueProps): void;
// (undocumented)
processPrimitiveValue(props: ProcessPrimitiveValueProps): void;
// (undocumented)
startArray(props: StartArrayProps): boolean;
// (undocumented)
startCategory(props: StartCategoryProps): boolean;
// (undocumented)
startContent(props: StartContentProps): boolean;
// (undocumented)
startField(props: StartFieldProps): boolean;
// (undocumented)
startItem(props: StartItemProps): boolean;
// (undocumented)
startStruct(props: StartStructProps): boolean;
}

// @public
export interface Id64RulesetVariable extends RulesetVariableBase {
// (undocumented)
Expand Down Expand Up @@ -1803,6 +1936,8 @@ export class PresentationRpcInterface extends RpcInterface {
getDisplayLabelDefinitions(_token: IModelRpcProps, _options: LabelRpcRequestOptions, _keys: InstanceKeyJSON[]): PresentationRpcResponse<LabelDefinitionJSON[]>;
// @deprecated (undocumented)
getDistinctValues(_token: IModelRpcProps, _options: ContentRpcRequestOptions, _descriptor: DescriptorJSON | DescriptorOverrides, _keys: KeySetJSON, _fieldName: string, _maximumValueCount: number): PresentationRpcResponse<string[]>;
// @beta (undocumented)
getElementProperties(_token: IModelRpcProps, _options: ElementPropertiesRpcRequestOptions): PresentationRpcResponse<ElementProperties>;
// (undocumented)
getFilteredNodePaths(_token: IModelRpcProps, _options: Omit<ExtendedHierarchyRpcRequestOptions, "parentKey">, _filterText: string): PresentationRpcResponse<NodePathElementJSON[]>;
// (undocumented)
Expand Down Expand Up @@ -1855,19 +1990,23 @@ export type PresentationRpcResponse<TResult = undefined> = Promise<{

// @public
export enum PresentationStatus {
// @deprecated
BackendOutOfSync = 65542,
BackendTimeout = 65543,
Canceled = 1,
Error = 65536,
InvalidArgument = 65539,
// @deprecated
InvalidResponse = 65540,
// @deprecated
NoContent = 65541,
NotInitialized = 65537,
Success = 0,
// @deprecated
UseAfterDisposal = 65538
}

// @alpha (undocumented)
// @beta
export enum PresentationUnitSystem {
// (undocumented)
BritishImperial = "british-imperial",
Expand All @@ -1887,6 +2026,36 @@ export interface PrimitiveTypeDescription extends BaseTypeDescription {
valueFormat: PropertyValueFormat.Primitive;
}

// @alpha (undocumented)
export interface ProcessFieldHierarchiesProps {
// (undocumented)
hierarchies: FieldHierarchy[];
}

// @alpha (undocumented)
export interface ProcessMergedValueProps {
// (undocumented)
mergedField: Field;
// (undocumented)
namePrefix?: string;
// (undocumented)
requestedField: Field;
}

// @alpha (undocumented)
export interface ProcessPrimitiveValueProps {
// (undocumented)
displayValue: DisplayValue;
// (undocumented)
field: Field;
// (undocumented)
namePrefix?: string;
// (undocumented)
rawValue: Value;
// (undocumented)
valueType: TypeDescription;
}

// @public
export class PropertiesField extends Field {
constructor(category: CategoryDescription, name: string, label: string, description: TypeDescription, isReadonly: boolean, priority: number, properties: Property[], editor?: EditorDescription, renderer?: RendererDescription);
Expand Down Expand Up @@ -2273,7 +2442,7 @@ export interface RequestOptions<TIModel> {
imodel: TIModel;
locale?: string;
priority?: number;
// @alpha
// @beta
unitSystem?: PresentationUnitSystem;
}

Expand Down Expand Up @@ -2322,6 +2491,8 @@ export class RpcRequestsHandler implements IDisposable {
// (undocumented)
getDisplayLabelDefinition(options: DisplayLabelRequestOptions<IModelRpcProps, InstanceKeyJSON>): Promise<LabelDefinitionJSON>;
// (undocumented)
getElementProperties(options: ElementPropertiesRequestOptions<IModelRpcProps>): Promise<ElementProperties | undefined>;
// (undocumented)
getFilteredNodePaths(options: ExtendedHierarchyRequestOptions<IModelRpcProps, never, RulesetVariableJSON>, filterText: string): Promise<NodePathElementJSON[]>;
// (undocumented)
getNodePaths(options: ExtendedHierarchyRequestOptions<IModelRpcProps, never, RulesetVariableJSON>, paths: InstanceKeyJSON[][], markedIndex: number): Promise<NodePathElementJSON[]>;
Expand Down Expand Up @@ -2572,6 +2743,58 @@ export enum StandardNodeTypes {
ECPropertyGroupingNode = "ECPropertyGroupingNode"
}

// @alpha (undocumented)
export interface StartArrayProps {
// (undocumented)
displayValues: DisplayValuesArray;
// (undocumented)
hierarchy: FieldHierarchy;
// (undocumented)
namePrefix?: string;
// (undocumented)
rawValues: ValuesArray;
// (undocumented)
valueType: TypeDescription;
}

// @alpha (undocumented)
export interface StartCategoryProps {
// (undocumented)
category: CategoryDescription;
}

// @alpha (undocumented)
export interface StartContentProps {
// (undocumented)
descriptor: Descriptor;
}

// @alpha (undocumented)
export interface StartFieldProps {
// (undocumented)
hierarchy: FieldHierarchy;
}

// @alpha (undocumented)
export interface StartItemProps {
// (undocumented)
item: Item;
}

// @alpha (undocumented)
export interface StartStructProps {
// (undocumented)
displayValues: DisplayValuesMap;
// (undocumented)
hierarchy: FieldHierarchy;
// (undocumented)
namePrefix?: string;
// (undocumented)
rawValues: ValuesMap;
// (undocumented)
valueType: TypeDescription;
}

// @public
export interface StringQuerySpecification extends QuerySpecificationBase {
query: string;
Expand Down Expand Up @@ -2648,6 +2871,15 @@ export interface SupplementationInfo {
supplementationPurpose: string;
}

// @alpha (undocumented)
export function traverseContent(visitor: IContentVisitor, content: Content): void;

// @alpha (undocumented)
export function traverseContentItem(visitor: IContentVisitor, descriptor: Descriptor, item: Item): void;

// @internal (undocumented)
export function traverseFieldHierarchy(hierarchy: FieldHierarchy, cb: (h: FieldHierarchy) => boolean): void;

// @public
export type TypeDescription = PrimitiveTypeDescription | ArrayTypeDescription | StructTypeDescription;

Expand Down
Loading

0 comments on commit f3b22c5

Please sign in to comment.