metadata-based-explorer1
Version:
Box UI Elements
183 lines (154 loc) • 7.38 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import classNames from 'classnames';
import { CellMeasurer, CellMeasurerCache } from 'react-virtualized/dist/commonjs/CellMeasurer';
import List from 'react-virtualized/dist/commonjs/List';
import 'react-virtualized/styles.css';
import FileVersionListItem from './FileVersionListItem';
import { VersionsPropType } from './prop-types';
import './FileVersionList.scss';
var DEFAULT_HEIGHT_PX = 96;
var LIST_HEIGHT_PX = 300;
var LIST_WIDTH_PX = 400;
var FileVersionList =
/*#__PURE__*/
function (_Component) {
_inherits(FileVersionList, _Component);
/* eslint-disable no-underscore-dangle */
function FileVersionList(props) {
var _this;
_classCallCheck(this, FileVersionList);
_this = _possibleConstructorReturn(this, _getPrototypeOf(FileVersionList).call(this, props));
_defineProperty(_assertThisInitialized(_this), "_cache", null);
_defineProperty(_assertThisInitialized(_this), "_list", null);
_defineProperty(_assertThisInitialized(_this), "rowRenderer", function (_ref) {
var index = _ref.index,
style = _ref.style,
parent = _ref.parent;
var _this$props = _this.props,
canDelete = _this$props.canDelete,
canUpload = _this$props.canUpload,
isProcessing = _this$props.isProcessing,
onDelete = _this$props.onDelete,
onDownload = _this$props.onDownload,
onMakeCurrent = _this$props.onMakeCurrent,
onRestore = _this$props.onRestore,
versions = _this$props.versions,
versionLimit = _this$props.versionLimit;
var version = versions[index];
var isOverVersionLimit = !!(versionLimit && index >= versionLimit);
var key = version.id;
return React.createElement(CellMeasurer, {
key: key,
cache: _this._cache,
columnIndex: 0,
parent: parent,
rowIndex: index
}, React.createElement(FileVersionListItem, {
canDelete: canDelete,
canUpload: canUpload,
isOverVersionLimit: isOverVersionLimit,
isProcessing: isProcessing,
onDelete: onDelete,
onDownload: onDownload,
onMakeCurrent: onMakeCurrent,
onRestore: onRestore,
style: style,
version: version,
versionLimit: versionLimit
}));
});
_defineProperty(_assertThisInitialized(_this), "_setListRef", function (ref) {
_this._list = ref;
});
_this._cache = new CellMeasurerCache({
defaultHeight: DEFAULT_HEIGHT_PX,
fixedWidth: true
});
return _this;
}
_createClass(FileVersionList, [{
key: "componentDidMount",
value: function componentDidMount() {
this.recalculateRowHeights();
this.jumpToVersionNumber();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
this.recalculateRowHeights();
if (prevProps.scrollToVersionNumber !== this.props.scrollToVersionNumber) {
this.jumpToVersionNumber();
}
}
}, {
key: "recalculateRowHeights",
value: function recalculateRowHeights() {
if (!this._list) {
return;
}
this._cache.clearAll();
this._list.recomputeRowHeights();
}
}, {
key: "jumpToVersionNumber",
value: function jumpToVersionNumber() {
var _this$props2 = this.props,
scrollToVersionNumber = _this$props2.scrollToVersionNumber,
versions = _this$props2.versions;
if (!this._list || !scrollToVersionNumber || !versions) {
return;
}
var scrollToIndex = versions.findIndex(function (version) {
return version.versionNumber === scrollToVersionNumber;
});
if (scrollToIndex >= 0) {
this._list.scrollToRow(scrollToIndex);
}
}
}, {
key: "render",
value: function render() {
var _this$props3 = this.props,
className = _this$props3.className,
versions = _this$props3.versions;
return React.createElement("div", {
className: classNames('file-version-list', className)
}, React.createElement(List, {
ref: this._setListRef,
deferredMeasurementCache: this._cache,
height: LIST_HEIGHT_PX,
rowCount: versions.length,
rowHeight: this._cache.rowHeight,
rowRenderer: this.rowRenderer,
scrollToAlignment: "start",
width: LIST_WIDTH_PX
}));
}
}]);
return FileVersionList;
}(Component);
_defineProperty(FileVersionList, "propTypes", {
canDelete: PropTypes.bool,
canUpload: PropTypes.bool,
className: PropTypes.string,
isProcessing: PropTypes.bool,
onDelete: PropTypes.func.isRequired,
onDownload: PropTypes.func.isRequired,
onMakeCurrent: PropTypes.func.isRequired,
onRestore: PropTypes.func.isRequired,
scrollToVersionNumber: PropTypes.number,
versions: VersionsPropType.isRequired,
versionLimit: PropTypes.number
});
export default FileVersionList;