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 { useDispatch, useSelector } from 'react-redux';
import { Share, Remove, Link, More } from '@scaleflex/icons';
import { Button } from '@scaleflex/ui/core';
import copyText from '@filerobot/utils/lib/copyText';
import getFileLink from '@filerobot/utils/lib/getFileLink';
import { PERMISSIONS, CONTEXTMENU_MODES } from '@filerobot/utils/lib/constants';
import getFileDetails from '@filerobot/utils/lib/getFileDetails';
import { isVisibilityPublic as isActualVisibilityPublic } from '@filerobot/utils/lib/visibility';
import { useContextMenu } from '@filerobot/core/lib/hooks';
import { selectIsUserPermittedToShare } from '@filerobot/core/lib/slices/user.slice';
import { useExplorer, useIsSmallScreen } from '../../hooks';
import DownloadWithExportButton from './DownloadWithExportButton';
import Styled from './ActionBar.styled';
import { selectFirstSelectedFileOrFolder, selectIsFileSelected, selectIsFolderSelected, selectIsSingleItemSelected, selectSelectedFilesUuids, selectSelectedFoldersUuids } from '../../slices/selections.slice';
import { useDeleteItemsModal, useDeleteModal } from '../Modals';
import { collectionsSelected, deleteCollections, selectSelectedCollections, selectSelectedCollectionsUuids } from '../../slices/collections.slice';
import { selectIsCollectionsView, selectIsLabelsView, selectIsShareboxView } from '../../slices/views.slice';
import { deleteLabels, selectLabelsSelected } from '../../slices/labels.slice';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var SelectionMenu = function SelectionMenu() {
var dispatch = useDispatch();
var _useExplorer = useExplorer(),
info = _useExplorer.info,
i18n = _useExplorer.i18n,
checkUserPermissions = _useExplorer.checkUserPermissions,
opts = _useExplorer.opts;
var triggerDeleteItemsModal = useDeleteItemsModal();
var triggerDeleteModal = useDeleteModal();
var toggleContextMenu = useContextMenu();
var isWidgetSmallSize = useIsSmallScreen();
var deleteModal = useDeleteModal(true);
var selectedLabels = useSelector(selectLabelsSelected);
var isCollectionsView = useSelector(selectIsCollectionsView);
var isLabelsView = useSelector(selectIsLabelsView);
var selectedCollectionsUuids = useSelector(selectSelectedCollectionsUuids);
var isUserPermittedToShare = useSelector(selectIsUserPermittedToShare);
var selectedFoldersUuids = useSelector(selectSelectedFoldersUuids);
var selectedFilesUuids = useSelector(selectSelectedFilesUuids);
var firstItem = useSelector(selectFirstSelectedFileOrFolder); // priorty goes to file then folder, even if folder selected after file.
var isOneItem = useSelector(selectIsSingleItemSelected);
var isFolderSelected = useSelector(selectIsFolderSelected);
var isFileSelected = useSelector(selectIsFileSelected);
var selectedCollections = useSelector(selectSelectedCollections);
var isShareboxView = useSelector(selectIsShareboxView);
var selectedItemsCount = selectedFoldersUuids.length + selectedFilesUuids.length;
var disableDownloadButton = opts.disableDownloadButton,
noImgOperationsAndDownload = opts.noImgOperationsAndDownload,
isFastToken = opts.isFastToken,
disableFilesContextMenu = opts.disableFilesContextMenu;
var deleteSelectedLabels = function deleteSelectedLabels() {
triggerDeleteModal({
title: i18n('labelsDeleteModalTitle', {
smart_count: (selectedLabels || []).length
}),
content: i18n('labelsListDeleteLabel', {
smart_count: (selectedLabels || []).length,
name: selectedLabels.map(function (label) {
var _label$name;
return (_label$name = label.name) !== null && _label$name !== void 0 ? _label$name : label.title;
}).join('", "')
}),
onConfirm: function onConfirm() {
return dispatch(deleteLabels(selectedLabels.map(function (_ref) {
var uuid = _ref.uuid;
return uuid;
})));
}
});
};
var copyLinkToClipboard = function copyLinkToClipboard() {
copyText(getFileLink(firstItem), i18n, info);
};
var handelRemoveClick = function handelRemoveClick() {
triggerDeleteItemsModal({
foldersUuids: selectedFoldersUuids,
filesUuids: selectedFilesUuids
});
};
var isVisibilityPublic = function isVisibilityPublic() {
if (firstItem && isOneItem) {
var _getFileDetails = getFileDetails(firstItem),
visibility = _getFileDetails.visibility;
return isActualVisibilityPublic(visibility);
}
};
var handleDeleteSelectedCollections = function handleDeleteSelectedCollections() {
var selectedCollectionsTitles = selectedCollections.map(function (_ref2) {
var _ref2$title = _ref2.title,
title = _ref2$title === void 0 ? '' : _ref2$title;
return title;
}).join(', ');
deleteModal({
title: i18n('collectionsDeleteModalTitle', {
smart_count: selectedCollectionsUuids.length
}),
content: i18n('collectionsListDeleteCollection', {
name: selectedCollectionsTitles,
smart_count: selectedCollectionsUuids.length
}),
onConfirm: function onConfirm() {
dispatch(deleteCollections(selectedCollectionsUuids));
}
});
dispatch(collectionsSelected([]));
};
var menuOptions = [{
Icon: More,
onClick: function onClick(event) {
return toggleContextMenu({
event: event,
foldersUuids: selectedFoldersUuids,
filesUuids: selectedFilesUuids
});
},
key: 'menu-dots',
hideOption: isShareboxView
}, _objectSpread({}, isOneItem && !isFolderSelected && isVisibilityPublic() ? {
Icon: Link,
onClick: copyLinkToClipboard,
key: 'get-file'
} : null), {
Icon: Share,
onClick: function onClick(event) {
return toggleContextMenu({
event: event,
mode: CONTEXTMENU_MODES.SHARE,
foldersUuids: selectedFoldersUuids,
filesUuids: selectedFilesUuids
});
},
key: 'shareability-file',
hideOption: !isUserPermittedToShare || isFastToken || isShareboxView || isFolderSelected
}, {
Icon: Remove,
onClick: handelRemoveClick,
key: 'remove-file',
hideOption: isShareboxView || !checkUserPermissions([isFolderSelected ? PERMISSIONS.FOLDER_DELETE : '', isFileSelected ? PERMISSIONS.FILE_DELETE : ''])
}].filter(function (n) {
return !!Object.keys(n).length;
});
return /*#__PURE__*/_jsxs(Styled.SelectionMenu, {
children: [/*#__PURE__*/_jsx(Styled.MenuOptionsWrapper, {
children: !!selectedItemsCount && !disableFilesContextMenu && menuOptions.map(function (_ref3) {
var Icon = _ref3.Icon,
onClick = _ref3.onClick,
hideOption = _ref3.hideOption,
key = _ref3.key;
return !hideOption && /*#__PURE__*/_jsx(Styled.SelectionIconButton, {
onClick: onClick,
size: "lg",
color: "basic",
children: function children(props) {
return /*#__PURE__*/_jsx(Icon, _objectSpread({}, props));
}
}, key);
})
}), !isWidgetSmallSize && !isShareboxView && /*#__PURE__*/_jsx(Styled.Seprator, {
$ml: 40
}), isLabelsView && !!selectedLabels.length && /*#__PURE__*/_jsx(Button, {
startIcon: /*#__PURE__*/_jsx(Remove, {
size: 18
}),
color: "warning-primary",
onClick: deleteSelectedLabels,
children: i18n('actionBarSelectionMenuDeleteLable', {
smart_count: selectedLabels.length
})
}), isCollectionsView && !!selectedCollectionsUuids.length && /*#__PURE__*/_jsx(Button, {
startIcon: /*#__PURE__*/_jsx(Remove, {
size: 18
}),
color: "warning-primary",
style: {
marginRight: 12
},
onClick: handleDeleteSelectedCollections,
children: i18n('actionBarSelectionMenuDeleteCollection', {
smart_count: selectedCollectionsUuids.length
})
}), !(disableDownloadButton || noImgOperationsAndDownload && isFolderSelected) && /*#__PURE__*/_jsx(DownloadWithExportButton, {})]
});
};
export default SelectionMenu;