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 } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Plus, Asc, Desc, Settings } from '@scaleflex/icons';
import { Button, Search, Skeleton, IconButton } from '@scaleflex/ui/core';
import NoCollections from '@filerobot/icons/lib/NoCollections';
import { useDebounce } from '@filerobot/common/lib/hooks';
import { useModal } from '@filerobot/core/lib/hooks';
import { useExplorerI18n } from '../../../hooks';
import { collectionsDeselected, collectionsSearchTermUpdated, selectCollections, selectCollectionsSearchTerm, selectCollectionsUuids, selectFilteredSortedCollectionsUuids, selectIsCollectionsLoading } from '../../../slices/collections.slice';
import NoItems from '../../NoItems';
import { selectionsCleared } from '../../../slices/selections.slice';
import CollectionsListModal from '../CollectionsListModal';
import Styled from './CollectionsTree.styled';
import CollectionTreeItem from './CollectionTreeItem';
import { ACTION_BAR_DEFAULT_Z_INDEX, ACTION_BAR_INSIDE_MODALS_Z_INDEX, collectionModalOpened, setActionBarZIndex } from '../../../slices/panels.slice';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var CollectionsContent = function CollectionsContent(_ref) {
  var activateCollection = _ref.activateCollection;
  var dispatch = useDispatch();
  var i18n = useExplorerI18n();
  var toggleModal = useModal();
  var loading = useSelector(selectIsCollectionsLoading);
  var collections = useSelector(selectCollections);
  var collectionsUuids = useSelector(selectCollectionsUuids);
  var collectionsSearchTerm = useSelector(selectCollectionsSearchTerm);
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isDesc = _useState2[0],
    setIsDesc = _useState2[1];
  var debouncedCollectionsSearchTerm = useDebounce(collectionsSearchTerm, 300);
  var filteredSortedCollectionsUuids = useSelector(function (state) {
    return selectFilteredSortedCollectionsUuids(state, isDesc);
  });
  var deselectAllCollections = function deselectAllCollections() {
    return dispatch(collectionsDeselected());
  };
  var clearSelection = function clearSelection() {
    return dispatch(selectionsCleared());
  };
  var setCollectionsSearchTerm = function setCollectionsSearchTerm(_ref2) {
    var value = _ref2.target.value;
    return dispatch(collectionsSearchTermUpdated(value));
  };
  var collectionsTable = function collectionsTable() {
    clearSelection();
    deselectAllCollections();
    dispatch(setActionBarZIndex(ACTION_BAR_INSIDE_MODALS_Z_INDEX));
    toggleModal({
      title: i18n('explorerManageCollectionsTitle'),
      showTitleLabel: true,
      disableAutoClose: true,
      content: function content() {
        return /*#__PURE__*/_jsx(CollectionsListModal, {});
      },
      hideSecondaryButton: true,
      enterKeySubmits: true,
      modalStyle: {
        maxWidth: '1296px',
        maxHeight: '1100px',
        height: '100%'
      },
      modalHeaderStyle: {
        padding: '12px 24px 12px 0'
      },
      modalBodyStyle: {
        padding: 0,
        flexGrow: 1,
        overflow: 'auto'
      },
      modalHeaderBottomBorder: true,
      modalFooterStyle: {
        display: 'none',
        height: '0'
      },
      primaryTitleStyle: {
        border: 'none',
        fontWeight: 400,
        fontSize: 18,
        lineHeight: '20px'
      },
      modalCrossButtonStyle: {
        margin: '10px 12px 10px 0'
      },
      contentStyle: {
        height: '100%'
      },
      clearSelectionOnClose: true,
      onCancel: function onCancel() {
        dispatch(setActionBarZIndex(ACTION_BAR_DEFAULT_Z_INDEX));
        deselectAllCollections();
      }
    });
  };
  var handleToggleCreateCollection = function handleToggleCreateCollection() {
    dispatch(collectionModalOpened({
      show: true
    }));
    deselectAllCollections();
  };
  var handleSortingCollections = function handleSortingCollections() {
    setIsDesc(!isDesc);
  };
  var renderNoCollections = function renderNoCollections() {
    if (loading) {
      return /*#__PURE__*/_jsxs("div", {
        children: [/*#__PURE__*/_jsx("div", {
          children: /*#__PURE__*/_jsx(Styled.Item, {
            children: /*#__PURE__*/_jsx(Skeleton, {
              width: 200
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          children: /*#__PURE__*/_jsx(Styled.Item, {
            children: /*#__PURE__*/_jsx(Skeleton, {
              width: 200
            })
          })
        }), /*#__PURE__*/_jsx("div", {
          children: /*#__PURE__*/_jsx(Styled.Item, {
            children: /*#__PURE__*/_jsx(Skeleton, {
              width: 200
            })
          })
        })]
      });
    }
    if (!collectionsUuids.length) {
      return /*#__PURE__*/_jsx(NoItems, {
        icon: NoCollections,
        mt: 80,
        secondary: i18n('mutualizedNoCollectionsLabel')
      });
    }
    if (!filteredSortedCollectionsUuids.length) {
      return /*#__PURE__*/_jsx(NoItems, {
        size: 100,
        noSearchResults: true,
        primary: i18n('mutualizedNoResults'),
        secondary: i18n('mutualizedYourFilterMatchedResults', {
          filter: debouncedCollectionsSearchTerm,
          count: 0
        })
      });
    }
    return null;
  };
  return /*#__PURE__*/_jsxs(Styled.Container, {
    children: [/*#__PURE__*/_jsxs(Styled.Header, {
      children: [/*#__PURE__*/_jsx(Styled.Title, {
        children: i18n('collectionsTreeTitle')
      }), /*#__PURE__*/_jsx(Search, {
        value: collectionsSearchTerm,
        onChange: setCollectionsSearchTerm,
        placeholder: i18n('collectionsTreeSearchPlaceholder'),
        size: "sm",
        fullWidth: true,
        focusOnMount: true,
        disabled: (collections || []).length === 0
      })]
    }), /*#__PURE__*/_jsx(Styled.AddCollectionBtnWrapper, {
      children: /*#__PURE__*/_jsx(Button, {
        color: "link-primary",
        startIcon: /*#__PURE__*/_jsx(Plus, {}),
        size: "sm",
        disabled: loading,
        onClick: handleToggleCreateCollection,
        children: i18n('collectionsTreeAddCollectionButton')
      })
    }), /*#__PURE__*/_jsxs(Styled.SettingsWrapper, {
      children: [/*#__PURE__*/_jsxs(Styled.SortingWrapper, {
        children: [/*#__PURE__*/_jsx(Styled.NameLabel, {
          children: i18n('sortOptionsByNameLabel')
        }), /*#__PURE__*/_jsx(IconButton, {
          color: "basic",
          disabled: loading,
          onClick: handleSortingCollections,
          children: isDesc ? /*#__PURE__*/_jsx(Desc, {
            size: 14
          }) : /*#__PURE__*/_jsx(Asc, {
            size: 14
          })
        })]
      }), /*#__PURE__*/_jsx(Styled.SettingsBtnWrapper, {
        color: "basic",
        disabled: loading,
        onClick: collectionsTable,
        children: /*#__PURE__*/_jsx(Settings, {
          size: 16
        })
      })]
    }), /*#__PURE__*/_jsxs(Styled.Content, {
      children: [!loading && !!filteredSortedCollectionsUuids.length && /*#__PURE__*/_jsx("div", {
        children: filteredSortedCollectionsUuids.map(function (collectionUuid) {
          return /*#__PURE__*/_jsx(CollectionTreeItem, {
            collectionUuid: collectionUuid,
            activateCollection: activateCollection,
            debouncedCollectionsSearchTerm: debouncedCollectionsSearchTerm
          }, collectionUuid);
        })
      }), renderNoCollections()]
    })]
  });
};
export default CollectionsContent;