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:
import { useContext, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { FMAW_URL_QUERY_PARAMS, PERMISSIONS, VIEW_IDS } from '@filerobot/utils/lib/constants';
import { VirtualListDataContext } from '@filerobot/core/lib/Providers';
import { useExplorer } from '../../hooks';
import { URL_PARAM_VIEW, VIEW_COMPONENTS, VIEW_OPTIONS } from './Views.constants';
import { activateViewFromUrl, selectActiveView, selectIsCollectionsViewAvailable, selectIsLabelsViewAvailable, selectViewLayout } from '../../slices/views.slice';
import { applyDefaultLabel, fetchLabels } from '../../slices/labels.slice';
import { applyDefaultCollection, fetchCollections } from '../../slices/collections.slice';
import Styled from './Views.styled';
import { applyDefaultSearchQuery } from '../../slices/search.slice';
import { locateFile } from '../../slices/selections.slice';
import { jsx as _jsx } from "react/jsx-runtime";
var Views = function Views() {
  var dispatch = useDispatch();
  var _useExplorer = useExplorer(),
    checkUserPermissions = _useExplorer.checkUserPermissions,
    opts = _useExplorer.opts,
    getUrlQueryParam = _useExplorer.getUrlQueryParam;
  var _useContext = useContext(VirtualListDataContext),
    virtualListApiRef = _useContext.apiRef;
  var isLabelsViewAvailable = useSelector(selectIsLabelsViewAvailable);
  var isCollectionsViewAvailable = useSelector(selectIsCollectionsViewAvailable);
  var viewLayout = useSelector(selectViewLayout);
  var activeViewId = useSelector(selectActiveView);
  useEffect(function () {
    var _URL_PARAM_VIEW$Objec, _opts$defaultItemToFo, _opts$defaultItemToFo2, _opts$defaultItemToFo3;
    var viewFromUrl = URL_PARAM_VIEW === null || URL_PARAM_VIEW === void 0 ? void 0 : (_URL_PARAM_VIEW$Objec = URL_PARAM_VIEW[Object.keys(URL_PARAM_VIEW).find(function (paramName) {
      var paramValue = getUrlQueryParam(paramName);
      return paramName === FMAW_URL_QUERY_PARAMS.FOLDER && paramValue === '/' ? false : paramValue;
    })]) === null || _URL_PARAM_VIEW$Objec === void 0 ? void 0 : _URL_PARAM_VIEW$Objec.viewId;
    if (viewFromUrl) {
      dispatch(activateViewFromUrl());
    } else if (opts.defaultSearchQuery) {
      dispatch(applyDefaultSearchQuery());
    } else if (opts.defaultLabelSid) {
      dispatch(applyDefaultLabel());
    } else if (opts.defaultCollectionUuid) {
      dispatch(applyDefaultCollection());
    } else if ((_opts$defaultItemToFo = opts.defaultItemToFocus) !== null && _opts$defaultItemToFo !== void 0 && _opts$defaultItemToFo.uuid && (_opts$defaultItemToFo2 = opts.defaultItemToFocus) !== null && _opts$defaultItemToFo2 !== void 0 && (_opts$defaultItemToFo3 = _opts$defaultItemToFo2.folder) !== null && _opts$defaultItemToFo3 !== void 0 && _opts$defaultItemToFo3.name) {
      dispatch(locateFile({
        file: opts.defaultItemToFocus,
        ref: virtualListApiRef
      }));
    } else {
      var _VIEW_OPTIONS$activeV, _VIEW_OPTIONS$activeV2;
      dispatch((_VIEW_OPTIONS$activeV = (_VIEW_OPTIONS$activeV2 = VIEW_OPTIONS[activeViewId]).activateAction) === null || _VIEW_OPTIONS$activeV === void 0 ? void 0 : _VIEW_OPTIONS$activeV.call(_VIEW_OPTIONS$activeV2));
    }

    // TODO: We should remove those calls & and have them called only on switching to the view, or if used in the context menu have them called on opening the option in context menu.
    if (![activeViewId, viewFromUrl].includes(VIEW_IDS.COLLECTIONS) && !opts.defaultCollectionUuid && isCollectionsViewAvailable && checkUserPermissions([PERMISSIONS.COLLECTIONS_MANAGE])) {
      dispatch(fetchCollections());
    }
    if (![activeViewId, viewFromUrl].includes(VIEW_IDS.LABELS) && !opts.defaultLabelSid && isLabelsViewAvailable && checkUserPermissions([PERMISSIONS.LABELS_LIST])) {
      dispatch(fetchLabels());
    }
  }, []);
  var ActiveView = VIEW_COMPONENTS[activeViewId];
  if (!ActiveView) {
    // TODO: Add proper error component for this.
    return 'Wrong view provided...';
  }

  // TODO: Rename the class name and refactor the classes applied there, also we should apply layoutType to state instead of opts?.
  return /*#__PURE__*/_jsx(Styled.ViewWrapper, {
    className: "filerobot-ProviderBrowser" // we are keeping this till we support all the related (parent/child ) classes
    ,
    viewLayout: viewLayout,
    children: /*#__PURE__*/_jsx(ActiveView, {})
  });
};
export default Views;