Repository URL to install this package:
|
Version:
3.12.2 ▾
|
import { FILECARD_TABS_IDS, FOLDERCARD_TABS_IDS, ITEMSCARD_TABS_IDS } from './constants';
function getSelectionDetails(selection, postUpload) {
var selectionCount = (selection || []).length;
var isEmptySelection = !selectionCount;
var hasSelectedItems = selectionCount > 0;
var isSingleItem = selectionCount === 1;
var isPreUpload = selection && (Array.isArray(selection) ? selection.some(function (_ref) {
var uploadStep = _ref.uploadStep;
return uploadStep;
}) : selection[0].uploadStep);
var defaultPrevTab = null;
var defaultActiveTab = null;
var singleItem = null;
if (hasSelectedItems) {
if (isSingleItem) {
singleItem = selection[0];
if (isPreUpload) {
singleItem.size = selection[0].size;
}
if (singleItem.isFolder) {
// Folder
defaultPrevTab = FOLDERCARD_TABS_IDS.VISIBILITY;
defaultActiveTab = FOLDERCARD_TABS_IDS.META; // No postUpload for folders (only for file)
} else {
// File
defaultPrevTab = FILECARD_TABS_IDS.EMBED;
defaultActiveTab = postUpload ? FILECARD_TABS_IDS.DETAILS : FILECARD_TABS_IDS.META;
}
} else {
// Multi items
defaultPrevTab = ITEMSCARD_TABS_IDS.VISIBILITY;
defaultActiveTab = ITEMSCARD_TABS_IDS.VISIBILITY; // No postUpload for items (only for file)
}
}
return {
selectionCount: selectionCount,
isEmptySelection: isEmptySelection,
isSingleItem: isSingleItem,
singleItem: singleItem,
defaultActiveTab: defaultActiveTab,
defaultPrevTab: defaultPrevTab,
isPreUpload: isPreUpload
};
}
export default getSelectionDetails;