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    
@filerobot/explorer / lib / components / Modals / LabelModal / LabelModal.utils.js
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import deepMerge from '@filerobot/utils/lib/deepMerge';
import { defaultState } from './LabelModal.constants';
import handlePromise from '@filerobot/utils/lib/handlePromise';
import { Label } from '@scaleflex/icons';
import { PC } from '@filerobot/common';
import { attachFilesLabels, createLabel, updateLabelByUuid } from '../../../slices/labels.slice';
import LabelModalContent from './LabelModalContent';
import { jsx as _jsx } from "react/jsx-runtime";
export var getLabelModalData = function getLabelModalData(_ref) {
  var label = _ref.label,
    dispatch = _ref.dispatch,
    info = _ref.info,
    i18n = _ref.i18n,
    theme = _ref.theme,
    onClose = _ref.onClose,
    filesUuids = _ref.filesUuids;
  var defaultLabel = deepMerge(defaultState, label || {});
  var handleButtonPrimaryClick = function handleButtonPrimaryClick(_ref2) {
    var _submittedLabel, _submittedLabel2;
    var setIsModalLoading = _ref2.setIsModalLoading,
      closeModal = _ref2.closeModal,
      setPrimaryButtonDisabled = _ref2.setPrimaryButtonDisabled,
      data = _ref2.data,
      updateData = _ref2.updateData;
    var updatedData = data;
    var submittedLabel = {};
    var newLabel = data.label;
    submittedLabel = newLabel;
    if (!newLabel && label.name !== '') {
      submittedLabel = _objectSpread(_objectSpread({}, defaultLabel), label);
      updatedData = {
        label: submittedLabel
      };
    }
    updateData(_objectSpread(_objectSpread({}, updatedData), {}, {
      isSubmitted: true
    }));
    if (!((_submittedLabel = submittedLabel) !== null && _submittedLabel !== void 0 && _submittedLabel.name)) {
      return false;
    }
    setIsModalLoading(true);
    setPrimaryButtonDisabled(true);
    var shouldCreateLabel = (_submittedLabel2 = submittedLabel) === null || _submittedLabel2 === void 0 ? void 0 : _submittedLabel2.uuid;
    handlePromise(shouldCreateLabel ? dispatch(updateLabelByUuid(submittedLabel)) : dispatch(createLabel({
      label: submittedLabel
    })), function (labels) {
      // if we have file uuids that we means we are adding labels to those files
      if ((filesUuids === null || filesUuids === void 0 ? void 0 : filesUuids.length) > 0 && Array.isArray(labels)) {
        var addedLabelSid = labels[0].sid;
        dispatch(attachFilesLabels({
          filesUuids: filesUuids,
          labelsSids: [addedLabelSid]
        })).then(function () {
          info(i18n('labelViewModelLabelsAttachedInfo', {
            smart_count: filesUuids.length
          }), 'success', 3000);
        });
      }
      info(i18n(shouldCreateLabel ? 'labelViewModelLabelCreatedInfo' : 'labelViewModelLabelUpdatedInfo'), 'success', 3000);
      (onClose || closeModal)();
    }, undefined, function () {
      setIsModalLoading(false);
      setPrimaryButtonDisabled(false);
    });
  };
  var _updateLabel = function updateLabel(updateData, newLabelData) {
    return updateData(function () {
      var latestData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      return _objectSpread(_objectSpread({}, latestData), {}, {
        label: _objectSpread(_objectSpread(_objectSpread({}, defaultLabel), latestData.label), typeof newLabelData === 'function' ? newLabelData(latestData.label || {}) : newLabelData)
      });
    });
  };
  return {
    title: i18n(label !== null && label !== void 0 && label.uuid ? 'labelModalEditLabelTitle' : 'labelModalAddLabelTitle'),
    icon: /*#__PURE__*/_jsx(Label, {
      size: 29,
      color: theme.palette[PC.AccentPrimary]
    }),
    disableAutoClose: true,
    content: function content(_ref3) {
      var updateData = _ref3.updateData,
        data = _ref3.data;
      return /*#__PURE__*/_jsx(LabelModalContent, {
        currentLabel: defaultLabel,
        i18n: i18n,
        updateLabel: function updateLabel(newLabelData) {
          return _updateLabel(updateData, newLabelData);
        },
        data: _objectSpread(_objectSpread({}, data), {}, {
          label: _objectSpread(_objectSpread({}, defaultLabel), data.label)
        })
      });
    },
    buttonPrimaryLabel: i18n(label !== null && label !== void 0 && label.uuid ? 'mutualizedSaveButton' : 'mutualizedAddButtonLabel'),
    buttonSecondaryLabel: i18n('mutualizedCancelButtonLabel'),
    enterKeySubmits: true,
    onButtonPrimaryClick: handleButtonPrimaryClick,
    modalStyle: {
      maxWidth: 350
    },
    modalFooterStyle: {
      flexDirection: 'row'
    }
  };
};