src/client/components/referenceInputUtils/index.js
function loadObjectData(object, keyProperty, labelProperty, objectLoader,
                        onLoadingStart = () => {}, onLoadingEnd = () => {}) {
  if (isNil(object)) {
    return Promise.resolve(object);
  }
  // is multiple
  if (Array.isArray(object)) {
    const someObjectHasNoLabel = object.some(item => !hasIn(item, labelProperty));

    if (someObjectHasNoLabel) {
      onLoadingStart();
      return Promise.all(
        object.map(item => _loadSingleObject(item, keyProperty, labelProperty, objectLoader))
      ).then(responses => {
        onLoadingEnd();
        return responses.map(response => _getObjectWithFallback(response, keyProperty, labelProperty));
      });
    } else {
      return Promise.resolve(object);
    }
  } else {
    onLoadingStart();
    return _loadSingleObject(object, keyProperty, labelProperty, objectLoader).
      then(result => {
        onLoadingEnd();
        return result;
      });
  }
}
function loadObjectData(object, keyProperty, labelProperty, objectLoader,
                        onLoadingStart = () => {}, onLoadingEnd = () => {}) {
  if (isNil(object)) {
    return Promise.resolve(object);
  }
  // is multiple
  if (Array.isArray(object)) {
    const someObjectHasNoLabel = object.some(item => !hasIn(item, labelProperty));

    if (someObjectHasNoLabel) {
      onLoadingStart();
      return Promise.all(
        object.map(item => _loadSingleObject(item, keyProperty, labelProperty, objectLoader))
      ).then(responses => {
        onLoadingEnd();
        return responses.map(response => _getObjectWithFallback(response, keyProperty, labelProperty));
      });
    } else {
      return Promise.resolve(object);
    }
  } else {
    onLoadingStart();
    return _loadSingleObject(object, keyProperty, labelProperty, objectLoader).
      then(result => {
        onLoadingEnd();
        return result;
      });
  }
}
/*
Loads object(s) from endpoint or falls back to object[labelProperty] -> object[keyProperty]

@param object or array of objects
@param keyProperty unique identifier, f.e. supplierId
@param labelProperty object ui property name f.e. _objectLabel
@param objectLoader function that takes unique identifier as an argument and return Promise with loaded object
@param onLoadingStart function that handles loading start
@param onLoadingEnd function that handles loading end
@returns {*}