-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH Use archive text when file archiving is enabled #1378
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,16 +3,31 @@ | |
"AssetAdmin.BACK": "Back", | ||
"AssetAdmin.BACK_DESCRIPTION": "Navigate up a level", | ||
"AssetAdmin.BULK_ACTIONS_CONFIRM": "Are you sure you want to %s these files?", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE": "Archive", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE_ITEMS_CONFIRM": "You're about to archive %s file(s) which may be used in your site's content. Carefully check the file usage on the files before archiving the folder.", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE_FAIL_02": "%s folders/files were successfully archived, but %s files were not able to be archived.", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE_FOLDER_CONFIRM": "Are you sure you want to archive this folder?", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE_FOLDERS_CONFIRM": "Are you sure you want to archive these folders?", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE_SUCCESS_02": "%s folders/files were successfully archived.", | ||
"AssetAdmin.BULK_ACTIONS_ARCHIVE_WARNING": "Ensure files are removed from content areas prior to archiving them, otherwise they will appear as broken links.", | ||
"AssetAdmin.BULK_ACTIONS_DELETE": "Delete", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_CONFIRM": "Are you sure you want to delete these files?", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_FAIL": "%s folders/files were successfully archived, but %s files were not able to be archived.", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_FAIL_02": "%s folders/files were successfully deleted, but %s files were not able to be deleted.", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_FOLDER": "These folders contain files which are currently in use, you must move or delete their contents before you can delete the folder.", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_FOLDER_CONFIRM": "Are you sure you want to delete this folder?", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_FOLDERS_CONFIRM": "Are you sure you want to delete these folders?", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_ITEMS_CONFIRM": "You're about to delete %s file(s) which may be used in your site's content. Carefully check the file usage on the files before deleting the folder.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is knowingly wrong where it says |
||
"AssetAdmin.BULK_ACTIONS_DELETE_MULTI_CONFIRM": "There are %s files currently in use, are you sure you want to delete these files?", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_SINGLE_CONFIRM": "This file is currently in use in %s places, are you sure you want to delete it?", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_SUCCESS": "%s folders/files were successfully archived.", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_SUCCESS_02": "%s folders/files were successfully deleted.", | ||
"AssetAdmin.BULK_ACTIONS_DELETE_WARNING": "Ensure files are removed from content areas prior to deleting them, otherwise they will appear as broken links.", | ||
"AssetAdmin.BULK_ACTIONS_PLACEHOLDER": "Select an action...", | ||
"AssetAdmin.CANCEL": "Cancel", | ||
"AssetAdmin.CONFIRMDELETE": "Are you sure you want to delete this record?", | ||
"AssetAdmin.CONFIRM_FILE_ARCHIVE": "Confirm archive", | ||
"AssetAdmin.CONFIRM_FILE_DELETION": "Confirm deletion", | ||
"AssetAdmin.CREATED": "First uploaded", | ||
"AssetAdmin.DELETE": "Delete", | ||
"AssetAdmin.DIM": "Dimensions", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -357,21 +357,31 @@ class AssetAdmin extends Component { | |
}) | ||
.then((resultItems) => { | ||
const successes = resultItems.filter((result) => result).length; | ||
const { archiveFiles } = this.props.sectionConfig; | ||
if (successes !== ids.length) { | ||
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_FAIL_02'; | ||
let transDefault = '%s folders/files were successfully deleted, but %s files were not able to be deleted.'; | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_FAIL_02'; | ||
transDefault = '%s folders/files were successfully archived, but %s files were not able to be archived.'; | ||
} | ||
this.props.actions.toasts.error( | ||
i18n.sprintf( | ||
i18n._t( | ||
'AssetAdmin.BULK_ACTIONS_DELETE_FAIL', | ||
'%s folders/files were successfully deleted, but %s files were not able to be deleted.' | ||
), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This key was wrong because in en.json the text is |
||
i18n._t(transKey, transDefault), | ||
successes, | ||
ids.length - successes | ||
) | ||
); | ||
} else { | ||
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_SUCCESS_02'; | ||
let transDefault = '%s folders/files were successfully deleted.'; | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_SUCCESS_02'; | ||
transDefault = '%s folders/files were successfully archived.'; | ||
} | ||
this.props.actions.toasts.success( | ||
i18n.sprintf( | ||
i18n._t('AssetAdmin.BULK_ACTIONS_DELETE_SUCCESS', '%s folders/files were successfully deleted.'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This key was wrong because in en.json the text is |
||
i18n._t(transKey, transDefault), | ||
successes | ||
) | ||
); | ||
|
@@ -674,6 +684,7 @@ class AssetAdmin extends Component { | |
|
||
render() { | ||
const { folder, folderId, query, getUrl, type, maxFiles, toolbarChildren } = this.props; | ||
const { archiveFiles } = this.props.sectionConfig; | ||
|
||
const showBackButton = Boolean(folderId || hasFilters(query.filter)); | ||
const searchFormSchemaUrl = this.props.sectionConfig.form.fileSearchForm.schemaUrl; | ||
|
@@ -723,7 +734,7 @@ class AssetAdmin extends Component { | |
{this.renderGallery()} | ||
{this.renderEditor()} | ||
</div> | ||
<BulkDeleteConfirmation onConfirm={this.handleDelete} /> | ||
<BulkDeleteConfirmation onConfirm={this.handleDelete} archiveFiles={archiveFiles} /> | ||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,14 @@ import i18n from 'i18n'; | |
const BulkDeleteConfirmation = ({ | ||
loading, LoadingComponent, transition, | ||
files, descendantFileCounts, | ||
onModalClose, onCancel, onConfirm | ||
onModalClose, onCancel, onConfirm, archiveFiles | ||
}) => { | ||
let body = null; | ||
const transKey = archiveFiles ? 'AssetAdmin.ARCHIVE' : 'AssetAdmin.DELETE'; | ||
const transDefault = archiveFiles ? 'Archive' : 'Delete'; | ||
let actions = [ | ||
{ | ||
label: i18n._t('AssetAdmin.DELETE', 'Delete'), | ||
label: i18n._t(transKey, transDefault), | ||
handler: () => onConfirm(files.map(({ id }) => id)), | ||
color: 'danger' | ||
}, | ||
|
@@ -42,7 +44,7 @@ const BulkDeleteConfirmation = ({ | |
const folderDescendantFileTotals = getFolderDescendantFileTotals(files, descendantFileCounts); | ||
const fileTotalItems = getFileTotalItems(files); | ||
|
||
const bodyProps = { folderCount, folderDescendantFileTotals, fileTotalItems }; | ||
const bodyProps = { folderCount, folderDescendantFileTotals, fileTotalItems, archiveFiles }; | ||
body = <BulkDeleteMessage {...bodyProps} />; | ||
|
||
if (folderDescendantFileTotals.totalItems || fileTotalItems) { | ||
|
@@ -53,10 +55,10 @@ const BulkDeleteConfirmation = ({ | |
color: 'primary' | ||
}, | ||
{ | ||
label: i18n._t('AssetAdmin.DELETE', 'Delete'), | ||
label: i18n._t(transKey, transDefault), | ||
handler: () => onConfirm(files.map(({ id }) => id)), | ||
color: 'danger', | ||
}, | ||
} | ||
]; | ||
} | ||
} | ||
|
@@ -72,6 +74,7 @@ const BulkDeleteConfirmation = ({ | |
actions={actions} | ||
onCancel={onCancel} | ||
onClosed={onModalClose} | ||
archiveFiles={archiveFiles} | ||
/>); | ||
}; | ||
|
||
|
@@ -84,6 +87,11 @@ BulkDeleteConfirmation.propTypes = { | |
onCancel: PropTypes.func.isRequired, | ||
onModalClose: PropTypes.func.isRequired, | ||
onConfirm: PropTypes.func.isRequired, | ||
archiveFiles: PropTypes.bool, | ||
}; | ||
|
||
BulkDeleteConfirmation.defaultProps = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding default props for now for existing jest tests to pass, will be removed in #1379 and |
||
archiveFiles: false | ||
}; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,44 +9,79 @@ import { descendantFileTotalsShape } from './helpers'; | |
* @param {object} fileTotalItems | ||
* @returns {string} | ||
*/ | ||
const confirmationMessage = (folderCount, folderDescendantFileTotals, fileTotalItems) => { | ||
const confirmationMessage = ( | ||
folderCount, | ||
folderDescendantFileTotals, | ||
fileTotalItems, | ||
archiveFiles | ||
) => { | ||
const fileCount = folderDescendantFileTotals.totalCount + fileTotalItems; | ||
if (fileCount > 0) { | ||
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_ITEMS_CONFIRM'; | ||
let transDefault = [ | ||
"You're about to delete %s file(s) which may be used in your site's content.", | ||
'Carefully check the file usage on the files before deleting the folder.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is knowingly wrong where it says |
||
].join(' '); | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_ITEMS_CONFIRM'; | ||
transDefault = [ | ||
"You're about to archive %s file(s) which may be used in your site's content.", | ||
'Carefully check the file usage on the files before archiving the folder.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This message is knowingly wrong where it says |
||
].join(' '); | ||
} | ||
return i18n.sprintf( | ||
i18n._t( | ||
'AssetAdmin.BULK_ACTIONS_DELETE_ITEMS_CONFIRM', | ||
[ | ||
"You're about to delete %s file(s) which may be used in your site's content.", | ||
'Carefully check the file usage on the files before deleting the folder.' | ||
].join(' ') | ||
), | ||
i18n._t(transKey, transDefault), | ||
fileCount | ||
); | ||
} else if (folderCount === 1) { | ||
return i18n._t( | ||
'AssetAdmin.BULK_ACTIONS_DELETE_FOLDER_CONFIRM', | ||
'Are you sure you want to delete this folder?' | ||
); | ||
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_FOLDER_CONFIRM'; | ||
let transDefault = 'Are you sure you want to delete this folder?'; | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_FOLDER_CONFIRM'; | ||
transDefault = 'Are you sure you want to archive this folder?'; | ||
} | ||
return i18n._t(transKey, transDefault); | ||
} | ||
return i18n._t( | ||
'AssetAdmin.BULK_ACTIONS_DELETE_FOLDERS_CONFIRM', | ||
'Are you sure you want to delete these folders?' | ||
); | ||
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_FOLDERS_CONFIRM'; | ||
let transDefault = 'Are you sure you want to delete these folders?'; | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_FOLDERS_CONFIRM'; | ||
transDefault = 'Are you sure you want to archive these folders?'; | ||
} | ||
return i18n._t(transKey, transDefault); | ||
}; | ||
|
||
/** | ||
* Display a context dependent confirmation message. | ||
*/ | ||
const BulkDeleteMessage = ({ folderCount, folderDescendantFileTotals, fileTotalItems }) => ( | ||
<Fragment> | ||
<p>{confirmationMessage(folderCount, folderDescendantFileTotals, fileTotalItems)}</p> | ||
{(folderDescendantFileTotals.totalItems > 0 || fileTotalItems > 0) && | ||
<p>{i18n._t( | ||
'AssetAdmin.BULK_ACTIONS_DELETE_WARNING', | ||
'Ensure files are removed from content areas prior to deleting them, otherwise they will appear as broken links.' | ||
)}</p>} | ||
</Fragment> | ||
); | ||
const BulkDeleteMessage = ({ | ||
folderCount, | ||
folderDescendantFileTotals, | ||
fileTotalItems, | ||
archiveFiles | ||
}) => { | ||
let transKey = 'AssetAdmin.BULK_ACTIONS_DELETE_WARNING'; | ||
let transDefault = 'Ensure files are removed from content areas prior to deleting them, otherwise they will ' | ||
+ 'appear as broken links.'; | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.BULK_ACTIONS_ARCHIVE_WARNING'; | ||
transDefault = 'Ensure files are removed from content areas prior to archiving them, otherwise they will ' | ||
+ 'appear as broken links.'; | ||
} | ||
const message = confirmationMessage( | ||
folderCount, | ||
folderDescendantFileTotals, | ||
fileTotalItems, | ||
archiveFiles | ||
); | ||
return ( | ||
<Fragment> | ||
<p>{message}</p> | ||
{(folderDescendantFileTotals.totalItems > 0 || fileTotalItems > 0) && | ||
<p>{i18n._t(transKey, transDefault)}</p>} | ||
</Fragment> | ||
); | ||
}; | ||
|
||
BulkDeleteMessage.propTypes = { | ||
folderCount: PropTypes.number, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,27 @@ import React from 'react'; | |
import PropTypes from 'prop-types'; | ||
import { Modal, ModalHeader, ModalBody, ModalFooter, Button } from 'reactstrap'; | ||
|
||
const DeletionModal = ({ isOpen, body, onCancel, actions }) => ( | ||
<Modal isOpen={isOpen} toggle={onCancel}> | ||
<ModalHeader toggle={onCancel}> | ||
{i18n._t('AssetAdmin.CONFIRM_FILE_DELETION', 'Confirm deletion')} | ||
</ModalHeader> | ||
<ModalBody>{body}</ModalBody> | ||
<ModalFooter> | ||
{actions.map(({ label, handler, color }) => ( | ||
<Button key={label} color={color} onClick={handler}>{label}</Button> | ||
))} | ||
</ModalFooter> | ||
</Modal> | ||
const DeletionModal = ({ isOpen, body, onCancel, actions, archiveFiles }) => { | ||
let transKey = 'AssetAdmin.CONFIRM_FILE_DELETION'; | ||
let transDefault = 'Confirm deletion'; | ||
if (archiveFiles) { | ||
transKey = 'AssetAdmin.CONFIRM_FILE_ARCHIVE'; | ||
transDefault = 'Confirm archive'; | ||
} | ||
return ( | ||
<Modal isOpen={isOpen} toggle={onCancel}> | ||
<ModalHeader toggle={onCancel}> | ||
{i18n._t(transKey, transDefault)} | ||
</ModalHeader> | ||
<ModalBody>{body}</ModalBody> | ||
<ModalFooter> | ||
{actions.map(({ label, handler, color }) => ( | ||
<Button key={label} color={color} onClick={handler}>{label}</Button> | ||
))} | ||
</ModalFooter> | ||
</Modal> | ||
); | ||
}; | ||
|
||
DeletionModal.propTypes = { | ||
isOpen: PropTypes.bool.isRequired, | ||
|
@@ -25,7 +33,12 @@ DeletionModal.propTypes = { | |
label: PropTypes.string.isRequired, | ||
handler: PropTypes.func, | ||
color: PropTypes.string | ||
})) | ||
})), | ||
archiveFiles: PropTypes.bool, | ||
}; | ||
|
||
DeletionModal.defaultProps = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding default props for now for existing jest tests to pass, will be removed in #1379 and |
||
archiveFiles: false | ||
}; | ||
|
||
export default DeletionModal; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is knowingly wrong where it says
archiving the folder
instead ofarchiving the file(s)
- this is because this text is tested in a jest test that will be updated in #1379