/** * @flow * @file Versions Sidebar component * @author Box */ import * as React from 'react'; import { FormattedMessage } from 'react-intl'; import { Route } from 'react-router-dom'; import type { MessageDescriptor } from 'react-intl'; import InlineError from '../../../components/inline-error'; import messages from './messages'; import SidebarContent from '../SidebarContent'; import VersionsMenu from './VersionsMenu'; import BackButton from '../../common/back-button'; import { DEFAULT_FETCH_END } from '../../../constants'; import { LoadingIndicatorWrapper } from '../../../components/loading-indicator'; import type { BoxItemVersion } from '../../../common/types/core'; import type { InternalSidebarNavigation, InternalSidebarNavigationHandler, ViewTypeValues } from '../../common/types/SidebarNavigation'; import './VersionsSidebar.scss'; const { useCallback } = React; const MAX_VERSIONS = DEFAULT_FETCH_END; type Props = { error?: MessageDescriptor, fileId: string, internalSidebarNavigation?: InternalSidebarNavigation, internalSidebarNavigationHandler?: InternalSidebarNavigationHandler, isLoading: boolean, parentName: ViewTypeValues, routerDisabled?: boolean, versionCount: number, versionLimit: number, versions: Array, }; type VersionsContentProps = { error?: MessageDescriptor, fileId: string, history?: any, internalSidebarNavigation?: InternalSidebarNavigation, internalSidebarNavigationHandler?: InternalSidebarNavigationHandler, isLoading: boolean, parentName: ViewTypeValues, routerDisabled?: boolean, versionCount: number, versionLimit: number, versions: Array, }; const VersionsContent = ({ error, history, internalSidebarNavigation, internalSidebarNavigationHandler, isLoading, parentName, routerDisabled, versions, ...rest }: VersionsContentProps) => { const showLimit = versions.length >= MAX_VERSIONS; const showVersions = !!versions.length; const showEmpty = !isLoading && !showVersions; const showError = !!error; const handleBackClick = useCallback(() => { if (routerDisabled && internalSidebarNavigationHandler) { internalSidebarNavigationHandler({ sidebar: parentName }); } else if (!routerDisabled && history) { history.push(`/${parentName}`); } }, [parentName, routerDisabled, internalSidebarNavigationHandler, history]); return ( } > {showError && ( }> )} {showEmpty && (
)} {showVersions && (
)} {showLimit && (
)}
); }; const VersionsSidebar = (props: Props) => { const { routerDisabled } = props; if (routerDisabled) { return ; } return ( {({ history }) => } ); }; export default VersionsSidebar;