/**
* @flow
* @file Collapsed Version component
*/
import * as React from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import type { IntlShape } from 'react-intl';
import ActivityCard from '../ActivityCard';
import IconInfo from '../../../../icons/general/IconInfo';
import PlainButton from '../../../../components/plain-button';
import messages from '../../../common/messages';
import selectors from '../../../common/selectors/version';
import { ACTIVITY_TARGETS } from '../../../common/interactionTargets';
import type { User, FileVersions } from '../../../../common/types/core';
import './Version.scss';
function getMessageForAction(
action: string,
collaborators: { [collaborator_id: string]: User },
version_start: number,
version_end: number,
): React.Node {
// We only support collapsing for multiple upload versions
if (action !== 'upload') {
return null;
}
const collaboratorIDs = Object.keys(collaborators);
const numberOfCollaborators = collaboratorIDs.length;
const versionRange: React.Node = (
{version_start} - {version_end}
);
if (numberOfCollaborators === 1) {
const collaborator = collaborators[collaboratorIDs[0]];
return (
{collaborator.name},
versions: versionRange,
}}
/>
);
}
return (
);
}
type Props = {
collaborators: { [collaborator_id: string]: User },
id: string,
intl: IntlShape,
onInfo?: Function,
shouldUseUAA?: boolean,
version_end: number,
version_start: number,
versions: FileVersions,
};
const CollapsedVersion = (props: Props): React.Node => {
// $FlowFixMe
const action = selectors.getVersionAction(props);
const { collaborators, id, intl, onInfo, shouldUseUAA, versions, version_start, version_end } = props;
return (
{getMessageForAction(action, collaborators, version_start, version_end)}
{onInfo ? (
{
onInfo(shouldUseUAA ? { id, version_number: version_end } : { versions });
}}
type="button"
>
) : null}
);
};
export { CollapsedVersion as CollapsedVersionBase };
export default injectIntl(CollapsedVersion);