Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import getJsonParsedValue from '@filerobot/utils/lib/getJsonParsedValue';
import { COLORS_OPTIONS } from '../../../Filters/Filters.constants';
export var generateGeneralSectionFields = function generateGeneralSectionFields(file, languageRegionalFilterUuid, i18n, isPreUpload) {
  var _info$brand, _orientationLabels$in, _info$main_colors_hex;
  var _file$meta = file.meta,
    meta = _file$meta === void 0 ? {} : _file$meta,
    _file$tags = file.tags,
    tags = _file$tags === void 0 ? [] : _file$tags,
    _file$info = file.info,
    info = _file$info === void 0 ? {} : _file$info,
    _file$labels = file.labels,
    labels = _file$labels === void 0 ? [] : _file$labels;
  var _ref = info || {},
    mainColors = _ref.main_colors;
  var brandsAndLogos = ((info === null || info === void 0 ? void 0 : (_info$brand = info.brand) === null || _info$brand === void 0 ? void 0 : _info$brand.extracted) || []).map(function (item) {
    return item === null || item === void 0 ? void 0 : item.classes;
  });
  var brandAndLogosLabels = brandsAndLogos.map(function (item) {
    var _item$;
    return item === null || item === void 0 ? void 0 : (_item$ = item[0]) === null || _item$ === void 0 ? void 0 : _item$.label;
  });
  var filteredBrandAndLogosLabels = _toConsumableArray(new Set(brandAndLogosLabels));
  var orientationLabels = {
    LD: i18n('mutualizedOrientationsLandscapeLabel'),
    PT: i18n('mutualizedOrientationsPortraitLabel'),
    SQ: i18n('mutualizedOrientationsSquareLabel'),
    PA: i18n('mutualizedOrientationsPanoramaLabel'),
    unknown: function unknown() {
      return info.img_h > info.img_w && (info.img_h > info.img_w ? orientationLabels.PT : orientationLabels.LD) || i18n('mutualizedUnknownText');
    }
  };
  var getCorrectColor = function getCorrectColor(color) {
    var _COLORS_OPTIONS$find;
    if (!color) return;
    return ((_COLORS_OPTIONS$find = COLORS_OPTIONS.find(function (colorOption) {
      return colorOption.value === color;
    })) === null || _COLORS_OPTIONS$find === void 0 ? void 0 : _COLORS_OPTIONS$find.color) || color;
  };

  /**
   * TODO(Ahmed K. -- it should be removed after have BE fix -- ):
   * Task (https://scaleflexhq.atlassian.net/browse/FRA-3071)
   */
  var currentMainColors = Array.isArray(mainColors) ? mainColors : [];

  // TODO: Refactor the underscore (_) naming to camelCase naming including the metadata comopnents.
  return [{
    can_edit: true,
    key: 'name',
    placeholder: "".concat(i18n('generalSectionNameLabel'), "..."),
    required: true,
    title: i18n('generalSectionNameLabel'),
    type: 'text',
    uuid: 'GENERAL-NAME',
    value: file.name
  }, {
    can_edit: true,
    key: 'title',
    placeholder: "".concat(i18n('generalSectionTitleLabel'), "..."),
    regional_variants_group_uuid: languageRegionalFilterUuid,
    required: true,
    title: i18n('generalSectionTitleLabel'),
    type: 'text',
    uuid: 'GENERAL-TITLE',
    value: getJsonParsedValue(meta.title)
  }, {
    can_edit: true,
    key: 'description',
    placeholder: "".concat(i18n('generalSectionDescriptionLabel'), "..."),
    regional_variants_group_uuid: languageRegionalFilterUuid,
    required: true,
    title: i18n('generalSectionDescriptionLabel'),
    type: 'textarea',
    uuid: 'GENERAL-DESCRIPTION',
    value: getJsonParsedValue(meta.description)
  }, {
    can_edit: true,
    key: 'tags',
    placeholder: "".concat(i18n('generalSectionTagsLabel'), "..."),
    regional_variants_group_uuid: languageRegionalFilterUuid,
    title: i18n('generalSectionTagsLabel'),
    type: 'tags',
    uuid: 'GENERAL-TAGS',
    value: tags,
    hide: isPreUpload
  }, {
    can_edit: false,
    key: 'labels',
    placeholder: "".concat(i18n('generalSectionLabelsLabel'), "..."),
    title: i18n('generalSectionLabelsLabel'),
    type: 'labels',
    uuid: 'GENERAL-LABELS',
    value: Array.isArray(labels) ? labels : [],
    // TODO: Some labels are object not array on BE we need to report about this.
    hide: isPreUpload
  }, {
    can_edit: false,
    key: 'orientation',
    placeholder: "".concat(i18n('generalSectionOrientationLabel'), "..."),
    title: i18n('generalSectionOrientationLabel'),
    type: 'text',
    uuid: 'GENERAL-ORIENTATION',
    value: (_orientationLabels$in = orientationLabels[info.img_o]) !== null && _orientationLabels$in !== void 0 ? _orientationLabels$in : orientationLabels.unknown(),
    hide: isPreUpload
  },
  // hidden as no BE post process handles that yet
  // {
  //   can_edit: false,
  //   key: 'imageStyle',
  //   placeholder: `${i18n('generalSectionImageStyleLabel')}...`,
  //   title: i18n('generalSectionImageStyleLabel'),
  //   type: 'text',
  //   uuid: 'GENERAL-IMAGE_STYLE',
  //   value: '' // ex: 'Photos' // TODO: Add dynamic value
  // },
  {
    can_edit: false,
    key: 'mainColors',
    placeholder: "".concat(i18n('mutualizedMainColorsLabel'), "..."),
    title: i18n('mutualizedMainColorsLabel'),
    type: 'mainColors',
    uuid: 'GENERAL-MAIN_COLORS',
    value: (info === null || info === void 0 ? void 0 : (_info$main_colors_hex = info.main_colors_hex) === null || _info$main_colors_hex === void 0 ? void 0 : _info$main_colors_hex.map(function (color) {
      return "#".concat(color);
    })) || currentMainColors.map(function (color) {
      return getCorrectColor(color);
    }),
    hide: isPreUpload
  }, {
    can_edit: false,
    key: 'dominantColor',
    placeholder: "".concat(i18n('mutualizedDominantColorLabel'), "..."),
    title: i18n('mutualizedDominantColorLabel'),
    type: 'dominantColor',
    uuid: 'GENERAL-DOMINANT_COLOR',
    value: info !== null && info !== void 0 && info.dominant_color_hex ? "#".concat(info === null || info === void 0 ? void 0 : info.dominant_color_hex) : getCorrectColor(info === null || info === void 0 ? void 0 : info.dominant_color),
    hide: isPreUpload
  }, {
    can_edit: false,
    key: 'logoAndBrand',
    placeholder: "".concat(i18n('generalSectionLogoAndBrandLabel'), "..."),
    title: i18n('generalSectionLogoAndBrandLabel'),
    type: 'linked-text',
    uuid: 'GENERAL-LOGO_AND_BRAND',
    value: filteredBrandAndLogosLabels,
    hide: !filteredBrandAndLogosLabels.length
  }];
};
export var generateProductSectionFields = function generateProductSectionFields(file, i18n) {
  var _file$product, _file$product2;
  return [{
    can_edit: true,
    key: 'ref',
    placeholder: "".concat(i18n('tabSectionProductReferenceLabel'), "..."),
    required: true,
    title: i18n('tabSectionProductReferenceLabel'),
    type: 'text',
    uuid: 'PRODUCT-REFERENCE',
    value: (_file$product = file.product) === null || _file$product === void 0 ? void 0 : _file$product.ref
  }, {
    can_edit: true,
    key: 'position',
    placeholder: "".concat(i18n('tabSectionProductPositionLabel'), "..."),
    required: true,
    title: i18n('tabSectionProductPositionLabel'),
    type: 'numeric',
    uuid: 'PRODUCT-POSITION',
    value: (_file$product2 = file.product) === null || _file$product2 === void 0 ? void 0 : _file$product2.position
  }];
};
var checkFieldVariantValue = function checkFieldVariantValue(value, possibleValues) {
  var _possibleValues$filte, _possibleValues$find;
  return Array.isArray(value) ? possibleValues === null || possibleValues === void 0 ? void 0 : (_possibleValues$filte = possibleValues.filter(function (element) {
    return value.includes(element === null || element === void 0 ? void 0 : element.internal_unique_value);
  })) === null || _possibleValues$filte === void 0 ? void 0 : _possibleValues$filte.map(function (selectedVal) {
    return selectedVal === null || selectedVal === void 0 ? void 0 : selectedVal.label;
  }) : possibleValues === null || possibleValues === void 0 ? void 0 : (_possibleValues$find = possibleValues.find(function (possibleValue) {
    return (possibleValue === null || possibleValue === void 0 ? void 0 : possibleValue.internal_unique_value) === value;
  })) === null || _possibleValues$find === void 0 ? void 0 : _possibleValues$find.label;
};
export var getFieldVariantValue = function getFieldVariantValue(value, possibleValues, regionalVariantsGroupUuid, metaRegionalFilters) {
  var parsedValue = getJsonParsedValue(value);
  if (regionalVariantsGroupUuid) {
    return parsedValue[metaRegionalFilters[regionalVariantsGroupUuid]] || (_typeof(parsedValue) === 'object' ? '' : parsedValue);
  }
  if (possibleValues && possibleValues.length > 0) {
    return checkFieldVariantValue(value, possibleValues);
  }
  return value;
};