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,
|
2023-08-10 23:18:59 +08:00
|
|
|
filenameConverted: PropTypes.string.isRequired,
|
2023-05-12 05:06:48 +08:00
|
|
|
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,
|
2023-08-10 23:18:59 +08:00
|
|
|
downloadableExtension: PropTypes.string.isRequired,
|
2023-05-12 05:06:48 +08:00
|
|
|
}).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-08-10 23:18:59 +08:00
|
|
|
const { filenameConverted, filename, downloadableExtension } = item;
|
2023-08-15 21:58:37 +08:00
|
|
|
const convertedFileExtension = filenameConverted?.split('.').slice(-1)[0];
|
2023-08-10 23:18:59 +08:00
|
|
|
const originalFileExtension = filename?.split('.').slice(-1)[0];
|
|
|
|
const toggleDownloadOriginalPresentation = (enableDownload, isConverted) => {
|
2023-05-03 19:50:36 +08:00
|
|
|
handleToggleDownloadable(item);
|
2023-04-20 19:48:43 +08:00
|
|
|
if (enableDownload) {
|
2023-08-15 21:30:17 +08:00
|
|
|
if (isConverted) {
|
|
|
|
handleDownloadingOfPresentation('Converted');
|
|
|
|
} else {
|
|
|
|
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) {
|
2023-08-10 23:18:59 +08:00
|
|
|
if (isDownloadable && !!downloadableExtension
|
|
|
|
&& downloadableExtension === originalFileExtension) {
|
2023-08-01 04:03:29 +08:00
|
|
|
this.menuItems.push({
|
|
|
|
key: this.actionsKey[0],
|
2023-08-10 23:18:59 +08:00
|
|
|
dataTest: 'disableOriginalPresentationDownload',
|
|
|
|
label: intl.formatMessage(intlMessages.disableOriginalPresentationDownload,
|
|
|
|
{ 0: originalFileExtension }),
|
2023-08-15 21:30:17 +08:00
|
|
|
onClick: () => toggleDownloadOriginalPresentation(false, false),
|
2023-08-01 04:03:29 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.menuItems.push({
|
|
|
|
key: this.actionsKey[0],
|
2023-08-10 23:18:59 +08:00
|
|
|
dataTest: 'enableOriginalPresentationDownload',
|
|
|
|
label: intl.formatMessage(intlMessages.enableOriginalPresentationDownload,
|
|
|
|
{ 0: originalFileExtension }),
|
2023-08-15 21:30:17 +08:00
|
|
|
onClick: () => toggleDownloadOriginalPresentation(true, false),
|
2023-08-01 04:03:29 +08:00
|
|
|
});
|
|
|
|
}
|
2023-08-10 23:18:59 +08:00
|
|
|
if ((!!filenameConverted && filenameConverted !== '')
|
|
|
|
&& convertedFileExtension !== originalFileExtension) {
|
|
|
|
if (isDownloadable && !!downloadableExtension
|
|
|
|
&& downloadableExtension === convertedFileExtension) {
|
|
|
|
this.menuItems.push({
|
|
|
|
key: this.actionsKey[0],
|
|
|
|
dataTest: 'disableOriginalPresentationDownload',
|
|
|
|
label: intl.formatMessage(intlMessages.disableOriginalPresentationDownload,
|
|
|
|
{ 0: convertedFileExtension }),
|
2023-08-15 21:30:17 +08:00
|
|
|
onClick: () => toggleDownloadOriginalPresentation(false, true),
|
2023-08-10 23:18:59 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.menuItems.push({
|
|
|
|
key: this.actionsKey[0],
|
|
|
|
dataTest: 'enableOriginalPresentationDownload',
|
|
|
|
label: intl.formatMessage(intlMessages.enableOriginalPresentationDownload,
|
|
|
|
{ 0: convertedFileExtension }),
|
2023-08-15 21:30:17 +08:00
|
|
|
onClick: () => toggleDownloadOriginalPresentation(true, true),
|
2023-08-10 23:18:59 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 04:03:29 +08:00
|
|
|
}
|
|
|
|
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);
|