Repository URL to install this package:
|
Version:
3.12.20 ▾
|
import { useSelector } from 'react-redux';
import classNames from 'classnames';
import { VIEW_OPTIONS } from '../Views/Views.constants';
import { BREADCRUMBS_VIEWS, VIEW_IDS } from '@filerobot/utils/lib/constants';
import { useExplorer } from '../../hooks';
import { selectFilesError, selectFilesStats, selectFilesUuids, selectIsFilesLoading } from '../../slices/files.slice';
import { selectExactSearchUuids, selectExtendedSearchUuids, selectIsExtendFetching, selectIsQuickFetching, selectSearchQuery } from '../../slices/search.slice';
import RightSide from './RightSide';
import BreadcrumbsSkeleton from '../Breadcrumbs/BreadcrumbsSkeleton';
import Breadcrumbs from '../Breadcrumbs';
import Styled from './HeaderBar.styled';
import { selectActiveView, selectIsAssetsView, selectIsCollectionsView, selectIsLabelsView, selectIsProductView, selectIsShareboxView } from '../../slices/views.slice';
import { selectActiveProductRef } from '../../slices/products.slice';
import { selectIsFoldersTreeOpened } from '../../slices/folders.slice';
import { selectIsShareboxLoading } from '../../slices/sharebox.slice';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var HeaderBar = function HeaderBar(_ref) {
var SortElement = _ref.SortElement;
var _useExplorer = useExplorer(),
i18n = _useExplorer.i18n,
_useExplorer$opts = _useExplorer.opts,
opts = _useExplorer$opts === void 0 ? {} : _useExplorer$opts;
var searchQuery = useSelector(selectSearchQuery);
var exactMatchSearchUuids = useSelector(selectExactSearchUuids) || [];
var extendedSearchUuids = useSelector(selectExtendedSearchUuids) || [];
var isQuickSearchFetching = useSelector(selectIsQuickFetching);
var isExtendedSearchFetching = useSelector(selectIsExtendFetching);
var isFilesLoading = useSelector(selectIsFilesLoading);
var isShareboxLoading = useSelector(selectIsShareboxLoading);
var activeView = useSelector(selectActiveView);
var isAssetsView = useSelector(selectIsAssetsView);
var isLabelsView = useSelector(selectIsLabelsView);
var isCollectionsView = useSelector(selectIsCollectionsView);
var _useSelector = useSelector(selectFilesStats),
filesCount = _useSelector.filesCount,
statsLoading = _useSelector.loading;
// the number of files retrieved/shown not from the BE used in other view such as (favorite view)
var retrievedFilesCount = useSelector(function (state) {
return selectFilesUuids(state).length;
});
var isProductView = useSelector(selectIsProductView);
var activeProductRef = useSelector(selectActiveProductRef);
var showFoldersTree = useSelector(selectIsFoldersTreeOpened);
var filesError = useSelector(selectFilesError);
var isShareboxView = useSelector(selectIsShareboxView);
var isBreadcrumbsView = BREADCRUMBS_VIEWS.includes(activeView);
var isSearchMode = isAssetsView && searchQuery;
var showBreadcrumbsLoading = !isSearchMode && isFilesLoading || isShareboxLoading;
var showBreadcrumbs = opts.showBreadcrumbs,
showSort = opts.showSort;
var getLabel = function getLabel() {
if (isSearchMode) {
if (isQuickSearchFetching && isExtendedSearchFetching) {
return i18n('searchResultsWithCountLabel', {
files_count: '...'
});
}
if (!isQuickSearchFetching && isExtendedSearchFetching) {
return i18n('searchExactMatchWithCountLabel', {
files_count: '...'
});
}
return !(exactMatchSearchUuids !== null && exactMatchSearchUuids !== void 0 && exactMatchSearchUuids.length) && !(extendedSearchUuids !== null && extendedSearchUuids !== void 0 && extendedSearchUuids.length) ? i18n('searchResultsWithCountLabel', {
files_count: (extendedSearchUuids === null || extendedSearchUuids === void 0 ? void 0 : extendedSearchUuids.length) || 0
}) : i18n('searchExactMatchWithCountLabel', {
files_count: exactMatchSearchUuids === null || exactMatchSearchUuids === void 0 ? void 0 : exactMatchSearchUuids.length
});
}
if (isAssetsView && !isExtendedSearchFetching) {
var count = filesCount || 0;
return i18n('mutualizedAssetsLabel', {
count: statsLoading ? '...' : count
});
}
if (isProductView) {
return activeProductRef;
}
return "".concat(i18n(VIEW_OPTIONS[activeView || VIEW_IDS.FOLDERS].i18nKey)).concat(retrievedFilesCount && !filesError ? " (".concat(retrievedFilesCount, ")") : '');
};
var renderViewLabel = function renderViewLabel() {
return /*#__PURE__*/_jsx(Styled.ViewLabel, {
children: getLabel()
});
};
var renderViewBar = function renderViewBar() {
if (showBreadcrumbsLoading) return /*#__PURE__*/_jsx(BreadcrumbsSkeleton, {});
if (showBreadcrumbs && isBreadcrumbsView) return /*#__PURE__*/_jsx(Breadcrumbs, {});
return renderViewLabel();
};
var showSortComponent = showSort && SortElement;
return /*#__PURE__*/_jsxs(Styled.HeaderBar, {
showFoldersTreeIcon: !showFoldersTree && !isShareboxView,
className: classNames('filerobot-ProviderBrowser-headerBar', {
'filerobot-ProviderBrowser-headerBar--simple': !showBreadcrumbs,
'filerobot-ProviderBrowser-headerBar--labelsView': isLabelsView,
'filerobot-ProviderBrowser-headerBar--collectionsView': isCollectionsView
}),
children: [renderViewBar(), showSortComponent && SortElement, /*#__PURE__*/_jsx(RightSide, {})]
});
};
export default HeaderBar;