Repository URL to install this package:
|
Version:
3.12.20 ▾
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import { useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { Plus, Upload, Menu } from '@scaleflex/icons';
import { Button, IconButton } from '@scaleflex/ui/core';
import { PERMISSIONS } from '@filerobot/utils/lib/constants';
import { selectIsUserPermittedTo } from '@filerobot/core/lib/slices/user.slice';
import Search from './Search';
import Styled from './TopBar.styled';
import { useExplorer, useIsSmallScreen } from '../../hooks';
import { selectIsDownloading } from '../../slices/downloads.slice';
import { selectionsCleared } from '../../slices/selections.slice';
import { collectionModalOpened, mainMenuUpdated, showAddFilesPanelUpdated } from '../../slices/panels.slice';
import { useAddNewFolderModal } from '../Modals/AddNewFolder/AddNewFolder.hooks';
import { selectIsAssetsView, selectIsCollectionsView, selectIsFavoritesView, selectIsLabelsView, selectIsProductView, selectIsShareboxView } from '../../slices/views.slice';
import { selectLabelsSearchTerm } from '../../slices/labels.slice';
import { collectionsDeselected } from '../../slices/collections.slice';
import { useLabelModal } from '../Modals';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var TopBar = function TopBar() {
var dispatch = useDispatch();
var triggerAddNewFolderModal = useAddNewFolderModal();
var _useExplorer = useExplorer(),
i18n = _useExplorer.i18n,
opts = _useExplorer.opts;
var isWidgetSmallSize = useIsSmallScreen();
var toggleLabelModal = useLabelModal();
var hideUploadButton = opts.hideUploadButton,
hideSearch = opts.hideSearch,
floaty = opts.floaty;
var isDownloading = useSelector(selectIsDownloading);
var isProductView = useSelector(selectIsProductView);
var isCollectionsView = useSelector(selectIsCollectionsView);
var isLabelsView = useSelector(selectIsLabelsView);
var isFavoritesView = useSelector(selectIsFavoritesView);
var isAssetsView = useSelector(selectIsAssetsView);
var isShareboxView = useSelector(selectIsShareboxView);
var labelsSearchTerm = useSelector(selectLabelsSearchTerm);
var isAllowedToCreateFolder = useSelector(function (state) {
return selectIsUserPermittedTo(state, PERMISSIONS.FOLDER_CREATE);
});
var isAllowedToUpload = useSelector(function (state) {
return selectIsUserPermittedTo(state, PERMISSIONS.UPLOAD);
});
var lastSearchValueRef = useRef('');
var openAddFilesPanel = function openAddFilesPanel() {
dispatch(showAddFilesPanelUpdated(true));
dispatch(selectionsCleared());
};
var toggleMainMenu = function toggleMainMenu(open) {
dispatch(mainMenuUpdated({
opened: open
}));
};
var toggleCreateLabel = function toggleCreateLabel() {
toggleLabelModal({
name: labelsSearchTerm
});
};
var handleOpenCollectionModal = function handleOpenCollectionModal() {
dispatch(selectionsCleared());
dispatch(collectionsDeselected());
dispatch(collectionModalOpened({
show: true
}));
};
var showAddFolderButton = !isShareboxView && !isProductView && isAllowedToCreateFolder && !isFavoritesView && !isAssetsView && !isLabelsView && !isCollectionsView;
var showUploadButton = !isLabelsView && !isCollectionsView && !hideUploadButton && isAllowedToUpload;
var showRightSide = showAddFolderButton || isLabelsView || isCollectionsView || showUploadButton;
return /*#__PURE__*/_jsxs(Styled.TopBar, {
className: "filerobot-Explorer-TopBar",
tabIndex: -1,
style: {
padding: isShareboxView ? 20 : undefined
},
children: [/*#__PURE__*/_jsxs(Styled.CenterSide, {
className: "filerobot-Explorer-TopBar-centerSide",
children: [!floaty && /*#__PURE__*/_jsx(Styled.LeftSide, {
children: /*#__PURE__*/_jsx(IconButton, {
size: "lg",
color: "basic",
onClick: function onClick() {
return toggleMainMenu(true);
},
"data-testid": "view-menu-toggle-btn",
children: function children(props) {
return /*#__PURE__*/_jsx(Menu, _objectSpread({}, props));
}
})
}), !hideSearch && /*#__PURE__*/_jsx(Search, {
lastSearchValueRef: lastSearchValueRef
})]
}), showRightSide && !hideUploadButton && /*#__PURE__*/_jsxs(Styled.RightSide, {
children: [showAddFolderButton && /*#__PURE__*/_jsx(Styled.AddFolderButton, {
color: "secondary",
startIcon: function startIcon(props) {
return /*#__PURE__*/_jsx(Plus, _objectSpread({}, props));
},
size: isWidgetSmallSize ? 'sm' : 'md',
onClick: function onClick() {
return triggerAddNewFolderModal();
},
children: i18n('topBarNewFolderButton')
}), isLabelsView && /*#__PURE__*/_jsx(Button, {
color: "secondary",
startIcon: function startIcon(props) {
return /*#__PURE__*/_jsx(Plus, _objectSpread({}, props));
},
size: isWidgetSmallSize ? 'sm' : 'md',
onClick: toggleCreateLabel,
style: {
marginRight: '12px'
},
children: i18n('topBarAddLabelButton')
}), isCollectionsView && /*#__PURE__*/_jsx(Button, {
color: "secondary",
startIcon: function startIcon(props) {
return /*#__PURE__*/_jsx(Plus, _objectSpread({}, props));
},
size: isWidgetSmallSize ? 'sm' : 'md',
onClick: handleOpenCollectionModal,
style: {
marginRight: '12px'
},
children: i18n('collectionModalAddCollectionTitle')
}), showUploadButton && /*#__PURE__*/_jsx(Button, {
startIcon: function startIcon(props) {
return /*#__PURE__*/_jsx(Upload, _objectSpread({}, props));
},
title: i18n('topBarUploadFilesInCurrentFolderTitle'),
onClick: isDownloading ? undefined : openAddFilesPanel,
color: "primary",
size: isWidgetSmallSize ? 'sm' : 'md',
disabled: isDownloading,
"data-testid": "topbar-upload-btn",
children: i18n('mutualizedUploadLabel')
})]
})]
});
};
export default TopBar;