-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add duplicate file validation for asset upload (#885)
* feat: add duplicate file validation for asset upload * fix: modal only appearing once * feat: add tests for overwrite modal * fix: input not allowing second upload of same file * fix: default pageSize for asset details
- Loading branch information
1 parent
a88a88e
commit 9740974
Showing
12 changed files
with
318 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { useSelector } from 'react-redux'; | ||
import { injectIntl, FormattedMessage, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { | ||
ActionRow, | ||
Button, | ||
ModalDialog, | ||
useToggle, | ||
} from '@openedx/paragon'; | ||
import { isEmpty } from 'lodash'; | ||
|
||
import messages from './messages'; | ||
|
||
const FileValidationModal = ({ | ||
handleFileOverwrite, | ||
// injected | ||
intl, | ||
}) => { | ||
const [isOpen, open, close] = useToggle(); | ||
|
||
const { duplicateFiles } = useSelector(state => state.assets); | ||
|
||
useEffect(() => { | ||
if (!isEmpty(duplicateFiles)) { | ||
open(); | ||
} | ||
}, [duplicateFiles]); | ||
|
||
return ( | ||
<ModalDialog | ||
title={intl.formatMessage(messages.overwriteModalTitle)} | ||
isOpen={isOpen} | ||
onClose={close} | ||
> | ||
<ModalDialog.Header> | ||
<ModalDialog.Title> | ||
<FormattedMessage {...messages.overwriteModalTitle} /> | ||
</ModalDialog.Title> | ||
</ModalDialog.Header> | ||
<ModalDialog.Body> | ||
<FormattedMessage {...messages.overwriteConfirmMessage} /> | ||
<ul className="mt-2"> | ||
{Object.keys(duplicateFiles).map(file => <li>{file}</li>)} | ||
</ul> | ||
</ModalDialog.Body> | ||
<ModalDialog.Footer> | ||
<ActionRow> | ||
<ModalDialog.CloseButton variant="tertiary"> | ||
<FormattedMessage {...messages.cancelOverwriteButtonLabel} /> | ||
</ModalDialog.CloseButton> | ||
<Button onClick={() => handleFileOverwrite(close, duplicateFiles)}> | ||
<FormattedMessage {...messages.confirmOverwriteButtonLabel} /> | ||
</Button> | ||
</ActionRow> | ||
</ModalDialog.Footer> | ||
</ModalDialog> | ||
); | ||
}; | ||
|
||
FileValidationModal.propTypes = { | ||
handleFileOverwrite: PropTypes.func.isRequired, | ||
// injected | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
export default injectIntl(FileValidationModal); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.