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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useState, useEffect } from 'react';
import { useModal } from '@filerobot/core/lib/hooks';
import Styled from './ActivityTab.styled';
import { useExplorer } from '../../../../hooks';
import { ACTIONS, ACTIONS_KEYS, ACTIONS_UPDATES_KEYS, COMMENT_MENTION_REG_EXP, GROUPED_ACTIONS } from './ActivityTab.constants';
import { formatDate, getDiffsObjectsInArray, mergeDuplicatedObjects } from './ActivityTab.utils';
import Avatar from './Avatar';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var YearActivities = function YearActivities(_ref) {
  var changes = _ref.changes;
  var toggleModal = useModal();
  var _useExplorer = useExplorer(),
    i18n = _useExplorer.i18n,
    info = _useExplorer.info;
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    activities = _useState2[0],
    setActivities = _useState2[1];
  var perpareActivity = function perpareActivity() {
    var mergedChanges = mergeDuplicatedObjects(changes);
    var newActivity = getDiffsObjectsInArray(changes, mergedChanges);
    var sortedActivities = mergedChanges.concat(newActivity).sort(function (a, b) {
      return ((b === null || b === void 0 ? void 0 : b.changed_at) || '').localeCompare((a === null || a === void 0 ? void 0 : a.changed_at) || '');
    });
    setActivities(sortedActivities);
  };
  useEffect(function () {
    if (changes) {
      perpareActivity();
    }
  }, [changes]);
  var getDescripiton = function getDescripiton(action, props) {
    var _oldLabelsArray, _newLabelsArray;
    var oldProps = props.old,
      newProps = props["new"];
    var oldVisibilty, newVisibility, deletedComment, newComment, oldLabelsArray, newLabelsArray, updatedLabel;
    var fileName = props.name;
    var isLabelDetached = ((_oldLabelsArray = oldLabelsArray) === null || _oldLabelsArray === void 0 ? void 0 : _oldLabelsArray.length) < ((_newLabelsArray = newLabelsArray) === null || _newLabelsArray === void 0 ? void 0 : _newLabelsArray.length);

    // TODO: need to check with BE devs what format we should expect in the future
    // if (action === ACTIONS.VISIBILITY) {
    //   oldVisibilty = i18n(VISIBILITY_OPTIONS[oldProps].i18nLabel)
    //   newVisibility = i18n(VISIBILITY_OPTIONS[newProps].i18nLabel)
    // }

    if ([ACTIONS.COMMENT_CREATED, ACTIONS.COMMENT_DELETED, ACTIONS.COMMENT_CHANGED].includes(action)) {
      var getFormattedComment = function getFormattedComment(comment) {
        var _JSON$parse$comment_t;
        return (_JSON$parse$comment_t = JSON.parse(comment).comment_text) === null || _JSON$parse$comment_t === void 0 ? void 0 : _JSON$parse$comment_t.replaceAll(COMMENT_MENTION_REG_EXP, '$2$3');
      };
      deletedComment = getFormattedComment(oldProps);
      newComment = getFormattedComment(newProps);
    }
    if (action === ACTIONS.LABELS) {
      oldLabelsArray = JSON.parse(oldProps);
      newLabelsArray = JSON.parse(newProps);
      if (isLabelDetached) {
        var _oldLabelsArray2;
        // only 1 label is attached or detached per change
        updatedLabel = (_oldLabelsArray2 = oldLabelsArray) === null || _oldLabelsArray2 === void 0 ? void 0 : _oldLabelsArray2.filter(function (x) {
          var _newLabelsArray2;
          return !((_newLabelsArray2 = newLabelsArray) !== null && _newLabelsArray2 !== void 0 && _newLabelsArray2.includes(x));
        })[0];
      } else {
        var _newLabelsArray3;
        updatedLabel = (_newLabelsArray3 = newLabelsArray) === null || _newLabelsArray3 === void 0 ? void 0 : _newLabelsArray3.filter(function (x) {
          var _oldLabelsArray3;
          return !((_oldLabelsArray3 = oldLabelsArray) !== null && _oldLabelsArray3 !== void 0 && _oldLabelsArray3.includes(x));
        })[0];
      }
    }
    var renderActionLabel = function renderActionLabel() {
      return /*#__PURE__*/_jsx("label", {
        children: i18n(ACTIONS_KEYS === null || ACTIONS_KEYS === void 0 ? void 0 : ACTIONS_KEYS[action], {
          smart_count: 1
        })
      });
    };
    var renderUpdateProps = {
      handleShowDetails: handleShowDetails,
      oldVisibilty: oldVisibilty,
      newVisibility: newVisibility,
      i18n: i18n,
      oldProps: oldProps,
      newProps: newProps,
      action: action,
      deletedComment: deletedComment,
      newComment: newComment,
      fileName: fileName,
      isLabelDetached: isLabelDetached,
      updatedLabel: updatedLabel,
      info: info
    };
    var renderActionUpdate = function renderActionUpdate() {
      var _GROUPED_ACTIONS$find;
      return /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(Styled.ActivityAction, {
          onlyLeftPadding: ![ACTIONS.COMMENT_CHANGED, ACTIONS.COMMENT_CREATED, ACTIONS.COMMENT_DELETED].includes(action),
          children: [ACTIONS.VISIBILITY, ACTIONS.METADATA, ACTIONS.TAGS, ACTIONS.RENAME].includes(action) ? i18n('activityTabWasUpdatedText', {
            smart_count: action === ACTIONS.TAGS ? 0 : 1
          }) : i18n(ACTIONS_UPDATES_KEYS === null || ACTIONS_UPDATES_KEYS === void 0 ? void 0 : ACTIONS_UPDATES_KEYS[action])
        }), /*#__PURE__*/_jsx(_Fragment, {
          children: ![ACTIONS.CREATED].includes(action) && (GROUPED_ACTIONS === null || GROUPED_ACTIONS === void 0 ? void 0 : (_GROUPED_ACTIONS$find = GROUPED_ACTIONS.find(function (actions) {
            var _actions$actionsArray;
            return (_actions$actionsArray = actions.actionsArray) === null || _actions$actionsArray === void 0 ? void 0 : _actions$actionsArray.includes(action);
          })) === null || _GROUPED_ACTIONS$find === void 0 ? void 0 : _GROUPED_ACTIONS$find.renderActionUpdate(renderUpdateProps))
        })]
      });
    };
    return /*#__PURE__*/_jsxs(Styled.ActivityDescription, {
      children: [renderActionLabel(), renderActionUpdate()]
    });
  };
  var modalContent = function modalContent(oldProps, newProps) {
    return /*#__PURE__*/_jsxs(Styled.ModalContentWrapper, {
      children: [/*#__PURE__*/_jsxs("div", {
        children: [/*#__PURE__*/_jsx("label", {
          children: i18n('metdaDataUpdatedModalBeforeLabel')
        }), /*#__PURE__*/_jsx("div", {
          children: JSON.stringify(JSON.parse(oldProps), null, 2)
        })]
      }), /*#__PURE__*/_jsxs("div", {
        children: [/*#__PURE__*/_jsx("label", {
          children: i18n('metdaDataUpdatedModalAfterLabel')
        }), /*#__PURE__*/_jsx("div", {
          children: JSON.stringify(JSON.parse(newProps), null, 2)
        })]
      })]
    });
  };
  var handleShowDetails = function handleShowDetails(action, oldProps, newProps) {
    var modelTitle = "".concat(i18n(ACTIONS_KEYS === null || ACTIONS_KEYS === void 0 ? void 0 : ACTIONS_KEYS[action]), " ").concat(i18n('activityTabWasUpdatedText', {
      smart_count: action === ACTIONS.METADATA ? 1 : 0
    }));
    toggleModal({
      title: modelTitle,
      content: modalContent(oldProps, newProps),
      enterKeySubmits: true,
      hidePrimaryButton: true,
      hideSecondaryButton: true,
      showTitleLabel: true,
      modalHeaderBorder: true,
      modalHeaderStyle: {
        padding: '11px 0'
      },
      modalCrossButtonStyle: {
        margin: '10px 16px 10px 0'
      },
      modalHeaderBottomBorder: true,
      primaryTitleStyle: {
        fontWeight: 400,
        fontSize: 18,
        lineHeight: '20px'
      },
      modalStyle: {
        maxWidth: 800,
        maxHeight: 588
      },
      modalBodyStyle: {
        padding: 0
      },
      modalFooterStyle: {
        padding: 0
      }
    });
  };
  var renderActivityItem = function renderActivityItem(item, index) {
    var action = item.action,
      props = item.props,
      _item$user = item.user,
      _item$user2 = _item$user === void 0 ? {} : _item$user,
      responsibleUserName = _item$user2.name,
      responsibleUserPhoto = _item$user2.photo,
      changedAt = item.changed_at;
    var isActionArray = Array.isArray(action);
    return /*#__PURE__*/_jsxs(Styled.ActivityWrapper, {
      children: [/*#__PURE__*/_jsx("label", {
        children: formatDate(changedAt)
      }), /*#__PURE__*/_jsxs(Styled.Activity, {
        children: [action !== ACTIONS.CREATED && /*#__PURE__*/_jsx(Avatar, {
          photo: responsibleUserPhoto,
          avatarOnly: true,
          avatarSize: 40,
          avatarIconSize: 18
        }), /*#__PURE__*/_jsxs(Styled.ActivityDetails, {
          children: [responsibleUserName && /*#__PURE__*/_jsx("label", {
            children: responsibleUserName
          }), isActionArray ? action.map(function (action, index) {
            return /*#__PURE__*/_jsx("div", {
              children: getDescripiton(action, props[index])
            }, index);
          }) : /*#__PURE__*/_jsx("div", {
            children: getDescripiton(action, props)
          }, index)]
        })]
      })]
    }, index);
  };
  return activities.map(renderActivityItem);
};
export default YearActivities;