UNPKG

@itwin/presentation-common

Version:

Common pieces for iModel.js presentation packages

90 lines 3.35 kB
/*--------------------------------------------------------------------------------------------- * Copyright (c) Bentley Systems, Incorporated. All rights reserved. * See LICENSE.md in the project root for license terms and full copyright notice. *--------------------------------------------------------------------------------------------*/ /** @packageDocumentation * @module Content */ import { LabelDefinition } from "../LabelDefinition.js"; import { omitUndefined } from "../Utils.js"; /** * A data structure that represents a single content record. * @public */ export class Item { /** * Keys of input instances that caused this item to be included in content. Only set if the content is * created with [[ContentFlags.IncludeInputKeys]] flag. */ inputKeys; /** Keys of instances whose data is contained in this item */ primaryKeys; /** Display label of the item */ label; /** For cases when item consists only of same class instances, information about the ECClass */ classInfo; /** Raw values dictionary */ values; /** Display values dictionary */ displayValues; /** List of field names whose values are merged (see [Merging values]($docs/presentation/content/Terminology#value-merging)) */ mergedFieldNames; /** Extended data injected into this content item */ extendedData; constructor(primaryKeysOrProps, label, imageId, classInfo, values, displayValues, mergedFieldNames, extendedData) { /* c8 ignore next 12 */ const props = Array.isArray(primaryKeysOrProps) ? { primaryKeys: primaryKeysOrProps, label: typeof label === "string" ? LabelDefinition.fromLabelString(label) : label, imageId: imageId, classInfo, values: values, displayValues: displayValues, mergedFieldNames: mergedFieldNames, extendedData, } : primaryKeysOrProps; if ("inputKeys" in props) { this.inputKeys = props.inputKeys; } this.primaryKeys = props.primaryKeys; this.classInfo = props.classInfo; this.values = props.values; this.displayValues = props.displayValues; this.mergedFieldNames = props.mergedFieldNames; this.extendedData = props.extendedData; this.label = props.label; } /** * Is value of field with the specified name merged in this record. */ isFieldMerged(fieldName) { return -1 !== this.mergedFieldNames.indexOf(fieldName); } /** Serialize this object to JSON */ toJSON() { const { label, ...baseItem } = this; return omitUndefined({ ...baseItem, labelDefinition: label, label, }); } /** Deserialize [[Item]] from JSON */ static fromJSON(json) { if (!json) { return undefined; } if (typeof json === "string") { return Item.fromJSON(JSON.parse(json)); } // eslint-disable-next-line @typescript-eslint/no-deprecated const { labelDefinition, label, ...baseJson } = json; return new Item({ ...baseJson, label: label ?? labelDefinition, }); } } //# sourceMappingURL=Item.js.map