2023-04-14 22:04:24 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-05-12 05:06:48 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2023-04-14 22:04:24 +08:00
|
|
|
import BBBMenu from '/imports/ui/components/common/menu/component';
|
|
|
|
import { uniqueId } from '/imports/utils/string-utils';
|
|
|
|
import Trigger from '/imports/ui/components/common/control-header/right/component';
|
2023-05-12 05:06:48 +08:00
|
|
|
import PresentationDownloadDropdownWrapper from './presentation-download-dropdown-wrapper/component';
|
2023-04-14 22:04:24 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
2023-04-20 19:48:43 +08:00
|
|
|
enableOriginalPresentationDownload: {
|
|
|
|
id: 'app.presentationUploader.enableOriginalPresentationDownload',
|
|
|
|
description: 'Send original presentation to chat',
|
|
|
|
},
|
|
|
|
disableOriginalPresentationDownload: {
|
|
|
|
id: 'app.presentationUploader.disableOriginalPresentationDownload',
|
2023-04-14 22:04:24 +08:00
|
|
|
description: 'Send original presentation to chat',
|
|
|
|
},
|
2023-06-17 00:40:09 +08:00
|
|
|
sendCurrentStateDocument: {
|
|
|
|
id: 'app.presentationUploader.exportCurrentStatePresentation',
|
|
|
|
description: 'Send presentation to chat in the current state label',
|
2023-04-14 22:04:24 +08:00
|
|
|
},
|
|
|
|
copySuccess: {
|
|
|
|
id: 'app.chat.copySuccess',
|
|
|
|
description: 'aria success alert',
|
|
|
|
},
|
|
|
|
copyErr: {
|
|
|
|
id: 'app.chat.copyErr',
|
|
|
|
description: 'aria error alert',
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
id: 'app.presentationUploader.dropdownExportOptions',
|
|
|
|
description: 'Chat Options',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-05-12 05:06:48 +08:00
|
|
|
const propTypes = {
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
handleDownloadingOfPresentation: PropTypes.func.isRequired,
|
|
|
|
handleToggleDownloadable: PropTypes.func.isRequired,
|
|
|
|
isDownloadable: PropTypes.bool.isRequired,
|
|
|
|
item: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
filename: PropTypes.string.isRequired,
|
|
|
|
isCurrent: PropTypes.bool.isRequired,
|
|
|
|
temporaryPresentationId: PropTypes.string.isRequired,
|
|
|
|
isDownloadable: PropTypes.bool.isRequired,
|
|
|
|
isRemovable: PropTypes.bool.isRequired,
|
|
|
|
conversion: PropTypes.shape,
|
|
|
|
upload: PropTypes.shape,
|
|
|
|
exportation: PropTypes.shape,
|
|
|
|
uploadTimestamp: PropTypes.number.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
closeModal: PropTypes.func.isRequired,
|
|
|
|
isRTL: PropTypes.bool.isRequired,
|
|
|
|
disabled: PropTypes.bool.isRequired,
|
|
|
|
};
|
|
|
|
|
2023-04-14 22:04:24 +08:00
|
|
|
class PresentationDownloadDropdown extends PureComponent {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.actionsKey = [
|
|
|
|
uniqueId('action-item-'),
|
|
|
|
uniqueId('action-item-'),
|
|
|
|
uniqueId('action-item-'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getAvailableActions() {
|
|
|
|
const {
|
|
|
|
intl,
|
2023-04-20 19:48:43 +08:00
|
|
|
handleDownloadingOfPresentation,
|
|
|
|
handleToggleDownloadable,
|
|
|
|
isDownloadable,
|
2023-08-01 04:03:29 +08:00
|
|
|
allowDownloadOriginal,
|
|
|
|
allowDownloadWithAnnotations,
|
2023-04-20 19:48:43 +08:00
|
|
|
item,
|
2023-05-03 19:50:36 +08:00
|
|
|
closeModal,
|
2023-04-14 22:04:24 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
this.menuItems = [];
|
|
|
|
|
2023-04-20 19:48:43 +08:00
|
|
|
const toggleDownloadOriginalPresentation = (enableDownload) => {
|
2023-05-03 19:50:36 +08:00
|
|
|
handleToggleDownloadable(item);
|
2023-04-20 19:48:43 +08:00
|
|
|
if (enableDownload) {
|
2023-05-12 05:06:48 +08:00
|
|
|
handleDownloadingOfPresentation('Original');
|
2023-04-20 19:48:43 +08:00
|
|
|
}
|
2023-05-03 19:50:36 +08:00
|
|
|
closeModal();
|
2023-05-12 05:06:48 +08:00
|
|
|
};
|
2023-04-20 19:48:43 +08:00
|
|
|
|
2023-08-01 04:03:29 +08:00
|
|
|
if (allowDownloadOriginal) {
|
|
|
|
if (!isDownloadable) {
|
|
|
|
this.menuItems.push({
|
|
|
|
key: this.actionsKey[0],
|
|
|
|
dataTest: 'enableOriginalPresentationDownload',
|
|
|
|
label: intl.formatMessage(intlMessages.enableOriginalPresentationDownload),
|
|
|
|
onClick: () => toggleDownloadOriginalPresentation(true),
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.menuItems.push({
|
|
|
|
key: this.actionsKey[0],
|
|
|
|
dataTest: 'disableOriginalPresentationDownload',
|
|
|
|
label: intl.formatMessage(intlMessages.disableOriginalPresentationDownload),
|
|
|
|
onClick: () => toggleDownloadOriginalPresentation(false),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (allowDownloadWithAnnotations) {
|
2023-06-09 02:16:26 +08:00
|
|
|
this.menuItems.push({
|
2023-08-01 04:03:29 +08:00
|
|
|
key: this.actionsKey[1],
|
|
|
|
id: 'sendCurrentStateDocument',
|
|
|
|
dataTest: 'sendCurrentStateDocument',
|
|
|
|
label: intl.formatMessage(intlMessages.sendCurrentStateDocument),
|
|
|
|
onClick: () => {
|
|
|
|
closeModal();
|
|
|
|
handleDownloadingOfPresentation('Annotated');
|
|
|
|
},
|
2023-06-09 02:16:26 +08:00
|
|
|
});
|
2023-05-04 19:48:32 +08:00
|
|
|
}
|
2023-04-14 22:04:24 +08:00
|
|
|
return this.menuItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2023-06-09 02:16:26 +08:00
|
|
|
const { intl, isRTL, disabled } = this.props;
|
2023-04-14 22:04:24 +08:00
|
|
|
|
2023-06-01 20:29:56 +08:00
|
|
|
const customStyles = { zIndex: 9999 };
|
|
|
|
|
2023-04-14 22:04:24 +08:00
|
|
|
return (
|
2023-06-09 02:16:26 +08:00
|
|
|
<PresentationDownloadDropdownWrapper disabled={disabled}>
|
2023-04-14 22:04:24 +08:00
|
|
|
<BBBMenu
|
2023-06-01 20:29:56 +08:00
|
|
|
customStyles={customStyles}
|
2023-06-09 02:16:26 +08:00
|
|
|
trigger={(
|
|
|
|
<Trigger
|
|
|
|
data-test="presentationOptionsDownload"
|
|
|
|
icon="more"
|
|
|
|
label={intl.formatMessage(intlMessages.options)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.options)}
|
|
|
|
onClick={() => null}
|
|
|
|
/>
|
|
|
|
)}
|
2023-04-14 22:04:24 +08:00
|
|
|
opts={{
|
|
|
|
id: 'presentation-download-dropdown',
|
|
|
|
keepMounted: true,
|
|
|
|
transitionDuration: 0,
|
|
|
|
elevation: 2,
|
2023-07-20 00:22:50 +08:00
|
|
|
getcontentanchorel: null,
|
2023-04-14 22:04:24 +08:00
|
|
|
fullwidth: 'true',
|
|
|
|
anchorOrigin: { vertical: 'bottom', horizontal: isRTL ? 'right' : 'left' },
|
|
|
|
transformOrigin: { vertical: 'top', horizontal: isRTL ? 'right' : 'left' },
|
|
|
|
}}
|
|
|
|
actions={this.getAvailableActions()}
|
|
|
|
/>
|
2023-05-03 19:50:36 +08:00
|
|
|
</PresentationDownloadDropdownWrapper>
|
2023-04-14 22:04:24 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-12 05:06:48 +08:00
|
|
|
PresentationDownloadDropdown.propTypes = propTypes;
|
|
|
|
|
2023-04-14 22:04:24 +08:00
|
|
|
export default injectIntl(PresentationDownloadDropdown);
|