How to use the @bentley/presentation-common.DisplayValue.isPrimitive function in @bentley/presentation-common

To help you get started, we’ve selected a few @bentley/presentation-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imodeljs / imodeljs / presentation / components / src / common / ContentBuilder.ts View on Github external
const createNestedContentRecord = (field: NestedContentField, item: Item, props: NestedContentCreationProps & PropertyDescriptionCreationProps): PropertyRecord => {
  const isMerged = item.isFieldMerged(field.name);
  let value: PropertyValue;

  if (isMerged) {
    const displayValue = item.displayValues[field.name];
    if (!DisplayValue.isPrimitive(displayValue))
      throw new PresentationError(PresentationStatus.Error, "displayValue should be primitive");
    // if the value is merged, just take the display value
    value = {
      valueFormat: UiPropertyValueFormat.Primitive,
      value: undefined,
      displayValue: (undefined !== displayValue) ? displayValue.toString() : "",
    };
  } else {
    const dictionaryValue = item.values[field.name];
    if (!Value.isNestedContent(dictionaryValue))
      throw new PresentationError(PresentationStatus.Error, "value should be nested content");
    // nested content value is in NestedContent[] format
    const nestedContentArray: NestedContentValue[] = dictionaryValue;
    value = {
      valueFormat: UiPropertyValueFormat.Array,
      items: nestedContentArray.map((r) => createNestedStructRecord(field, r, props)),
github imodeljs / imodeljs / presentation / components / src / common / ContentBuilder.ts View on Github external
const createRecord = (propertyDescription: PropertyDescription, typeDescription: TypeDescription,
  value: Value, displayValue: DisplayValue, isReadOnly: boolean, isMerged: boolean, extendedData?: { [key: string]: any }): PropertyRecord => {
  const valueObj = createValue(propertyDescription, typeDescription, isMerged, value, displayValue);
  const record = new PropertyRecord(valueObj, propertyDescription);
  if (displayValue)
    record.description = createRecordDescription(typeDescription, displayValue);
  if (isMerged)
    record.isMerged = true;
  if (isReadOnly)
    record.isReadonly = true;
  if (extendedData)
    record.extendedData = extendedData;
  if (displayValue && DisplayValue.isPrimitive(displayValue) && getLinks(displayValue).length !== 0)
    record.links = {
      matcher: getLinks,
    };
  return record;
};