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 _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 { useSelector, useDispatch } from 'react-redux';
import { COLLECTIONS_LIST_COLS_OBJECTS, COLLECTIONS_LIST_COLS_IDS } from '@filerobot/utils/lib/constants';
import { CheckBox, Table, TableHead, TableRow, TableBody, TableCell, Button } from '@scaleflex/ui/core';
import { LoaderView } from '@filerobot/common';
import NoCollections from '@filerobot/icons/lib/NoCollections';
import { ArrowDown, ArrowUp, NoResult, Plus } from '@scaleflex/icons';
import NoItems from '@filerobot/explorer/lib/components/NoItems';
import { useExplorer, useIsSmallScreen } from '../../../hooks';
import { collectionsDeselected, collectionsSelected, collectionsSortingUpdated, selectSelectedCollectionsUuids, selectCollectionsUuids, selectIsAllCollectionsSelected, selectCollectionsSortBy, selectCollectionsSortOrder } from '../../../slices/collections.slice';
import { selectTopSectionHeight } from '../../../slices/topSection.slice';
import { selectIsExplorerPluginLoading } from '../../../slices/common.slice';
import { collectionModalOpened } from '../../../slices/panels.slice';
import CollectionsListLi from './CollectionsListLi';
import Styled from '../../CollectionsView/VirtualFoldersGrid.styled';
import { SORT_ORDER } from '../../common/Sort/Sort.constants';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var CollectionsList = function CollectionsList(_ref) {
  var filteredSortedCollectionsUuids = _ref.filteredSortedCollectionsUuids,
    height = _ref.height;
  var dispatch = useDispatch();
  var _useExplorer = useExplorer(),
    i18n = _useExplorer.i18n;
  var isWidgetSmallSize = useIsSmallScreen();
  var loading = useSelector(selectIsExplorerPluginLoading);
  var collectionsUuids = useSelector(selectCollectionsUuids);
  var selectedCollections = useSelector(selectSelectedCollectionsUuids);
  var topSectionHeight = useSelector(selectTopSectionHeight);
  var isAllSelected = useSelector(selectIsAllCollectionsSelected);
  var sortBy = useSelector(selectCollectionsSortBy);
  var sortOrder = useSelector(selectCollectionsSortOrder);
  var handleToggleSelectAll = function handleToggleSelectAll() {
    var selected = isAllSelected ? [] : filteredSortedCollectionsUuids;
    dispatch(collectionsSelected(selected));
  };
  var handleToggleCheckbox = function handleToggleCheckbox(collectionUuid) {
    var selectedSet = new Set(selectedCollections);
    selectedSet[selectedSet.has(collectionUuid) ? 'delete' : 'add'](collectionUuid);
    dispatch(collectionsSelected(_toConsumableArray(selectedSet)));
  };
  var handleToggleCreateCollection = function handleToggleCreateCollection() {
    dispatch(collectionModalOpened({
      show: true
    }));
    dispatch(collectionsDeselected());
  };
  var renderColumn = function renderColumn(columnName) {
    var _COLLECTIONS_LIST_COL = COLLECTIONS_LIST_COLS_OBJECTS[columnName],
      sortValue = _COLLECTIONS_LIST_COL.sortValue,
      i18nStr = _COLLECTIONS_LIST_COL.i18nStr;
    var isSorted = sortValue === sortBy;
    var handleColumnSort = function handleColumnSort() {
      var isSortValueChanged = sortValue !== sortBy;
      var nextSortOrder = sortOrder === SORT_ORDER.ASC ? SORT_ORDER.DSC : SORT_ORDER.ASC;
      if (isSortValueChanged) nextSortOrder = SORT_ORDER.ASC;
      dispatch(collectionsSortingUpdated({
        sortBy: sortValue,
        order: nextSortOrder
      }));
    };
    var renderSortArrows = function renderSortArrows() {
      if (!isSorted) return null;
      if (sortOrder === SORT_ORDER.ASC) return /*#__PURE__*/_jsx(ArrowDown, {
        size: 12
      });
      return /*#__PURE__*/_jsx(ArrowUp, {
        size: 12
      });
    };
    return /*#__PURE__*/_jsx(Styled.HeaderTableCell, {
      columnName: columnName,
      cursorPointer: !!sortValue,
      children: sortValue ? /*#__PURE__*/_jsxs(Styled.HeaderItemLabel, {
        onClick: handleColumnSort,
        children: [i18n(i18nStr), renderSortArrows()]
      }) : i18n(i18nStr)
    }, columnName);
  };
  var renderNoItems = function renderNoItems() {
    if (!collectionsUuids.length) {
      return /*#__PURE__*/_jsx(NoItems, {
        size: 100,
        icon: NoCollections,
        primary: i18n('mutualizedNoCollectionsLabel'),
        secondary: i18n('collectionsViewAddFirstCollectionLabel'),
        mt: 150
      });
    }
    if (!filteredSortedCollectionsUuids.length) {
      return /*#__PURE__*/_jsx(NoItems, {
        mt: 60,
        icon: NoResult,
        size: 90,
        primary: i18n('mutualizedNoResults')
      });
    }
    return null;
  };
  return /*#__PURE__*/_jsxs(Styled.BrowserList, {
    className: "filerobot-ProviderBrowser-list filerobot-ProviderBrowser-list-collections",
    isWidgetSmallSize: isWidgetSmallSize,
    topSectionHeight: topSectionHeight,
    height: height,
    withSidePadding: true,
    children: [loading && /*#__PURE__*/_jsx(LoaderView, {
      loaderLabel: i18n('loaderLoadingLabel')
    }), /*#__PURE__*/_jsxs(Styled.TableContainer, {
      children: [/*#__PURE__*/_jsxs(Table, {
        children: [/*#__PURE__*/_jsx(TableHead, {
          children: /*#__PURE__*/_jsxs(TableRow, {
            children: [!!filteredSortedCollectionsUuids.length && /*#__PURE__*/_jsx(Styled.CheckBoxTableCell, {
              padding: "options",
              header: true,
              children: /*#__PURE__*/_jsx(CheckBox, {
                size: "md",
                onChange: handleToggleSelectAll,
                checked: isAllSelected,
                type: isAllSelected ? 'intermediate' : 'checkbox',
                style: {
                  marginRight: 20
                }
              })
            }), [COLLECTIONS_LIST_COLS_IDS.NAME, COLLECTIONS_LIST_COLS_IDS.VISIBILITY, COLLECTIONS_LIST_COLS_IDS.CREATED_AT].map(function (col) {
              return renderColumn(col);
            }), /*#__PURE__*/_jsx(TableCell, {})]
          })
        }), /*#__PURE__*/_jsx(TableBody, {
          children: filteredSortedCollectionsUuids.length ? filteredSortedCollectionsUuids.map(function (collectionUuid) {
            return /*#__PURE__*/_jsx(CollectionsListLi, {
              collectionUuid: collectionUuid,
              isChecked: false,
              toggleCheckbox: handleToggleCheckbox,
              isSelected: selectedCollections.includes(collectionUuid)
            }, collectionUuid);
          }) : !loading && renderNoItems()
        })]
      }), /*#__PURE__*/_jsx(Styled.AddBtnWrapper, {
        children: /*#__PURE__*/_jsx(Button, {
          color: "link-primary",
          size: "sm",
          startIcon: /*#__PURE__*/_jsx(Plus, {}),
          onClick: handleToggleCreateCollection,
          children: i18n('collectionModalAddCollectionTitle')
        })
      })]
    })]
  });
};
export default CollectionsList;