UNPKG

@itwin/presentation-components

Version:

React components based on iTwin.js Presentation library

213 lines 8.62 kB
/** @packageDocumentation * @module Core */ import "./DisposePolyfill.js"; import { PropertyDescription, PropertyRecord } from "@itwin/appui-abstract"; import { IModelConnection } from "@itwin/core-frontend"; import { Content, Descriptor, DescriptorOverrides, Field, KeySet, PageOptions, Ruleset, SelectionInfo } from "@itwin/presentation-common"; import { DiagnosticsProps } from "./Diagnostics.js"; import { IPresentationDataProvider } from "./IPresentationDataProvider.js"; /** * Properties for invalidating content cache. * @public */ export interface CacheInvalidationProps { /** * Invalidate content descriptor. Should be set when invalidating * after changing anything that affects how the descriptor is built: * `keys`, `selectionInfo`, `imodel`, `rulesetId`. */ descriptor?: boolean; /** * Invalidate configured content descriptor. Should be set when * invalidating something that affects how descriptor is configured * in the `configureContentDescriptor` callback, e.g. hidden fields, * sorting, filtering, etc. */ descriptorConfiguration?: boolean; /** * Invalidate cached content size. Should be set after changing anything * that may affect content size. Generally, it should always be set when * the `descriptor` flag is set. Additionally, it should also be set after * setting `filterExpression` or similar descriptor properties. */ size?: boolean; /** * Invalidate cached content. Should be set after changing anything that may * affect content. Generally, it should always be set when the `descriptor` * flag is set. Additionally, it should also be set after setting `sortingField`, * `sortDirection`, `filterExpression` and similar fields. */ content?: boolean; /** * Invalidate content formatting. Should be set after changes to active formatting options: * format specs, unit system, etc. */ formatting?: boolean; } /** @public */ export declare namespace CacheInvalidationProps { /** * Create CacheInvalidationProps to fully invalidate all caches. */ const full: () => CacheInvalidationProps; } /** * Interface for all presentation-driven content providers. * @public */ export interface IContentDataProvider extends IPresentationDataProvider { /** Display type used to format content */ readonly displayType: string; /** Keys defining what to request content for */ keys: KeySet; /** Information about selection event that results in content change */ selectionInfo: SelectionInfo | undefined; /** * Get the content descriptor. */ getContentDescriptor: () => Promise<Descriptor | undefined>; /** * Get the number of content records. */ getContentSetSize: () => Promise<number>; /** * Get the content. * @param pageOptions Paging options. */ getContent: (pageOptions?: PageOptions) => Promise<Content | undefined>; /** * Get field that was used to create the given property record. * @deprecated in 4.0. Use [[getFieldByPropertyDescription]] instead. */ getFieldByPropertyRecord: (propertyRecord: PropertyRecord) => Promise<Field | undefined>; /** Get field that was used to create a property record with given property description. */ getFieldByPropertyDescription: (descr: PropertyDescription) => Promise<Field | undefined>; } /** * Properties for creating a `ContentDataProvider` instance. * @public */ export interface ContentDataProviderProps extends DiagnosticsProps { /** IModel to pull data from. */ imodel: IModelConnection; /** Id of the ruleset to use when requesting content or a ruleset itself. */ ruleset: string | Ruleset; /** The content display type which this provider is going to load data for. */ displayType: string; /** * Paging size for obtaining content records. * * Presentation data providers, when used with paging, have ability to save one backend request for size / count. That * can only be achieved when `pagingSize` property is set on the data provider and it's value matches size which is used when * requesting content. To help developers notice this problem, data provider emits a warning similar to this: * ``` * ContentDataProvider.pagingSize doesn't match pageOptions in ContentDataProvider.getContent call. Make sure you set provider's pagingSize to avoid excessive backend requests. * ``` * To fix the issue, developers should make sure the page size used for requesting data is also set for the data provider: * ```TS * const pagingSize = 10; * const provider = new ContentDataProvider({ imodel, ruleset, displayType, pagingSize}); * // only one backend request is made for the two following requests: * provider.getContentSetSize(); * provider.getContent({ start: 0, size: pagingSize }); * ``` */ pagingSize?: number; } /** * Base class for all presentation-driven content providers. * @public */ export declare class ContentDataProvider implements IContentDataProvider { #private; private _imodel; private _ruleset; private _displayType; private _keys; private _previousKeysGuid; private _selectionInfo?; private _pagingSize?; private _diagnosticsOptions?; private _listeners; private _isContentFormatted; /** Constructor. */ constructor(props: ContentDataProviderProps); /** Destructor. Must be called to clean up. */ [Symbol.dispose](): void; /** @deprecated in 5.7. Use `[Symbol.dispose]` instead. */ dispose(): void; /** Display type used to format content */ get displayType(): string; /** * Paging options for obtaining content. * @see `ContentDataProviderProps.pagingSize` */ get pagingSize(): number | undefined; set pagingSize(value: number | undefined); /** IModel to pull data from */ get imodel(): IModelConnection; set imodel(imodel: IModelConnection); /** Id of the ruleset to use when requesting content */ get rulesetId(): string; set rulesetId(value: string); /** Keys defining what to request content for */ get keys(): KeySet; set keys(keys: KeySet); /** Information about selection event that results in content change */ get selectionInfo(): SelectionInfo | undefined; set selectionInfo(info: SelectionInfo | undefined); /** * Invalidates cached content. */ protected invalidateCache(props: CacheInvalidationProps): void; private createRequestOptions; private setupListeners; /** * Called to check if content should be requested even when `keys` is empty. If this * method returns `false`, then content is not requested and this saves a trip * to the backend. */ protected shouldRequestContentForEmptyKeyset(): boolean; /** * Get the content descriptor overrides. * * The method may be overriden to configure the content based on content descriptor. If necessary, * it may use [[getContentDescriptor]] to get the descriptor first. */ protected getDescriptorOverrides(): Promise<DescriptorOverrides>; private getDefaultContentDescriptor; /** * Get the content descriptor. * * The method may return `undefined ` descriptor if: * - [[shouldRequestContentForEmptyKeyset]] returns `false` and `this.keys` is empty * - there is no content based on the ruleset and input */ getContentDescriptor: import("micro-memoize").Memoized<() => Promise<Descriptor | undefined>>; /** * Get the number of content records. */ getContentSetSize(): Promise<number>; /** * Get the content. * @param pageOptions Paging options. */ getContent(pageOptions?: PageOptions): Promise<Content | undefined>; /** * Get field using PropertyRecord. * @deprecated in 4.0. Use [[getFieldByPropertyDescription]] instead. */ getFieldByPropertyRecord(propertyRecord: PropertyRecord): Promise<Field | undefined>; /** Get field that was used to create a property record with given property description. */ getFieldByPropertyDescription(descr: PropertyDescription): Promise<Field | undefined>; private _getContentAndSize; private _getFormattedContentAndSize; private onContentUpdate; private onIModelContentChanged; private onRulesetModified; private onRulesetVariableChanged; private onUnitSystemChanged; private onFormatsChanged; } //# sourceMappingURL=ContentDataProvider.d.ts.map